Doom emacs 如何得到所有 theme 的列表?

想做一个切换到随机主题的小功能,但是发现在 doom emacs 里面似乎不能直接获得当前所有的主题列表?不知道有什么办法拿到这个 list。

(custom-available-themes) ?

;; `all-completions' is a faster replacement for string filtering than
;; (cl-remove-if-not (lambda (x) (string-match-p "doom" x)) (custom-available-themes))
(all-completions "doom" (custom-available-themes))
;; =>
;; ("doom-Iosvkem"
;;  "doom-acario-dark"
;;  "doom-acario-light"
;;  "doom-challenger-deep"
;;  "doom-city-lights"
;;  "doom-dark+"
;;  "doom-dracula"
;;  "doom-ephemeral"
;;  "doom-fairy-floss"
;;  "doom-gruvbox"
;;  "doom-horizon"
;;  "doom-laserwave"
;;  "doom-manegarm"
;;  "doom-material"
;;  "doom-molokai"
;;  "doom-monokai-classic"
;;  "doom-monokai-pro"
;;  "doom-monokai-spectrum"
;;  "doom-moonlight"
;;  "doom-nord-light"
;;  "doom-nord"
;;  "doom-nova"
;;  "doom-oceanic-next"
;;  "doom-one-light"
;;  "doom-one"
;;  "doom-opera-light"
;;  "doom-opera"
;;  "doom-outrun-electric"
;;  "doom-palenight"
;;  "doom-peacock"
;;  "doom-rouge"
;;  "doom-snazzy"
;;  "doom-solarized-dark"
;;  "doom-solarized-light"
;;  "doom-sourcerer"
;;  "doom-spacegrey"
;;  "doom-tomorrow-day"
;;  "doom-tomorrow-night"
;;  "doom-vibrant"
;;  "doom-wilmersdorf")
2 个赞

唉唉 谢谢,当时用 rg 在 .emacs.d 下面搜索没找到来着。

我如果想在 emacs 做一件事,步骤基本如下:

  1. 想想自己用过得某个功能/函数有没有这目标方面的东西,如果有直接 <C-h f> 看那个函数的源码。
  2. 上网搜索。
  3. 尝试自己实现。

这个函数我也没用过,但是我用 counsel-load-theme 会显示主题列表,所以我看了看该函数的实现,就有这个。 :smile:

1 个赞

不过的 emacs 配置里面似乎没有这个变量。怪不得找不到。

请问这是在什么文件里面呢?我没找到这个变量的定义唉。

这是一个函数啊…

可能是大佬自己写的

custom-available-themes is a compiled function defined in custom.el.gz.

1 个赞

差不多,好多时候,我也是这么找函数的

SPC + h + t 直接切换配色(doom 下)

我的想法是随机选择一个主题而不是快速切换主题。目前已经写好了。

(defun random-choice (items)
  (let* ((size (length items))
         (index (random size)))
    (nth index items)))
(defun +my/pick-random-theme ()
  (interactive)
  (load-theme (random-choice available-themes ) t))

Random theme in Doom Emacs

(defun random-choice (items)
  "Random choice a list"
  (let* ((size (length items))
         (index (random size)))
    (nth index items)))

(defun kr/load-theme-random ()
  "Load random themes of doom-*"
  (interactive)
  (let* ((doom-themes (all-completions "doom" (custom-available-themes)))
         (theme       (random-choice doom-themes)))
    (counsel-load-theme-action theme)
    (message "Current random doom-* theme is: %s" theme)
    (setq doom-theme theme)))

;; Get random themes on Emacs startup
(setq doom-theme (random-choice (custom-available-themes)))