I'm working on a small function to recursively load my Emacs customizations. In writing it, I noticed the argument of load
, MUST-SUFFIX
, requires the FILE
argument to not include a directory name to capitalize on the suffix "autodetection" behavior (I only want it to load based on load-suffixes
).
I thought I'd try temporarily setting load-path
, since the description of load
also mentions:
This function searches the directories in `load-path'.
When I tried setting load-path
in a let
to the current directory, it wouldn't load any of the files. However, when I temporarily appended it to the beginning of load-path, it seemed to work.
I'm wondering what the difference is. Since I am making use of functions from dash.el
and cl-lib
, do these need to be in load-path?
Here is what I wrote (sorry it's a bit jumbled, I threw it together rather quickly, since my current solution for the same task much slower):
(defun my-load-recursive (directory)
(let ((load-path (cons directory load-path))
(dir-contents
(->> (directory-files directory nil nil 'nosort)
(-remove
(lambda (element)
(or (string-equal element ".")
(string-equal element ".."))))
(-separate
(lambda (file)
(file-regular-p
(expand-file-name file directory)))))))
(destructuring-bind (files dirs) dir-contents
(nconc
(delq
nil
(mapcar
(lambda (file)
(when (load file 'noerror 'nomessage nil 'mustsuffix)
(expand-file-name file directory)))
(delete-dups (mapcar 'file-name-base files))))
(car
(mapcar
#'my-load-recursive
(mapcar
(lambda (dir)
(expand-file-name dir directory))
dirs)))))))
load-path
, an elisp command you expect to load one of your files, what happens when you try to load it, and what you expect to happen?load-path
to a list ? Or just to a directory path string? (And if you're going to clobber it completely, be very careful that nothing you're loading will itself try to load/require something not in your directory.)(let ((load-path (cons directory load-path))))
with(let ((load-path (list directory))))
, and it gave me the output I was looking for. If you create an answer from your comment, I can accept it.