从 Emacs 打开和关闭 macOS 黑暗模式并适配 Emacs 主题

auto-dark-emacs - My attempt to make emacs follow the global Dark Mode on MacOS : emacs 启发,写了一个用来开关 macOS 黑暗模式的命令,顺便适配下 Emacs 的主题:

(defun mac-toggle-dark-mode ()
  "Toggle dark mode"
  (interactive)
  (do-applescript "
tell application \"System Events\"
    tell appearance preferences
        set dark mode to not dark mode
    end tell
end tell"))

(defun mac-dark-mode-p ()
  "Return t if dark mode is on, otherwise return nil."
  (string=
   "true"
   (do-applescript
    "tell application \"System Events\" to get dark mode of appearance preferences")))

(defun chunyang-mac-toggle-theme ()
  "打开或关闭黑暗模式,并设置 Emacs 主题."
  (interactive)
  (mac-toggle-dark-mode)
  (mapc 'disable-theme custom-enabled-themes)
  (load-theme
   (if (mac-dark-mode-p)
       'sanityinc-tomorrow-night
     'sanityinc-tomorrow-day)
   t))
2 个赞

我是用了完全相反的思路:mac port 加进了一个新的 color list,其中提供了一批根据系统亮色/暗色自动切换的颜色名字。

自己的 theme 里主要使用这些颜色的话,Emacs 的颜色就可以跟随系统自动切换了。

我自己用的 theme:basic-theme.el · GitHub
对应的博文:https://9.obelus.net/2019/05/30/emacs-color-macos.html

2 个赞

楼上两位都是大神啊

楼上3位都是大神啊