5

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?

sawa
  • 165,429
  • 45
  • 277
  • 381

1 Answers1

4

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.

Nicholas Riley
  • 43,532
  • 6
  • 101
  • 124
  • Thanks. But your code does not work as is. I am looking at the documentation, and trying different versions without `,` before `(`, and with/without `:propertize` but that does not work either. – sawa May 27 '11 at 04:13
  • 1
    I wrote the code in Emacs; it works (http://sabi.net/temp/modeline.png). Make sure you're using a backtick (`\``) not a quote (`'`). The `:propertize` form has the problem with `risky-local-variable` as described in the documentation. – Nicholas Riley May 27 '11 at 04:20
  • It worked. I didn't know the use of backtick, and had used a quote. That was the problem. Thanks. – sawa May 27 '11 at 04:24
  • How can I set part of it not the whole mode line, such as I only want to set the line:column part, not set the whole mode line into just the line:column???? – CodyChan Dec 02 '14 at 01:11
  • Is it possible to propertize the `"%l"` and other special percent-sign variables? – BallpointBen Nov 12 '17 at 18:58
  • Sure! You can put a `%l` or whatever inside `propertize` too. – Nicholas Riley Nov 14 '17 at 16:47