关于theme的一件小事

(setq-default custom-enabled-themes '(doom-one))
(defun reapply-themes ()
  "Forcibly load the themes listed in `custom-enabled-themes'."
  (dolist (theme custom-enabled-themes)
  (unless (custom-theme-p theme)
  (load-theme theme)))
(custom-set-variables `(custom-enabled-themes (quote ,custom-enabled-themes))))
(add-hook 'after-init-hook 'reapply-themes)


(defun light ()
  "Activate a light color theme."
  (interactive)
  (setq custom-enabled-themes '(doom-solarized-light))
  (reapply-themes))

(defun dark ()
  "Activate a dark color theme."
  (interactive)
  (setq custom-enabled-themes '(doom-dracula))
  (reapply-themes))

我从purcell的配置里拿了这一段,想定义主题的设置,可是在实际应用的时候发现每次重启都会出现那个是否写入配置的交互。这个。

Loading a theme can run lisp code ? Really load? 
treat this theme as safe in future session?

只有在一次重启内重复切换时不会出现,一但重启,所有主题载入的时候都会再出现一次,我觉得可能是custom.el的问题,有没有大佬指教一下。

第一次加上代码,求原谅

试试将最后一句 (load-theme theme) 修改成 (load-theme theme t)

感谢 ,完美解决。只是为什么purcell的原本配置怎么会没有呢

其实我有点不大懂,为什么要手动设置 custom 变量,或许是purcell 的个人习惯.

加不加t有什么影响

来看一下文档:

(load-theme THEME &optional NO-CONFIRM NO-ENABLE)

:around advice: ‘ad-Advice-load-theme’
:before advice: No documentation

Load Custom theme named THEME from its file.
The theme file is named THEME-theme.el, in one of the directories
specified by ‘custom-theme-load-path’.

If the theme is not considered safe by ‘custom-safe-themes’,
prompt the user for confirmation before loading it.  But if
optional arg NO-CONFIRM is non-nil, load the theme without
prompting.

加了t 就是NO-CONFIRM 不为空,就不会在加载theme 的时候问你是不是确定要加载了.

1 个赞