Mac 中从 GUI 启动 Emacs 时找不到执行路径

最近在学习lisp,我使用 mac, 用 brew 安装 sbcl, 在控制台直接可以键入sbcl运行。

然后在.emacs 加入 (setq inferior-lisp-program "sbcl") 竟然不行,找不到路径。要 (setq inferior-lisp-program "/usr/local/bin/sbcl") 才行。

奇怪的以前明明是可以的。 大家能帮我解惑一下。涉及到什么机制?

可以用 (executable-find "sbcl")

Search for COMMAND in `exec-path' and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'.

Shell 下一个可执行文件要仅用名字(而不用完整的路径)来执行,需要把它放到 PATH 中,而对于 Emacs 来说则是 exec-path。一般境况下,Emacs 启动的时候会根据 PATH 初始化 exec-path,但是 Mac 下从 Finder (Dock 等)启动的 GUI 的 Emacs 不能接受到你给 Shell 设定的 PATH,最终的结果就是 /usr/local/bin/ 不在 exec-path 中。你可以手动调整 exec-path 或使用 exec-path-from-shell。在终端中启动 Emacs (open -a Emacs)也能解决这个问题。

3 个赞

exec-path-from-shell 啊,就是这个。以前装了忘记了!

谢谢楼上两位的回复