Table of Contents
|Emacs term||popular term||use|
|variable pitch font||proportional font||usual text|
|fixed pitch font||monospace font||source code & ascii art|
1 Enabling proportional font for text-mode buffers
(add-hook 'text-mode-hook 'variable-pitch-mode)
With that, every major mode, including org-mode, inheriting from text-mode will display buffers in proportional font.
2 Using monospace font for tables and code blocks, while still using variable-pitch-mode in org mode buffers
(defun my-adjoin-to-list-or-symbol (element list-or-symbol) (let ((list (if (not (listp list-or-symbol)) (list list-or-symbol) list-or-symbol))) (require 'cl-lib) (cl-adjoin element list))) (eval-after-load "org" '(mapc (lambda (face) (set-face-attribute face nil :inherit (my-adjoin-to-list-or-symbol 'fixed-pitch (face-attribute face :inherit)))) (list 'org-code 'org-block 'org-table 'org-block-background)))
Now org buffers text should be displayed in proportional font, except for tables and source blocks which are displayed in monospace font.
If you see glitches in tables and source blocks, or if you find the text not anti-aliased, apply this bug fix for fixed-pitch
3 How does the code work?
It adds the face fixed-pitch to the inherit attribute of the faces: org-code, org-block, org-table, and org-block-background.
How does one find out that those four faces are the faces to target? This command
lists all faces active at point.
I did not check the other three, but when I checked org-code face, its inherit attribute was the symbol
shadow is yet another face name. The above code replaces that attribute with the list:
so that the combined effect of fixed-pitch and shadow applies to org-code face.
Does this break anything? Yes, I found that when I export as html an org file which contains a source block whose contents is itself an org buffer which contains a source block, Emacs reports error and says that (fixed-pitch shadow) is not a symbol. Probably related to htmlize.
4 Info buffers
Why not enable variable-pitch-mode on Info buffers as well, now that we know how to make parts of text to be in monospace font.
;;; display Info mode buffers in proportional font (add-hook 'Info-mode-hook 'variable-pitch-mode) ;;; but code examples in monospace font (defvar my-rx-info-code (rx bol " " (* not-newline) eol)) (add-hook 'Info-mode-hook 'my-Info-font-lock) (defun my-Info-font-lock () (interactive) (require 'org) (font-lock-add-keywords nil `((,my-rx-info-code . ;; let's just use org-block (quote org-block) )))) ;;; following doesn't work. don't know why ;; (font-lock-add-keywords ;; 'Info-mode ;; `((,my-rx-info-code ;; . ;; (quote org-block) ;; )))
my-rx-info-code matches lines starting with five spaces. It intends to match emacs lisp code examples, but there are lots of false positives as well.
5 Markdown mode buffers
To display source code blocks or pre blocks in monospace:
(eval-after-load "markdown-mode" '(mapc (lambda (face) (set-face-attribute face nil :inherit (my-adjoin-to-list-or-symbol 'fixed-pitch (face-attribute face :inherit)))) (list 'markdown-pre-face 'markdown-inline-code-face)))