假设我正在编写一个 emacs lisp 函数,该函数与位于定义函数的文件相关的文件进行接口(interface)。
- bin/executable
- foo.el
foo.el
:(defun foo ()
(shell-command-to-string
(format "echo '%s' | ./bin/executable"
(buffer-substring-no-properties
(point-min)
(point-max)))))
如果我从
foo.el
运行它然后效果很好。如果我在编辑任何其他文件时调用该函数,则它不起作用,因为路径不正确。我怎样才能可靠地引用
./bin/executable
来自foo.el
无论函数在哪里调用?
最佳答案
使用load-file-name
多变的。
(defconst directory-of-foo (file-name-directory load-file-name))
(defun foo ()
(shell-command-to-string
(format "echo '%s' | %s"
(buffer-substring-no-properties
(point-min)
(point-max))
(expand-file-name "./bin/executable" directory-of-foo))))
关于emacs - elisp - 获取相对于脚本的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26991001/