From 1506ab49e39cb208774ac49c480b77e9edb4dea7 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Sat, 26 Aug 2023 09:20:29 +0800 Subject: [PATCH] emacs: correct the order of profiles and their sub dirs in load-path This patch does two things: 1. making user profiles preferred over system profiles 2. putting sub dirs of one profile to the right place - before this patch, they are appended to the end of load-path - after this patch, they are inserted right after the profile Example value of load-path before this patch: /run/current-system/sw/share/emacs/site-lisp/ /etc/profiles/per-user/user/share/emacs/site-lisp/ /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp/elpa /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp/elpa/wgrep-20230203.1214 /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/site-lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/site-lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/lisp/vc ... /etc/profiles/per-user/user/share/emacs/site-lisp/elpa /etc/profiles/per-user/user/share/emacs/site-lisp/elpa/jinx-20230730.1200 /run/current-system/sw/share/emacs/site-lisp/elpa /run/current-system/sw/share/emacs/site-lisp/elpa/repology-1.2.3 after this patch: /etc/profiles/per-user/user/share/emacs/site-lisp /etc/profiles/per-user/user/share/emacs/site-lisp/elpa /etc/profiles/per-user/user/share/emacs/site-lisp/elpa/jinx-20230730.1200 /run/current-system/sw/share/emacs/site-lisp /run/current-system/sw/share/emacs/site-lisp/elpa /run/current-system/sw/share/emacs/site-lisp/elpa/repology-1.2.3 /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp/elpa /nix/store/hash1-emacs-packages-deps/share/emacs/site-lisp/elpa/wgrep-20230203.1214 /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/site-lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/site-lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/lisp /nix/store/hash2-emacs-29.1-rc1/share/emacs/29.1/lisp/vc ... --- pkgs/applications/editors/emacs/site-start.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/editors/emacs/site-start.el b/pkgs/applications/editors/emacs/site-start.el index acc6833b98c9..668b76cfd3e8 100644 --- a/pkgs/applications/editors/emacs/site-start.el +++ b/pkgs/applications/editors/emacs/site-start.el @@ -8,8 +8,11 @@ least specific (the system profile)" ;;; 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))) +(dolist (profile (reverse (nix--profile-paths))) + ;; `directory-file-name' is important to add sub dirs to the right place of `load-path' + ;; see the source code of `normal-top-level-add-to-load-path' + (let ((default-directory (directory-file-name + (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))))