From efbc61c3d8739cc5ab5bb8b98b503b1c8122c3be Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Sat, 9 Mar 2024 19:12:32 +0100 Subject: [PATCH] Automatically toggle light and dark theme with macOS system appearance --- init.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/init.el b/init.el index 2fc2119..7444b95 100644 --- a/init.el +++ b/init.el @@ -131,6 +131,14 @@ (setq ef-themes-to-toggle '(ef-day ef-night)) (mapc #'disable-theme custom-enabled-themes) (load-theme 'ef-night :no-confirm) + (when (eq window-system 'ns) + (defun dl/themes-toggle-with-system (appearance) + "Load dark or light theme depending on system appearance on macOS." + (mapc #'disable-theme custom-enabled-themes) + (pcase appearance + ('light (load-theme 'ef-day :no-confirm)) + ('dark (load-theme 'ef-night :no-confirm)))) + (add-hook 'ns-system-appearance-change-functions #'dl/themes-toggle-with-system)) :bind ("" . ef-themes-toggle)) (use-package diminish