萌新提问,貌似 .el 结尾的文件夹没有添加到 load-path 中

我想把site-lisp中的子文件夹都添加到load-path中

(defun add-subdirs-to-load-path (&rest _)
  "Add subdirectories to `load-path'."
  (let ((default-directory (expand-file-name "site-lisp" user-emacs-directory)))
    (normal-top-level-add-subdirs-to-load-path)))
❯ ls
awesome-tray       bind-key      dash.el      emacs-which-key  evil-leader       go-mode.el  nox       swiper       yasnippet
benchmark-init-el  company-mode  diminish.el  evil             expand-region.el  magit       posframe  use-package  yasnippet-snippets

没有以 .el 结尾的都成功 require 成功了, 类似 expand-region.el 在

(require 'expand-region)

的时候就会报这个错误,搜了半天没有找到什么相关的问题

Debugger entered--Lisp error: (file-error "Cannot open load file" "Is a directory" "expand-region")

请问是哪里的操作出现问题了吗 :cold_face:

(let ((base "~/.config/emacs/site-lisp/"))
  (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)))))

解决了部分,但是像magit这种不在一级目录下而是在 "site-lisp/magit/lisp 中的还是没加进来, elisp 我还不熟,我去看看怎么把它搞进来

被 normal-top-level-add-subdirs-to-load-path 排除了:

(not (string-match "\\.elc?\\'" file))

这函数功能乱糟糟的,干脆就不要用了。

load-path 可以手动一个一个加,自动加的话,会缺、会多。另,这是包管理器该干的事情,使用一个包管理器会自动帮你解决。

我是想用 git submodule 来管理,主要是不想在打开 emacs 时等它下载包什么的, 不知道这样做可不可以达到那种效果 :rofl:

有支持 Git 的现成的包管理器,如 straight.elborg,不过肯定都比较折腾。

1 个赞

如果是嫌官方 ELPA 慢的话,可以试试国内镜像

(setq package-archives '(("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
                         ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(setq package-archives '(("gnu"   . "https://mirrors.cloud.tencent.com/elpa/gnu/")
                         ("melpa" . "https://mirrors.cloud.tencent.com/elpa/melpa/")))

还有其它的。

改一下文件夹名字,比如改成emacs-expand-region

哈哈,倒不是慢不慢,我就不想让它执行那个动作 :rofl: