Search code examples
emacsorg-mode

How to change the default face of Org mode to different font from the default face of Emac?


Like the title, the face of the normal text portion is default, how can I change the font of that face but only apply to Org-mode.

I also find a face name: org-default, but when I try to change the font of that face using:

(set-face-attribute 'org-default nil :font "Fira Mono" :height 130)

Emac output an error said that face is invalid.

I have tried using this code from another question from the emac sub:

(defun my/org-mode-font-configuartion ()
  (face-remap-add-relative 'default :font "Fira Mono" :height 130))

(add-hook 'org-mode-hook 'my/org-mode-font-configuartion)

But when I use M-x describe-face, the text portion still hasn't changed. Any help would be appreciated.

What I would expect is the default face in Org mode has different font than the default face in Emac.


Solution

  • I was able to fix my problem thanks to Protesilaos Stavrou, you can find more here.

    ;Function only run in Org mode, to separate it with emac.
    (defface your-new-face-remap
        '((t (:font "Fira Mono" :height 130)))
        "My custom font for org mode default.")
    
    (define-minor-mode your-new-face-mode
        "Remap the face of org mode default."
        :local t
        :init-value nil
        (if your-new-face-mode
            ;if true do
            (setq your-new-face-remap-cookie
                (face-remap-add-relative 'default 'your-new-face-remap-style))
            ;if false do
            (face-remap-remove-relative my-comment-remap-cookie)))
    
    (add-hook 'org-mode-hook #'your-new-face-mode)
    

    The defface is really finicky, you must have '((' for it to work.