What's a recommended way to set the font size for org-mode (or any other major mode) to a certain value that is different from the global font size?

By looking at documentation C-h k C-x C-+, this is what I came up with:

  (defun scale-up-font ()
    (text-scale-increase 2))
  (add-hook 'org-mode-hook 'scale-up-font)

With this, I've noticed loading time for org-mode files to be slightly longer. Is there a better way to do this?

  • I would suggest using the function face-remap-add-relative, or you could also go against what the doc string warns about and set the variable face-remapping-alist directly using setq-local. The approach using the org-mode-hook is fine, but with a faster method such as the one suggested in this comment.. The following linked example does not change the font size, but you could modify it to suit your needs: emacs.stackexchange.com/a/7283/2287 In a different thread, I learned that the display engine expects a potential setting of the face-remapping-alist and is fast.
    – lawlist
    May 24 '20 at 16:14
  • FYI: text-scale-increase uses functions defined in face-remap.el, which utilizes face-remap-add-relative. It is possible that the calculations used to find the appropriate increase are somewhat slow ... If that is the case, then you could make your calculations ahead of time and just set the font size to your liking as suggested in the previous comment. You might also want to read through that library and see if there are any obviously costly functions, e.g., force-window-update and the like ...
    – lawlist
    May 24 '20 at 16:44

Your Answer

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

Browse other questions tagged or ask your own question.