The contents of each mode line are specified by the buffer-local
variable mode-line-format
(see The Top Level of Mode Line Control). This variable
holds a mode line construct: a template that controls what is
displayed on the buffer’s mode line. The value of
header-line-format
specifies the buffer’s header line in the same
way. All windows for the same buffer use the same
mode-line-format
and header-line-format
unless a
mode-line-format
or header-line-format
parameter has been
specified for that window (see Window Parameters).
For efficiency, Emacs does not continuously recompute each window’s
mode line and header line. It does so when circumstances appear to call
for it—for instance, if you change the window configuration, switch
buffers, narrow or widen the buffer, scroll, or modify the buffer. If
you alter any of the variables referenced by mode-line-format
or
header-line-format
(see Variables Used in the Mode Line), or any other
data structures that affect how text is displayed (see Emacs Display), you
should use the function force-mode-line-update
to update the
display.
This function forces Emacs to update the current buffer’s mode line and
header line, based on the latest values of all relevant variables,
during its next redisplay cycle. If the optional argument all is
non-nil
, it forces an update for all mode lines and header lines.
This function also forces an update of the menu bar and frame title.
The selected window’s mode line is usually displayed in a different
color using the face mode-line-active
. Other windows’ mode
lines appear in the face mode-line-inactive
instead.
See Faces.
If you want to have more extensive differences between the mode lines
in selected and non-selected windows, you can use this predicate in an
:eval
construct. For instance, if you want to display the
buffer name in bold in selected windows, but in italics in the other
windows, you can say something like:
(setq-default mode-line-buffer-identification '(:eval (propertize "%12b" 'face (if (mode-line-window-selected-p) 'bold 'italic))))
Some modes put a lot of data in the mode line, pushing elements at
the end of the mode line off to the right. Emacs can “compress” the
mode line if the mode-line-compact
variable is non-nil
by turning stretches of spaces into a single space. If this variable
is long
, this is only done when the mode line is wider than the
currently selected window. (This computation is approximate, based on
the number of characters, and not their displayed width.) This
variable can be buffer-local to only compress mode-lines in certain
buffers.