19

Is it possible to set different fonts following the major mode? Say Inconsolata-12 in org-mode buffers and Symbola-12 in all remaining modes. Or at least, is it possible to do a

(set-frame-font "Inconsolata" t)

after switching to org-mode buffers?

21

buffer-face-set and buffer-face-mode in Emacs 23 or later is designed for exactly this. From the Emacs wiki:

;; Use variable width font faces in current buffer
 (defun my-buffer-face-mode-variable ()
   "Set font to a variable width (proportional) fonts in current buffer"
   (interactive)
   (setq buffer-face-mode-face '(:family "Symbola" :height 100 :width semi-condensed))
   (buffer-face-mode))

 ;; Use monospaced font faces in current buffer
 (defun my-buffer-face-mode-fixed ()
   "Sets a fixed width (monospace) font in current buffer"
   (interactive)
   (setq buffer-face-mode-face '(:family "Inconsolata" :height 100))
   (buffer-face-mode))

 ;; Set default font faces for Info and ERC modes
 (add-hook 'erc-mode-hook 'my-buffer-face-mode-variable)
 (add-hook 'Info-mode-hook 'my-buffer-face-mode-variable)
4

You can do the change by using the org-mode-hook, like this

(add-hook 'org-mode-hook (lambda () (set-frame-font "Inconsolata" t)))

Which will change the font whenever you enter org mode. The downside is that it doesn't change the font back after you leave org mode.

Edit: as pointed out by Ryan, you can follow the advice on this wiki page to do it per buffer. I haven't tested extensively, but this seems to work

(add-hook 'org-mode-hook (lambda ()
                            (setq buffer-face-mode-face '(:family "Inconsolata"))
                            (buffer-face-mode)))

It might have issues if you want to use buffer-face-mode in other buffers, but if you only use it for this then it should work.

  • 4
    Have you looked at buffer-face-set? This wiki page indicates you can do the same thing per buffer instead of per frame. – Ryan Nov 3 '14 at 20:11
  • 1
    Great, thanks, this is exactly was I was looking for. This community is extraordinary. – csantosb Nov 3 '14 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.