all repos — nixfiles @ e55ec214705492e8ac0baaca394b34cabbc23461

System and user configuration, managed by nix and home-manager

Emacs: use dark/light theme on macos according to system
Alan Pearce alan@alanpearce.eu
Mon, 03 Oct 2022 00:08:17 +0200
commit

e55ec214705492e8ac0baaca394b34cabbc23461

parent

3a292a23130db25932a6ceec755e1bb19487e5d3

1 files changed, 27 insertions(+), 4 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -72,7 +72,18 @@ modus-themes-syntax '(alt-syntax)                     modus-themes-hl-line 'nil
                     modus-themes-region '(bg-only)
                     modus-themes-diffs 'desaturated)
-              (load-theme 'modus-operandi t)))
+              (let ((light-mode-theme 'modus-operandi)
+                    (dark-mode-theme 'modus-vivendi))
+                (defun my/set-dark-or-light-theme ()
+                  (let ((appearance (plist-get (mac-application-state) :appearance)))
+                    (cond ((equal appearance "NSAppearanceNameAqua")
+                           (load-theme light-mode-theme t))
+                          ((equal appearance "NSAppearanceNameDarkAqua")
+                           (load-theme dark-mode-theme t)))))
+                (add-hook 'mac-effective-appearance-change-hook #'my/set-dark-or-light-theme)
+                (if (boundp 'mac-effective-appearance-change-hook)
+                    (my/set-dark-or-light-theme)
+                  (load-theme light-mode-theme t)))))
   (if (eq window-system 'x)
       (setq-default line-spacing 0.2))
   (setq frame-background-mode 'light)
@@ -100,12 +111,24 @@ (add-to-list 'default-frame-alist '(ns-appearance . 'light))) 
 (add-to-list 'default-frame-alist '(width . 100))
 (add-to-list 'default-frame-alist '(height . 40))
+(setq-default display-line-numbers 'relative
+              display-line-numbers-widen t)
+
+(defun noct-relative ()
+  "Show relative line numbers."
+  (setq-local display-line-numbers 'relative))
+
+(defun noct-absolute ()
+  "Show absolute line numbers."
+  (setq-local display-line-numbers t))
+
+(add-hook 'evil-insert-state-entry-hook #'noct-absolute)
+(add-hook 'evil-insert-state-exit-hook #'noct-relative)
 
 ;;; Encoding
 
-(setq bidi-paragraph-direction 'left-to-right)
-(when (version<= "27.1" emacs-version)
-  (setq bidi-inhibit-bpa t))
+(setq-default bidi-paragraph-direction 'left-to-right)
+(setq bidi-inhibit-bpa t)
 
 ;;; Dates & Times