The mode line contents are controlled by a data structure of lists,
strings, symbols, and numbers kept in the buffer-local variable
mode-line-format
. The data structure is called a mode line
construct, and it is built in recursive fashion out of simpler mode line
constructs. The same data structure is used for constructing
frame titles (see section Frame Titles).
A mode line construct may be as simple as a fixed string of text, but it usually specifies how to use other variables to construct the text. Many of these variables are themselves defined to have mode line constructs as their values.
The default value of mode-line-format
incorporates the values
of variables such as mode-name
and minor-mode-alist
.
Because of this, very few modes need to alter mode-line-format
.
For most purposes, it is sufficient to alter the variables referenced by
mode-line-format
.
A mode line construct may be a list, a symbol, or a string. If the value is a list, each element may be a list, a symbol, or a string.
string
%
-constructs. Decimal digits after the `%'
specify the field width for space filling on the right (i.e., the data
is left justified). See section %
-Constructs in the Mode Line.
symbol
t
and nil
are ignored; so 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.
(string rest...) or (list rest...)
(symbol then else)
nil
,
the second element, then, is processed recursively as a mode line
element. But if the value of symbol is nil
, the third
element, else, is processed recursively. You may omit else;
then the mode line element displays nothing if the value of symbol
is nil
.
(width rest...)
(-3 "%p")
.
If you do alter mode-line-format
itself, the new value should
use the same variables that appear in the default value (see section Variables Used in the Mode Line), rather than duplicating their contents or displaying
the information in another fashion. This way, customizations made by
the user or by Lisp programs (such as display-time
and major
modes) via changes to those variables remain effective.
Here is an example of a mode-line-format
that might be
useful for shell-mode
, since it contains the hostname and default
directory.
(setq mode-line-format (list "" 'mode-line-modified "%b--" (getenv "HOST") ; One element is not constant. ":" 'default-directory " " 'global-mode-string " %[(" 'mode-name 'mode-line-process 'minor-mode-alist "%n" ")%]----" '(line-number-mode "L%l--") '(-3 . "%p") "-%-"))
Go to the first, previous, next, last section, table of contents.