I'm working on a small function to recursively load my Emacs customizations. In writing it, I noticed the argument of
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
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
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)))))))