By-host configs in Doom. Custom starting window sizes.
I’ve got a few Macs and a few Linux machines and they all respond differently to some basic font size stuff and starting window dimensions. For the laptops, I don’t mind if they start Emacs maximized. For the desktops, their screen geometries differ enough that I end up fiddling around. On the Macs I’ve got Rectangle Pro to make a preset and keyboard shortcut, but even that’s a little annoying.
I used to have a bunch of conditional logic in config.org
to manage all this, but it was sort of a pain to pick through when adding a machine, so I wanted to isolate the individual machine configurations a little. I’m guessing it could be useful for other stuff in the future, but for now it handles some appearance stuff.
For by-host configs, I added this to my config.org
:
1(let ((hostname (system-name)))
2 (let ((hostname-file (expand-file-name (concat hostname ".el") doom-private-dir)))
3 (when (file-exists-p hostname-file)
4 (load-file hostname-file))))
That just looks for a file in my Doom directory with the hostname.el
naming convention.
A sample hostname.el
file looks like this:
1(setq doom-font (font-spec :family "Fira Code" :size 14.0 :weight 'medium))
2(setq mixed-pitch-set-height 15)
3(set-face-attribute 'default nil :family "Fira Code" :height 140)
4(set-face-attribute 'fixed-pitch nil :family "Fira Code")
5(set-face-attribute 'variable-pitch nil :family "Helvetica Neue")
6
7(setq initial-frame-alist
8 '((width . 171)
9 (height . 66)
10 (left . 728)
11 (top . 166)))
12
13(setq default-frame-alist
14 '((width . 171)
15 (height . 66)
16 (left . 728)
17 (top . 166)))
The initial-frame-alist
and default-frame-alist
dimensions came from this function:
1(defun my/print-frame-setup-snippet ()
2 "Print a config snippet for setting the current frame size and position."
3 (interactive)
4 (let* ((w (frame-width))
5 (h (frame-height))
6 (pos (frame-position))
7 (l (car pos))
8 (top-pos (cdr pos)))
9 (with-temp-buffer
10 (insert (format "(setq initial-frame-alist\n '((width . %d)\n (height . %d)\n (left . %d)\n (top . %d)))\n\n"
11 w h l top-pos))
12 (insert (format "(setq default-frame-alist\n '((width . %d)\n (height . %d)\n (left . %d)\n (top . %d)))"
13 w h l top-pos))
14 (kill-new (buffer-string))
15 (message "!!! Frame setup snippet copied to clipboard! Paste it into your config.el."))))
So, set the Emacs frame up the way you want, then run that function, and paste it into hostname.el
.