about summary refs log tree commit diff
path: root/pkgs/applications/editors/emacs
diff options
context:
space:
mode:
authorCaleb Chase <caleb@chasecaleb.com>2022-02-22 19:55:58 -0600
committerCaleb Chase <caleb@chasecaleb.com>2022-02-22 20:03:35 -0600
commita131be8f99862d5fdb34c2aa809c8716493ef56e (patch)
tree84553e56640c659cf7b29b20d44738c54b92415e /pkgs/applications/editors/emacs
parent244185c486428aecec8d9e5aa13d2ef6f6432935 (diff)
downloadnixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar.gz
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar.bz2
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar.lz
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar.xz
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.tar.zst
nixlib-a131be8f99862d5fdb34c2aa809c8716493ef56e.zip
emacs: populate load-path recursively
Previous behavior only added <nix_profile>/share/emacs/site-lisp/ and
one level of subdirectories, whereas this commit adds all subdirectories
recursively using normal-top-level-add-subdirs-to-load-path. This
matches the behavior of Emacs on non-Nix distros, which include a
/usr/share/emacs/site-lisp/subdirs.el file with identical recursive
behavior.

See also: https://www.emacswiki.org/emacs/LoadPath
Diffstat (limited to 'pkgs/applications/editors/emacs')
-rw-r--r--pkgs/applications/editors/emacs/site-start.el24
1 files changed, 8 insertions, 16 deletions
diff --git a/pkgs/applications/editors/emacs/site-start.el b/pkgs/applications/editors/emacs/site-start.el
index 3f9ec25d99f0..acc6833b98c9 100644
--- a/pkgs/applications/editors/emacs/site-start.el
+++ b/pkgs/applications/editors/emacs/site-start.el
@@ -5,22 +5,14 @@ The list is ordered from more-specific (the user profile) to the
 least specific (the system profile)"
   (reverse (split-string (or (getenv "NIX_PROFILES") ""))))
 
-;;; Extend `load-path' to search for elisp files in subdirectories of
-;;; all folders in `NIX_PROFILES'. Also search for one level of
-;;; subdirectories in these directories to handle multi-file libraries
-;;; like `mu4e'.'
-(require 'seq)
-(let* ((subdirectory-sites (lambda (site-lisp)
-                             (when (file-exists-p site-lisp)
-                               (seq-filter (lambda (f) (file-directory-p (file-truename f)))
-                                           ;; Returns all files in `site-lisp', excluding `.' and `..'
-                                           (directory-files site-lisp 'full "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)")))))
-       (paths (apply #'append
-                     (mapcar (lambda (profile-dir)
-                               (let ((site-lisp (concat profile-dir "/share/emacs/site-lisp/")))
-                                 (cons site-lisp (funcall subdirectory-sites site-lisp))))
-                             (nix--profile-paths)))))
-  (setq load-path (append paths load-path)))
+;;; Extend `load-path' to search for elisp files in subdirectories of all folders in `NIX_PROFILES'.
+;;; Non-Nix distros have similar logic in /usr/share/emacs/site-lisp/subdirs.el.
+;;; See https://www.gnu.org/software/emacs/manual/html_node/elisp/Library-Search.html
+(dolist (profile (nix--profile-paths))
+  (let ((default-directory (expand-file-name "share/emacs/site-lisp/" profile)))
+    (when (file-exists-p default-directory)
+      (setq load-path (cons default-directory load-path))
+      (normal-top-level-add-subdirs-to-load-path))))
 
 ;;; Remove wrapper site-lisp from EMACSLOADPATH so it's not propagated
 ;;; to any other Emacsen that might be started as subprocesses.