Domanda

Is there are way to change the fonts depending on the major mode? If so, how? I usually use a proportional font, but only for dired mode and shell mode, I want to switch to a non-proportional font. These modes do not have a special face for them, and just use the default face, so it cannot be just done by setting the font faces. I want to be able to automatically switch depending on the major mode, perhaps using hooks.

È stato utile?

Soluzione

Use the mode hook, hooking your function that remaps the face for the current buffer using the face remapping feature:

(defun use-monospace ()
  "Switch the current buffer to a monospace font."
  (face-remap-add-relative 'default '(:family "Monospace")))

(add-hook 'dired-mode-hook 'use-monospace)
...

Altri suggerimenti

Another alternative to defining your own function as above, is to use buffer-face-mode. Normally this will use variable-pitch for buffers it is enabled in, but since you want to use a variable pitch font as the default you can change it to fixed-pitch instead:

(setq buffer-face-mode-face 'fixed-pitch)
(add-hook 'dired-mode-hook 'buffer-face-mode)
(add-hook 'shell-mode-hook 'buffer-face-mode)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top