Emacs28 mode line 显示 emacs lisp major mode 的问题

Emacs28 的 emacs-lisp-mode 在mode line 显示为 Elisp/l 或 Elisp/d

用如下方式设置 mode-line-format 显示 major mode

(setq-default mode-line-format (list
                                "%m"
                                "  |  "
                                'mode-name))

为什么 %m 会什么都不显示,而 mode-name 显示正常。

A string is printed verbatim in the mode line except for %-constructs:
  %b -- print buffer name.      %f -- print visited file name.
  %F -- print frame name.
  %* -- print %, * or hyphen.   %+ -- print *, % or hyphen.
	%& is like %*, but ignore read-only-ness.
	% means buffer is read-only and * means it is modified.
	For a modified read-only buffer, %* gives % and %+ gives *.
  %s -- print process status.   %l -- print the current line number.
  %c -- print the current column number (this makes editing slower).
        Columns are numbered starting from the left margin, and the
        leftmost column is displayed as zero.
        To make the column number update correctly in all cases,
	‘column-number-mode’ must be non-nil.
  %C -- Like %c, but the leftmost column is displayed as one.
  %i -- print the size of the buffer.
  %I -- like %i, but use k, M, G, etc., to abbreviate.
  %p -- print percent of buffer above top of window, or Top, Bot or All.
  %P -- print percent of buffer above bottom of window, perhaps plus Top,
        or print Bottom or All.
  %n -- print Narrow if appropriate.
  %t -- visited file is text or binary (if OS supports this distinction).
  %z -- print mnemonics of keyboard, terminal, and buffer coding systems.
  %Z -- like %z, but including the end-of-line format.
  %e -- print error message about full memory.
  %@ -- print @ or hyphen.  @ means that default-directory is on a
        remote machine.
  %[ -- print one [ for each recursive editing level.  %] similar.
  %% -- print %.   %- -- print infinitely many dashes.
Decimal digits after the % specify field width to which to pad.

我寻思着 mode-line-format 里也没说可以用 %m 啊?

看网页文档是有的,不过状态是 obsolete 。我这边 emacs 27.2 是可以使用的,扫了一眼 news.28 没找到相关说明,不确定 28 是不是给删除了。

The following  `%` -construct is still supported, but it is obsolete, since you can get the same result using the variable  `mode-name` .

`%m`    The value of  `mode-name` .

貌似 %m 不支持显示在定义major mode 的时候 mode name 是表达式的情况。

自己写一个函数就可以了,我是master分支

(defun my/mode-line-mode-name ()
  (format "%s "
		  (propertize (format-mode-line mode-name)
					  'face '(:inherit italic))))

(setq-default mode-line-format '("%e" " "
								 (:eval (concat
										 (my/mode-line-mode-name)))))