【已解决】如何在切换主题时自动运行设置字体的代码?

我用 SPC T n 切换主题时 字体不是我想要的,我希望在每次切换主题后自动运行自定义的一个函数 set-cnfonts ,请教如何找到对应的hook ?

已找到解决方法:

(add-hook 'spacemacs-post-theme-change-hook 'set-cnfonts)

可以试试我的一个advice函数。

(defcustom load-theme-before-hook nil
  "Functions to run before load theme."
  :type 'hook)

(defcustom load-theme-after-hook nil
  "Functions to run after load theme."
  :type 'hook)

(defun load-theme-hook-wrapper (origin-func theme &rest args)
  "A wrapper of hooks around `load-theme'."
  (mapc #'disable-theme custom-enabled-themes)
  (run-hook-with-args 'load-theme-before-hook theme)
  (apply origin-func theme args)
  (run-hook-with-args 'load-theme-after-hook theme))

(advice-add 'load-theme :around #'load-theme-hook-wrapper)

然后使用这些hook就行了。

谢谢回复! 学习了