From 4dd393528c831660f3057ef99beda4551b3d17a3 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 21 Apr 2020 09:05:44 +0200 Subject: emacs: properly check the OS and use that MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The font detection was based on the window system, which utterly failed when starting up on server mode. Thus, we should use the `system-type' variable instead. Moreover, I'm taking this oportunity to create two new constants which are convenient to check the two supported OSes, and I'm also checking the OS at the very beginning. Signed-off-by: Miquel Sabaté Solà --- .emacs.d/init.org | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/.emacs.d/init.org b/.emacs.d/init.org index ee8ba6a..30e08ad 100644 --- a/.emacs.d/init.org +++ b/.emacs.d/init.org @@ -79,6 +79,19 @@ individually handled. (message "Your GNU Emacs is a bit old and some functionality will be disabled. Consider upgrading to at least v%s" recver))) #+END_SRC +Check the operating system: + +#+BEGIN_SRC elisp +(defconst IS-LINUX (eq system-type 'gnu/linux) + "Current system is GNU/Linux") + +(defconst IS-MAC (eq system-type 'darwin) + "Current system is MacOS") + +(unless (or IS-LINUX IS-MAC) + (error "This configuration has been checked only on GNU/Linux and MacOS")) +#+END_SRC + Temporarily reduce garbage collection so startup time is lower. Idea taken from [[https://github.com/purcell][@purcell]]. @@ -207,20 +220,21 @@ Use the much fancier =doom-modeline= as our modeline: (use-package all-the-icons :ensure t :config - (require 'cl-lib) - ;; Check if the fonts have been already been installed. If that is not the - ;; case, then install it now. The path detection is taken from + ;; case, then install it now. The path detection is based from ;; all-the-icons.el. - (let* ((font-dest (cl-case window-system - (x (concat (or (getenv "XDG_DATA_HOME") - (concat (getenv "HOME") "/.local/share")) - "/fonts/")) - (mac (concat (getenv "HOME") "/Library/Fonts/" )) - (ns (concat (getenv "HOME") "/Library/Fonts/" )))) + (let* ((font-dest (if IS-LINUX + (concat (or (getenv "XDG_DATA_HOME") + (concat (getenv "HOME") "/.local/share")) + "/fonts/") + (if IS-MAC + (concat (getenv "HOME") "/Library/Fonts/") + nil))) (ttf-path (concat font-dest "all-the-icons.ttf"))) - (unless (file-exists-p ttf-path) + ;; If we were able to detect the OS and we don't have a the file installed, + ;; try to do it now. + (when (and font-dest (not (file-exists-p ttf-path))) (message "Installing fonts...") (all-the-icons-install-fonts)))) -- cgit v1.2.3