0

this is my current font configuration:

;; Default
(set-face-attribute 'default nil :font "Hack" :height 180)

;; Variable-pitch
(set-face-attribute 'variable-pitch nil :font "Hack" :height 180)

;; Fixed-pitch
(set-face-attribute 'fixed-pitch nil :font "DejaVu Sans Mono")
(defun my/org-fixed-pitch ()
  (set-face-attribute 'org-table nil :inherit 'fixed-pitch)
  (set-face-attribute 'org-block nil :inherit 'fixed-pitch :foreground nil)
  (set-face-attribute 'org-code  nil :inherit '(shadow fixed-pitch)))

;; International Phonetic Alphabet
(set-fontset-font t 'phonetic (font-spec :family "DejaVu Sans Mono"))
(dolist (char (string-to-list "æθðŋʷʸˈˌ"))
  (set-fontset-font nil char (font-spec :family "DejaVu Sans Mono")))

The my/org-fixed-pitch function is called when Org mode is launched and ensures that tables and code blocks are always in a monospaced font if I ever decide to switch the variable-pitch to Times New Roman.

The phonetic alphabet code ensures that certain IPA characters are displayed in DejaVu Sans Mono instead of Hack.

The problem with my actual code is that if any of the fonts are missing on my computer Emacs hangs on startup and gives an error. Another problem is that emacs --daemon doesn't launch.

I did some research on the Internet and defining the fonts in the built-in faces package seems to be a better approach as missing fonts won't cause Emacs to hang. The daemon mode works too.

(use-package faces
    :ensure nil
    :preface
    (defun my/org-fixed-pitch ()
      (set-face-attribute 'org-table nil :inherit 'fixed-pitch)
      (set-face-attribute 'org-block nil :inherit 'fixed-pitch :foreground nil)
      (set-face-attribute 'org-code  nil :inherit '(shadow fixed-pitch)))
    :custom-face
    (default ((nil (:family "Hack" :height 180))))
    (variable-pitch ((nil (:family "Hack" :height 180))))
    (fixed-pitch ((nil (:family "DejaVu Sans Mono"))))
    :custom
    (set-fontset-font t 'phonetic (font-spec :family "DejaVu Sans Mono"))
    (dolist (char (string-to-list "æθðŋʷʸˈˌ"))
      (set-fontset-font nil char (font-spec :family "DejaVu Sans Mono"))))

However I'm not sure if I did it right with the phonetic alphabet code putting it inside the :custom keyword.

Also, I was wondering in ditching the custom org-fixed-pitch function and defining those on org's :custom-face property, like so:

(use-package org
  :ensure nil
  :hook (org-mode . (lambda ()
                      (org-indent-mode)
                      ;(my/org-fixed-pitch)))
  :bind (("C-c l" . org-store-link)
         ("C-c a" . org-agenda)
         ("C-c c" . org-capture))
  :custom-face
  (org-table ((nil (:inherit 'fixed-pitch))))

0

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.