作为一个主题控,经常会切换主题,之前切换主题的方式是这样的,M-x,`load-theme`,选中,但是个人认为不够便捷,正好前几天发现了hydra这个插件,也想实践一下
获取主题列表
(setq maple-cycle-themes (mapcar 'symbol-name (custom-available-themes)))
获取当前主题索引
(cl-position (car (mapcar 'symbol-name custom-enabled-themes)) maple-cycle-themes :test 'equal)
获取下一个主题
(setq maple-current-theme-index (+ 1 maple-current-theme-index)) (setq maple-current-theme (nth maple-current-theme-index maple-cycle-themes))
加载主题
(load-theme (intern maple-current-theme) t)
最后得到这样的函数
(defun maple/cycle-theme (num) (interactive) (setq maple-current-theme-index (+ num (cl-position (car (mapcar 'symbol-name custom-enabled-themes)) maple-cycle-themes :test 'equal))) (when (>= maple-current-theme-index (length maple-cycle-themes)) (setq maple-current-theme-index …