How to use macOS system line selection colors with lin-mode
I've tried out lin
and it does its job well!
I adapted my old code that uses macOS named system colors to highlight lines for lin
:
(use-package lin
:load-path "~/.emacs.d/src/lin"
:after modus-themes
:config
(defun ct/modus-themes-lin-colors-macos (&optional appearance)
"On macOS, use system default selection colors. Works for dark and light mode."
(when (memq window-system '(mac ns))
(set-face-attribute 'lin-hl nil
:foreground "alternateSelectedControlTextColor"
:background "selectedContentBackgroundColor")))
(add-hook 'modus-themes-after-load-theme-hook #'ct/modus-themes-lin-colors-macos)
(add-hook 'ns-system-appearance-change-functions #'ct/modus-themes-lin-colors-macos)
(dolist (hook '(elfeed-search-mode-hook
notmuch-search-mode-hook))
(add-hook hook #'lin-mode)))
This is quite a striking contrast for anything but list-based selection, so I'm happy that regular hl-line-mode
's faces are accessible again for highlighting the line at point
The ns-system-appearance-change-functions
hook is triggered when you switch dark/light mode on macOS. I added a hook for modus-themes, too, for good measure mostly. Might actually be overkill.
This is the relevant part:
(when (memq window-system '(mac ns))
(set-face-attribute 'lin-hl nil
:foreground "alternateSelectedControlTextColor"
:background "selectedContentBackgroundColor"))
I believe that adding different settings for different OS's to the main code will not pay off since there's no easy way for 1 person to test all these, so it's better documented here (we can happily close the issue right away) or maybe in the README.