Skip to content

Commit

Permalink
Refactor doom-{path,file,dir,glob}
Browse files Browse the repository at this point in the history
Breaking change: doom-glob would formerly return a string (if only one
match) or a list. Now it always returns a list.
  • Loading branch information
hlissner committed May 24, 2021
1 parent 13f316e commit a8e5743
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
36 changes: 16 additions & 20 deletions core/autoload/files.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,37 @@ This is used by `file-exists-p!' and `project-file-exists-p!'."
`(file-exists-p ,filevar))
,filevar)))))

(defun doom--path (&rest segments)
(let ((segments (delq nil segments))
;;;###autoload
(defun doom-path (&rest segments)
"Constructs a file path from SEGMENTS.
Ignores `nil' elements in SEGMENTS."
(let ((segments (remq nil segments))
file-name-handler-alist
dir)
(while segments
(setq dir (expand-file-name (car segments) dir)
segments (cdr segments)))
(setq segment (pop segments)
dir (expand-file-name
(if (listp segment)
(apply #'doom-path dir segment)
segment)
dir)))
dir))

;;;###autoload
(defun doom-glob (&rest segments)
"Construct a path from SEGMENTS and expand glob patterns.
Returns nil if the path doesn't exist.
Ignores `nil' elements in SEGMENTS."
(let* (case-fold-search
(dir (apply #'doom--path segments)))
(if (string-match-p "[[*?]" dir)
(file-expand-wildcards dir t)
(if (file-exists-p dir)
dir))))

;;;###autoload
(defun doom-path (&rest segments)
"Constructs a file path from SEGMENTS.
Ignores `nil' elements in SEGMENTS."
(if segments
(apply #'doom--path segments)
(file!)))
(let (case-fold-search)
(file-expand-wildcards (apply #'doom-path segments) t)))

;;;###autoload
(defun doom-dir (&rest segments)
"Constructs a path from SEGMENTS.
See `doom-path'.
Ignores `nil' elements in SEGMENTS."
(when-let (path (apply #'doom-path segments))
(directory-file-name (file-name-directory path))))
(when-let (path (doom-path segments))
(directory-file-name path)))

;;;###autoload
(cl-defun doom-files-in
Expand Down
4 changes: 2 additions & 2 deletions core/autoload/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ each package."
(mapc (fn! ((cat . mod))
(if-let (packages-file
(pcase cat
(:private (doom-glob doom-private-dir "packages.el"))
(:core (doom-glob doom-core-dir "packages.el"))
(:private (car (doom-glob doom-private-dir "packages.el")))
(:core (car (doom-glob doom-core-dir "packages.el")))
(_ (doom-module-locate-path cat mod "packages.el"))))
(with-current-buffer
(or (get-file-buffer packages-file)
Expand Down
2 changes: 1 addition & 1 deletion core/cli/autoloads.el
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ one wants that.")
in (append (list doom-core-dir)
(cdr (doom-module-load-path 'all-p))
(list doom-private-dir))
if (doom-glob dir "autoload.el") collect it
if (doom-glob dir "autoload.el") collect (car it)
if (doom-glob dir "autoload/*.el") append it)
(mapcan #'doom-glob doom-autoloads-files))
nil)
Expand Down
16 changes: 7 additions & 9 deletions core/cli/byte-compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ and your private config files, respectively. To recompile your packages, use
'doom build' instead."
(doom-cli-byte-compile
(if (or core-p private-p)
(append (when core-p
(list (doom-glob doom-emacs-dir "init.el")
doom-core-dir))
(when private-p
(list doom-private-dir)))
(append (if core-p (doom-glob doom-emacs-dir "init.el"))
(if core-p (list doom-core-dir))
(if private-p (list doom-private-dir)))
(or (y-or-n-p
(concat "WARNING: Changes made to your config after compiling it won't take effect until\n"
"this command is rerun or you run 'doom clean'! It will also make error backtraces\n"
"much more difficult to decipher.\n\n"
"If you intend to use it anyway, remember this or it will come back to bite you!\n\n"
"Continue anyway?"))
(user-error "Aborted"))
(append (list (doom-glob doom-emacs-dir "init.el")
doom-core-dir)
(cl-remove-if-not
(append (doom-glob doom-emacs-dir "init.el")
(list doom-core-dir)
(seq-filter
;; Only compile Doom's modules
(lambda (path) (file-in-directory-p path doom-emacs-dir))
(doom-rpartial #'file-in-directory-p doom-emacs-dir)
;; Omit `doom-private-dir', which is always first
(cdr (doom-module-load-path)))))
recompile-p
Expand Down
2 changes: 1 addition & 1 deletion modules/email/notmuch/autoload.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
(doom-glob (or (getenv "XDG_CONFIG_HOME")
"~/.config")
"isync/mbsyncrc"))
(format "-c %S" config-file)
(format "-c %S" (car config-file))
"")))
(`offlineimap
"offlineimap && notmuch new")
Expand Down
2 changes: 1 addition & 1 deletion modules/lang/dart/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:config
(when (and (featurep! +flutter) IS-LINUX)
(when-let (path (doom-glob "/opt/flutter/bin/cache/dart-sdk"))
(setq flutter-sdk-path path)))
(setq flutter-sdk-path (car path))))
(set-ligatures! '(dart-mode)
;; Functional
:def "Function"
Expand Down

0 comments on commit a8e5743

Please sign in to comment.