reddit / emacs

[auto-dark-emacs] - An automatic theme changer for Emacs on macOS - UPDATED!

LionyxML · 2022-11-04 20:31
LionyxML · 2022-11-04 20:32
Hello there! My humble package just got updated to version `0.5`. If you're using the great `emacs-plus` formulae, with compiled `System appearance change` plugin, it now uses the provided plugin as the preferred method of detecting a switch on macOS theme (which does not rely on polling and thus is a lot faster!). If such plugin is not present it then falls back to the old polling method.Would appreciate any suggestions/good critique/help/stars: Repo: [https://github.com/LionyxML/auto-dark-emacs](https://github.com/LionyxML/auto-dark-emacs) Also available on MELPA: [https://melpa.org/#/auto-dark](https://melpa.org/#/auto-dark)
reliktary · 2022-11-05 01:10
I use it for few months now and it's great. Thank you! Works perfectly with auto color schema in my macos. I also use `auto-dim-other-buffers` package which dims inactive buffers and your `auto-dark-dark-mode-hook` and `auto-dark-light-mode-hook` are really helpful because when a theme changes I also want to change the "dim color". Thanks for thinking about those hook and adding them.
LionyxML · 2022-11-05 02:42
To be fair it is a collaborative work. The feature you're describing was added by this PR ([https://github.com/LionyxML/auto-dark-emacs/pull/10](https://github.com/LionyxML/auto-dark-emacs/pull/10)). Good ideas are always welcome :D Glad it is useful! Thanks!
xenodium · 2022-11-05 10:31
If you fancy toggling macOS dark mode from emacs https://twitter.com/xenodium/status/1583573083004493825?s=46&t=d_tebyYVCHdYDg_LslXLkw
m_sachs · 2022-11-05 11:20
This looks very good! As a sidenote, does anyone know if something similar exists for Gnome? Thanks!
quzyte · 2022-11-06 11:13
Here's what I came up with some time ago (for doom-emacs on ubuntu). It works by checking the current theme using dconf settings. Hope it helps. ;; Automatically detect & set dark background according to system theme ;; set default (light-mode) theme here (setq my-light-theme 'doom-one-light) ;; set theme for dark-mode here (setq my-dark-theme 'doom-one) ;; set the frequency of checks (in seconds) (setq doom-theme-auto-refresh-duration 9) (setq doom-theme my-light-theme) (setq my-auto-theme my-light-theme) ;; If theme is manually changed during a session, then STOP automatically updating theme: to do so, we use the variable my-auto-theme to keep track of current theme. ;; If it is not your intended behaviour, then simply replace the function `auto-toggle-dark-theme` with `set-doom-theme-based-on-system-theme` in the last line (where function is started with repeat timer) (defun set-doom-theme-based-on-system-theme () (setq system-dark-theme-status (if (string= "'Yaru-dark'\n" (shell-command-to-string "dconf read /org/gnome/desktop/interface/gtk-theme")) 0 1)) (cond ((and (eq 0 system-dark-theme-status) (string= doom-theme my-light-theme)) (progn (load-theme my-dark-theme) (setq my-auto-theme my-dark-theme))) ((and (eq 1 system-dark-theme-status) (string= doom-theme my-dark-theme)) (progn (load-theme my-light-theme) (setq my-auto-theme my-light-theme))))) (defun auto-toggle-dark-theme () (when (string= doom-theme my-auto-theme) (set-doom-theme-based-on-system-theme))) (let ((timer-max-repeats 1)) (run-with-timer 0 doom-theme-auto-refresh-duration 'auto-toggle-dark-theme))
m_sachs · 2022-11-06 18:01
Thanks a lot! I'll upload a modified version for Adwaita/Gnome dark mode when I have a minute.
stibbons · 2022-11-07 08:26
For what it's worth, the [emacs-mac](https://github.com/railwaycat/homebrew-emacsmacport) port provides a `mac-effective-appearance-change-hook` hook to do the same thing as the System appearance change plugin. I use it like this: ``` (defun my/appearance-change-hook () (let ((appearance (plist-get (mac-application-state) :appearance))) (cond ((equal appearance "NSAppearanceNameAqua") (load-theme light-mode-theme)) ((equal appearance "NSAppearanceNameDarkAqua") (load-theme dark-mode-theme))))) (add-hook 'after-init-hook 'my/appearance-change-hook) (add-hook 'mac-effective-appearance-change-hook 'my/appearance-change-hook) ```
LionyxML · 2022-11-21 22:46
Nice. I’ll keep this in mind and try to incorporate it.
LionyxML · 2022-11-21 22:47
We now have support for linux (under gnome) if you’re willing to give it a try.
LionyxML · 2022-11-21 22:47
Noice
m_sachs · 2022-11-22 07:05
Thanks a lot for letting me know.