From 0570ec90f20d39842213fd930860b09059a767f5 Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Thu, 28 Sep 2017 18:57:19 -0400 Subject: [PATCH] Updated logic for font loading and fallback --- emacs/.emacs.d/README.org | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/emacs/.emacs.d/README.org b/emacs/.emacs.d/README.org index 4bab1db..b30f2d5 100644 --- a/emacs/.emacs.d/README.org +++ b/emacs/.emacs.d/README.org @@ -221,12 +221,27 @@ I don't really want to have to look at menu bars that I'm not going to use *** Fonts -I like Inconsolata so use it if installed. +Quick macro that tries to load the font. If it loads it return =t= so we +know not to try and load anything else if it returns =nil= then we'll +try a different font. #+BEGIN_SRC emacs-lisp :tangle yes - (when (member "Inconsolata" (font-family-list)) ; Set default font - (add-to-list 'default-frame-alist '(font . "Inconsolata-15" )) - (set-face-attribute 'default t :font "Inconsolata-15")) + (defmacro load-font-if-exists (family size) + (if (member family (font-family-list)) ; Set default font + (progn + (let ((font-and-size (format "%s-%s" family size))) + (add-to-list 'default-frame-alist `(font . ,font-and-size)) + (set-face-attribute 'default t :font font-and-size)) + t) + nil)) +#+END_SRC + +I like =Inconsolata-dz= a bit more than =Inconsolata= so use it if installed +otherwise fall back to regular =Inconsolata=. + +#+BEGIN_SRC emacs-lisp :tangle yes + (unless (load-font-if-exists "Inconsolata-dz" 15) + (load-font-if-exists "Inconsolata" 15)) #+END_SRC Make sure that UTF-8 is used everywhere. @@ -1438,3 +1453,4 @@ Stores all backups and temp files in =~/.bak.emacs/= (reverse comments))) #+END_SRC +