24.4.3 模式行控制的顶层结构

全局控制模式行的变量是 mode-line-format

User Option: mode-line-format

该变量的值是一个模式行构造,用于控制模式行的内容。它在所有缓冲区中始终为缓冲区局部变量。

如果在某个缓冲区中将此变量设为 nil,则该缓冲区不会显示模式行。(高度仅为一行的窗口同样不会显示模式行。)

mode-line-format 的默认值设计为使用其他变量的值,例如 mode-line-positionmode-line-modes (后者又会整合 mode-nameminor-mode-alist 等变量的值)。绝大多数模式无需直接修改 mode-line-format。对于大多数场景,只需修改 mode-line-format 直接或间接引用的部分变量即可。

若确实需要修改 mode-line-format 本身,新值应沿用默认值中出现的相同变量(see 模式行中使用的变量),而非复制其内容或以其他方式展示信息。这样一来,用户或 Lisp 程序(如 display-time 与各类主模式)通过修改这些变量所做的自定义设置依然有效。

以下是一个适用于 Shell 模式的假想 mode-line-format 示例(实际 Shell 模式并不会设置 mode-line-format):

(setq mode-line-format
  (list "-"
   'mode-line-mule-info
   'mode-line-modified
   'mode-line-frame-identification
   "%b--"
   ;; 注意:此表达式在构造列表时求值。
   ;; 它生成一个仅为字符串的模式行构造。
   (getenv "HOST")
   ":"
   'default-directory
   "   "
   'global-mode-string
   "   %[("
   '(:eval (format-time-string "%F"))
   'mode-line-process
   'minor-mode-alist
   "%n"
   ")%]--"
   '(which-function-mode ("" which-func-format "--"))
   '(line-number-mode "L%l--")
   '(column-number-mode "C%c--")
   '(-3 "%p")))

(变量 line-number-modecolumn-number-modewhich-function-mode 用于启用对应的次要模式;与通常情况一致,这些变量名同时也是对应次要模式的命令名。)

emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike