Emacs Lisp:如何将文件夹及其所有第一级子文件夹添加到加载路径

如果我有一个这样的文件夹结构:

~/Projects
    emacs
        package1
            package1-helpers
        package2
            package2-helpers
            package2-more-helpers
        package3
            package3-helpers

如何添加这些文件夹:

>〜/ Projects / emacs
>〜/ Projects / emacs / package1
>〜/ Projects / emacs / package2
>〜/ Projects / emacs / package3

…到我的.emacs文件的加载路径?

我基本上需要一个简短的自动版本的代码:

(add-to-list 'load-path "~/Projects/emacs")
(add-to-list 'load-path "~/Projects/emacs/package1")
(add-to-list 'load-path "~/Projects/emacs/package2")
(add-to-list 'load-path "~/Projects/emacs/package3")
最佳答案
(let ((base "~/Projects/emacs"))
  (add-to-list 'load-path base)
  (dolist (f (directory-files base))
    (let ((name (concat base "/" f)))
      (when (and (file-directory-p name) 
                 (not (equal f ".."))
                 (not (equal f ".")))
        (add-to-list 'load-path name)))))

转载注明原文:Emacs Lisp:如何将文件夹及其所有第一级子文件夹添加到加载路径 - 代码日志