- Why do you not want to define a minor mode here? It's as simple as this - in this case I put a character into the mode line, in
global-mode-string, but you can adapt the code.
(defvar mlc-char-in-mode-line-mode-initialized nil
"Non-nil if `mlc-char-in-mode-line-mode' has been called.")
(define-minor-mode mlc-char-in-mode-line-mode
"Show char after point in mode line, at start of `global-mode-string'."
nil nil nil :group 'Modeline
(unless mlc-char-in-mode-line-mode-initialized
(setq mlc-char-in-mode-line-mode-initialized t)
(setq global-mode-string
(cond ((consp global-mode-string)
(add-to-list 'global-mode-string mlc-mode-line-char-format))
((not global-mode-string)
(list mlc-mode-line-char-format))
((stringp global-mode-string)
(list mlc-mode-line-char-format global-mode-string))))))
mlc-mode-line-char-format does essentially this:
(let* ((ch (following-char))
(str (format (if (= ?% ch) "[%%%c=%06x] " "[%c=%06x] ") ch ch)))
str)
More generally, you can use one of the mode-line variables described in the Elisp manual, node Mode Line Variables. See node Mode Line Data for an understanding of how data you put in the mode line needs to be formatted.
In particular, you can show the value of a symbol in the mode line just by inserting the symbol there. From Mode Line Data:
A symbol as a mode line construct stands for its value. The value
of SYMBOL is used as a mode line construct, in place of SYMBOL.
However, the symbols t and nil are ignored, as is any symbol
whose value is void.
There is one exception: if the value of SYMBOL is a string, it is
displayed verbatim: the %-constructs are not recognized.
Unless SYMBOL is marked as risky (i.e., it has a non-nil
risky-local-variable property), all text properties specified in
SYMBOL’s value are ignored. This includes the text properties of
strings in SYMBOL’s value, as well as all :eval and :propertize
forms in it. (The reason for this is security: non-risky variables
could be set automatically from file variables without prompting
the user.)
read-stringto another question. Thx. – Drew Mar 08 '19 at 19:53completing-read. You cannot use a list of symbols as theDEFAULT-VALUEargument (toread-string,read-command,completing-read, or other functions), but you can use it as theCOLLECTIONarg tocompleting-read. – Drew Mar 08 '19 at 20:19symbol-nameto each predicate symbol, and use the result as aDEFAULT-VALUEarg inread-stringor whatever - e.g.mapcarsymbol-nameover your list of predicate symbols. Butcompleting-readis what you want to use, in general - allow the user completion. – Drew Mar 08 '19 at 20:33