21

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?

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
csantosb
  • 1,045
  • 6
  • 15

2 Answers2

25

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)
Ryan
  • 3,989
  • 1
  • 26
  • 49
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.

resueman
  • 401
  • 3
  • 10
  • 4
    Have you looked at `buffer-face-set`? [This wiki page](http://www.emacswiki.org/emacs/FacesPerBuffer) indicates you can do the same thing per buffer instead of per frame. – Ryan Nov 03 '14 at 20:11
  • 1
    Great, thanks, this is exactly was I was looking for. This community is extraordinary. – csantosb Nov 03 '14 at 20:26