Hello, I decided to keep my doom folder at github, so I could sync my config between laptop and desktop.
This is okay but laptop has different resolution than the desktop, making the fonts appear small. Please note, my elisp knowledge is worth a week.
My first attempt was to add bare elisp to config.el. After a few rounds, I made stuff like this work:
(setq my-font-size
(if (getenv "emacs_font_size")
(string-to-number (getenv "emacs_font_size"))
my-default-font-size))
(setq doom-font
(font-spec :family my-font
:size my-font-size
:weight my-font-weight))
The few rounds I mentioned above can be summarized as:
-
Exporting the variables from the shell. I had zsh, so that also took a few rounds, but none the less managed to do it.
-
Making doom recognize the new
env
s. This was taken care of with adoom sync
. -
I wanted to do the same for
pitch
font as well. So that let me with 6 envs to export and import.
All was working fine, but then the process didn’t seem very streaming. So with my week’s worth of elisp, I decided to write some functions for proof of concept
.
(defun mb/load-env ()
"loads local dotenv"
(interactive)
(setq envs (split-string (f-read "~/.doom.d/.env") "\n" t))
(dolist (env envs)
(set 'keyval (split-string-and-unquote env "="))
(set 'key (car keyval))
(set 'val (car (cdr keyval)))
(setenv key val)
(print "done")
))
(defun mb/set-env-fonts()
"sets font from env"
(interactive)
(mb/load-env)
(setq doom_font (getenv "doom_font"))
(setq doom_font_length (length (split-string doom_font "\, ")))
(setq doom_fonte (split-string doom_font "\, "))
(if (and (> doom_font_length 1) doom_font)
(progn (setq doom-font
(font-spec :family (nth 0 doom_fonte)
:size (string-to-number(nth 1 doom_fonte))
:weight (make-symbol (concat (nth 2 doom_fonte)))))
(print (nth 1 doom_fonte))
(doom/reload-font))))
-
This reads the .env through emacs, doesn’t require any shell magic.
-
This also does not put any bare elisp into the config, I can hook this somewhere, and can call without exiting emacs.
This is working fine too, but before I go and try to optimize this, I wanted to ask if I am reinventing the wheel and was there already a better way to handle this task of dotenv for doom.