- 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.")
"Show char after point in mode line, at start of `global-mode-string'."
nil nil nil :group 'Modeline
(setq mlc-char-in-mode-line-mode-initialized t)
(cond ((consp global-mode-string)
(add-to-list 'global-mode-string mlc-mode-line-char-format))
(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)))
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
SYMBOL is used as a mode line construct, in place of
However, the symbols
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.
SYMBOL is marked as risky (i.e., it has a non-
risky-local-variable property), all text properties specified in
SYMBOL’s value are ignored. This includes the text properties of
SYMBOL’s value, as well as all
forms in it. (The reason for this is security: non-risky variables
could be set automatically from file variables without prompting