summaryrefslogtreecommitdiff
path: root/lisp/custom.el
diff options
context:
space:
mode:
authorBasil L. Contovounesios <contovob@tcd.ie>2018-06-04 02:12:33 +0100
committerStefan Monnier <monnier@iro.umontreal.ca>2018-07-13 11:28:16 -0400
commit70d702d3b1c40f72059bb5694bd805b1c65d141d (patch)
treecb59139dbdde17172e36b649a598db478829a498 /lisp/custom.el
parent530aa469a4de7b4800557ae783f6c450df59a5b4 (diff)
downloademacs-70d702d3b1c40f72059bb5694bd805b1c65d141d.tar.gz
Fix custom-available-themes file expansion
For discussion, see thread starting at https://lists.gnu.org/archive/html/emacs-devel/2018-05/msg00222.html. * lisp/custom.el: (custom-available-themes): Use directory-files instead of performing arbitrary wildcard expansion in file names. (custom-theme--load-path): Document return value. * test/lisp/custom-tests.el: New file. (custom-theme--load-path): New test.
Diffstat (limited to 'lisp/custom.el')
-rw-r--r--lisp/custom.el26
1 files changed, 16 insertions, 10 deletions
diff --git a/lisp/custom.el b/lisp/custom.el
index b8ea8811a2a..4536788eb20 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1311,19 +1311,25 @@ The returned symbols may not correspond to themes that have been
loaded, and no effort is made to check that the files contain
valid Custom themes. For a list of loaded themes, check the
variable `custom-known-themes'."
- (let (sym themes)
+ (let ((suffix "-theme\\.el\\'")
+ themes)
(dolist (dir (custom-theme--load-path))
- (when (file-directory-p dir)
- (dolist (file (file-expand-wildcards
- (expand-file-name "*-theme.el" dir) t))
- (setq file (file-name-nondirectory file))
- (and (string-match "\\`\\(.+\\)-theme.el\\'" file)
- (setq sym (intern (match-string 1 file)))
- (custom-theme-name-valid-p sym)
- (push sym themes)))))
- (nreverse (delete-dups themes))))
+ ;; `custom-theme--load-path' promises DIR exists and is a
+ ;; directory, but `custom.el' is loaded too early during
+ ;; bootstrap to use `cl-lib' macros, so guard with
+ ;; `file-directory-p' instead of calling `cl-assert'.
+ (dolist (file (and (file-directory-p dir)
+ (directory-files dir nil suffix)))
+ (let ((theme (intern (substring file 0 (string-match-p suffix file)))))
+ (and (custom-theme-name-valid-p theme)
+ (not (memq theme themes))
+ (push theme themes)))))
+ (nreverse themes)))
(defun custom-theme--load-path ()
+ "Expand `custom-theme-load-path' into a list of directories.
+Members of `custom-theme-load-path' that either don't exist or
+are not directories are omitted from the expansion."
(let (lpath)
(dolist (f custom-theme-load-path)
(cond ((eq f 'custom-theme-directory)