Search code examples
emacsfontsthemeselispmodeline

Setting fonts to parts of modeline


How can I use multiple fonts in the modeline? For example, If want it to look like

Line: 23 Size: 3000

with Line and Size in a different font than the modeline font, how should

(setq-default mode-line-format '(
    "Line: %l Size: %i"
))

be modified?


Solution

  • Use propertize. For example, to get Line: and Size: in bold as in your example:

    (setq-default mode-line-format `(
        ,(propertize "Line:" 'face 'bold)
        " %l "
        ,(propertize "Size:" 'face 'bold)
        " %i"
    ))
    

    You can use M-x list-faces-display to see samples of defined faces, or define your own.

    For future reference, you can take a look at the documentation for any variable you're trying to customize with C-h v; the help for mode-line-format mentions using propertize.