reddit / emacs

Advice Needed: A good way to tell whether I'm using an undocked laptop vs one attached to multiple screens.

vale_fallacia · 2022-12-08 13:14
My current `init.el` is shared between 3 computers: my Linux desktop, my main work (intel) macbook with thunderbolt dock + closed lid + 3 attached screens, and my (m1) macbook that I use on the couch etc. I switch between Linux and MacOS specific configs with several blocks like this: (defun my-system-type-is-darwin () "Return non-nil if system is darwin-based (Mac OS X)." (string-equal system-type "darwin") ) (when (my-system-type-is-darwin) (global-set-key (kbd "s-/") 'comment-or-uncomment-region-or-line) ) So I've got the different system types fairly easily distinguished. Unfortunately, the font sizes that work OK on the main docked macbook with multiple screens don't work well on the undocked/portable macbook. Any advice on a robust way to tell which mac I'm using, with a view to the config working on other screen configurations? I was thinking I could just detect a hard-coded "if 3 screens of these dimensions then do X, if 1 screen of those dimensions do Y" but I'm not sure the best way to do that, or even if that *is* the best way to do what I want. Any other tips for sharing a single init.el between multiple computers?
alrasdk · 2022-12-08 13:58
I'm not sure how to query a particular screen setup, but (system-name) should at least let you which machine you're on.
yurikhan · 2022-12-08 14:26
You should *probably* focus on getting your DPI settings right. Then, the same font size in points gives you roughly the same angular size of characters on all your screens. The exact way to do that is highly platform-dependent though.
vale_fallacia · 2022-12-08 15:01
Aha! I hadn't considered the DPI angle. Searching for that brings me to: https://emacs.stackexchange.com/questions/28390/quickly-adjusting-text-to-dpi-changes Thank you for thinking about this differently to me, you've helped a lot!
yurikhan · 2022-12-08 15:40
What I see there is only Emacs workarounds, but I feel the correct solution should lie in platform-specific configuration. E.g. on X11/GNU/Linux you’d adjust either the `Xft.dpi` setting in the resource database (`.Xresources`), or your desktop environment’s settings manager, or your `/etc/X11/xorg.conf[.d]` config file(s).
ComprehensiveAd5882 · 2022-12-08 16:37
Just so we are clear, I don't think OP is worried about GNU/Linux emacs .
ieure · 2022-12-08 16:53
I have the same Emacs config working on multiple machines, across Linux and sometimes macOS. I'm not sure if this is exactly what you need, but I hope it's at least helpful to get you thinking about how to approach the problem. The main thing I do is have customizations broken up along several dimensions: - Customizations which apply everywhere: `.emacs.d/customizations/global.el`. - Per-OS customizations: `.emacs.d/customizations/os-WHATEVER.el` (ex `os-darwin.el`, `os-gnu-linux.el`. - Per-machine customizations: `.emacs.d/customizations/machine-HOSTNAME.el`. This code in my `init.el` loads the right set of stuff for a given host: ;; Store customizations per-host (setq custom-file (format "~/.emacs.d/customizations/machine-%s.el" (car (split-string system-name "\\.")))) (mapc (lambda (file) (load file 'noerror)) (list ;; Global "~/.emacs.d/customizations/global.el" ;; Platform (format "~/.emacs.d/customizations/os-%s.el" (replace-regexp-in-string "/" "-" (symbol-name system-type))) ;; System custom-file)) The main drawback to this approach is that there's no enumeration of which settings belong to what source, so saving customizations overwrites the machine-specific one. I keep meaning to do something about that, but I've been using this thing for over a decade and haven't, so I'll probably continue to not. If you need to have the same computer adapt to multiple display layouts, this approach can't cope with that. On macOS, you're going to have to deal with something like OSA (meaning AppleScript, meaning one of the worst programming languages I've ever used) to get at that info and print it in a format Emacs can read in and use.
yurikhan · 2022-12-08 17:13
What, you mean, DPI on one of the Macs is wrong out of the box? Is that even legal in Mac land? /s
deaddyfreddy · 2022-12-08 17:23
> Any other tips for sharing a single init.el between multiple computers? `use-package` has `:if` keyword, so it's pretty easy to describe every case. As for the predicate to detect screen size, why don't use `(system-name)` instead?
ComprehensiveAd5882 · 2022-12-08 17:39
No.
bravosierrasierra · 2022-12-08 18:02
may be you need (system-name) based "(when"?
harizvi · 2022-12-08 18:53
I have this to allow for plugging into various monitors, works on recent Emacsen (28, 29): ;; allow for changing monitors (defun hr/set-default-font-height (&optional frame) (interactive) "Calculate the correct default font height from the primary monitor attached." (let* ((display-attrs (car (display-monitor-attributes-list))) (monitor-name (cdr (assq 'name display-attrs))) (monitor-size (/ (cadr (assq 'mm-size display-attrs)) 25.4)) (hr/default-font-height (if (and monitor-name (string-match "P2715Q\\|U32\\|S27B350" monitor-name)) 150 (if (and monitor-size (> monitor-size 27)) 150 190)))) (set-face-attribute 'default nil :height hr/default-font-height :weight 'medium)))
HM0880 · 2022-12-09 19:17
I have been looking for functions to query the monitor size and to adjust the font, so this function is perfect. Thanks!