Set Emacs defaut font face per-buffer/mode

emax picture emax · Feb 10, 2009 · Viewed 8.9k times · Source

How do you change the default face which Emacs uses to style text on a per-mode basis?

For example, say that I am already happy with the face customizations that I have, which include a default fixed-width font. However, in one particular mode (markdown-mode.el, say), I want the default font to be variable-width.

It is easy to style headers, links etc. uniquely for markdown-mode: simply place the cursor over the styled text and M-x describe-face, then click the link to customize it.

However, the default face is the face used if no other face is specified, so it is not specific to markdown-mode and if modified will affect all other modes.

What magic can I put in the markdown-mode-hook to set the default face for buffers using this mode?

Answer

jrockway picture jrockway · Feb 11, 2009

How about something like this:

(add-hook 'markdown-mode-hook (lambda () (variable-pitch-mode t))

You can then customize the variable-pitch face, and the other faces in the buffer will inherit from this instead of the default face.

Read the docs for buffer-face-mode for more customization details. (BufFace is also used for text-scale-increase and text-scale-decrease... very useful.)