Re: Propertize C string for percent position in mode-line?
Michael Heerdegen via Users list for the GNU Emacs text editor <[email protected]> Wed, 08 Jul 2026 01:52:44 +0200
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
Frank Steiner <[email protected]> writes: > [...] > And these two work identically inside this construct: > > (propertize "L%l C%c %o" 'face 'modeline-red-face) > '(:propertize "L%l C%c %o" face modeline-red-face) Note that these are completely different things: the first is an expression to be evaluated, the second is a list describing a mode line construct. Obviously, in the first case the result is again used as a string specifying a mode-line construct, so it is not displayed literally but you get the % specs substituted. I did not know that this is the case - it doesn't seem to be documented. I mean, that the return value of :eval mode-line constructs gets a recursive interpretation, that I did not know. Nice. > But only the latter construct allows lists like > '(:propertize ("L%l C%c %o") face modeline-red-face) > '(:propertize ("L%l C%c " (-3 "%o")) face modeline-red-face) The reason for that should be clear now. > While I'm still trying to understand that in detail, I'm > totally lost when looking at > > '(:propertize (list -3 "%o") face modeline-red-face) > '(:propertize (-3 "%o") face modeline-red-face) > > The first line shows "Bottom" in the mode-line while the second one > shows "Bot". But shouldn't (list -3 "%o") return exactly (-3 "%o")? > > No matter how much I read about it, sometimes this "what is evaluated > when" is still a mystery :-) | ‘(LIST REST...)’ | A list whose first element is a string or list means to process all | the elements recursively and concatenate the results. - see (info "(elisp) Mode Line Data"). Your problem is that you did not understand that the "language" used to describe the format of the mode-line is _not_ Emacs Lisp but something entirely different. Both languages use lists, and they share some names (so that they are easier to remember), but apart from that it's just 2 entirely different languages. The exception: `:eval' does allow to specify an Elisp expression. This is Emacs, so of course this is made possible. That you use it at top-level (which, I think, is not a good idea, already for reasons of efficiency) is the perfect recipe to get confused entirely. So please, unless you are entirely new to Lisp, just read said (info "(elisp) Mode Line Data") info node carefully (again) and afterwards everything should be crystal clear. Just keep an eye on which parts of your spec will be interpreted as which language. Michael.