24.4.9 模拟模式行格式化

你可以使用函数 format-mode-line 根据指定的模式行结构计算出模式行或标题栏中应显示的文本。

Function: format-mode-line format &optional face window buffer

该函数按照 format 格式化一行文本,如同为 window 生成模式行,并以字符串形式返回文本。 参数 window 默认为选中窗口。若 buffernil,所有信息均取自 buffer; 默认情况下信息来自 window 所属的缓冲区。

返回的字符串通常带有与模式行一致的文本属性,包括字体、键盘映射等。 对于 format 未指定 face 属性的字符,会使用由 face 决定的默认值。 若 facet,则表示使用 mode-line(窗口选中时)或 mode-line-inactive(未选中时)。 若 facenil 或省略,则使用默认字体。若 face 为整数, 函数返回值将不包含任何文本属性。

你也可以将其他合法字体指定为 face 的值。指定后,该字体会为 format 未指定字体的字符提供 face 属性。

注意:将 mode-linemode-line-inactiveheader-line 作为 face 时,除返回格式化字符串外,还会使用对应字体的当前定义重新显示模式行或标题栏。 (其他字体不会触发重绘。)

例如,(format-mode-line header-line-format) 返回选中窗口标题栏中应显示的文本 (无标题栏时返回 "")。(format-mode-line header-line-format 'header-line) 返回相同文本,且每个字符携带其在标题栏中实际显示的字体属性,同时重绘标题栏。

emacs

Emacs

org-mode

Orgmode

Donations

打赏

Copyright

© Jasper Hsu

Creative Commons

Creative Commons

Attribute

Attribute

Noncommercial

Noncommercial

Share Alike

Share Alike