lol

Merge pull request #33416 from the-kenny/emacs-site-lisp-subdirectory-support

Emacs `site-lisp` subdirectory support

authored by

Michael Raskin and committed by
GitHub
91eb41b1 718de7c2

+31 -10
+31 -10
pkgs/applications/editors/emacs/site-start.el
··· 1 - ;;; NixOS specific load-path 2 - (setq load-path 3 - (append (reverse (mapcar (lambda (x) (concat x "/share/emacs/site-lisp/")) 4 - (split-string (or (getenv "NIX_PROFILES") "")))) 5 - load-path)) 1 + (defun nix--profile-paths () 2 + "Returns a list of all paths in the NIX_PROFILES environment 3 + variable, ordered from more-specific (the user profile) to the 4 + least specific (the system profile)" 5 + (reverse (split-string (or (getenv "NIX_PROFILES") "")))) 6 + 7 + ;;; Extend `load-path' to search for elisp files in subdirectories of 8 + ;;; all folders in `NIX_PROFILES'. Also search for one level of 9 + ;;; subdirectories in these directories to handle multi-file libraries 10 + ;;; like `mu4e'.' 11 + (require 'seq) 12 + (let* ((subdirectory-sites (lambda (site-lisp) 13 + (when (file-exists-p site-lisp) 14 + (seq-filter (lambda (f) (file-directory-p (file-truename f))) 15 + ;; Returns all files in `site-lisp', excluding `.' and `..' 16 + (directory-files site-lisp 'full "^\\([^.]\\|\\.[^.]\\|\\.\\..\\)"))))) 17 + (paths (apply #'append 18 + (mapcar (lambda (profile-dir) 19 + (let ((site-lisp (concat profile-dir "/share/emacs/site-lisp/"))) 20 + (cons site-lisp (funcall subdirectory-sites site-lisp)))) 21 + (nix--profile-paths))))) 22 + (setq load-path (append paths load-path))) 23 + 6 24 7 25 ;;; Make `woman' find the man pages 8 26 (eval-after-load 'woman 9 27 '(setq woman-manpath 10 - (append (reverse (mapcar (lambda (x) (concat x "/share/man/")) 11 - (split-string (or (getenv "NIX_PROFILES") "")))) 28 + (append (mapcar (lambda (x) (concat x "/share/man/")) 29 + (nix--profile-paths)) 12 30 woman-manpath))) 13 31 14 32 ;;; Make tramp work for remote NixOS machines 15 33 (eval-after-load 'tramp 34 + ;; TODO: We should also add the other `NIX_PROFILES' to this path. 35 + ;; However, these are user-specific, so we would need to discover 36 + ;; them dynamically after connecting via `tramp' 16 37 '(add-to-list 'tramp-remote-path "/run/current-system/sw/bin")) 17 38 18 39 ;;; C source directory ··· 22 43 ;;; from: /nix/store/<hash>-emacs-<version>/share/emacs/site-lisp/site-start.el 23 44 ;;; to: /nix/store/<hash>-emacs-<version>/share/emacs/<version>/src/ 24 45 (let ((emacs 25 - (file-name-directory ;; .../emacs/ 26 - (directory-file-name ;; .../emacs/site-lisp 27 - (file-name-directory load-file-name)))) ;; .../emacs/site-lisp/ 46 + (file-name-directory ; .../emacs/ 47 + (directory-file-name ; .../emacs/site-lisp 48 + (file-name-directory load-file-name)))) ; .../emacs/site-lisp/ 28 49 (version 29 50 (file-name-as-directory 30 51 (concat