我需要将batch-compile
生成的elisp字节码输出到自定义目录。自定义值byte-compile-dest-file-function
似乎与此相关:
(defcustom byte-compile-dest-file-function nil
"Function for the function `byte-compile-dest-file' to call.
It should take one argument, the name of an Emacs Lisp source
file name, and return the name of the compiled file."
:group 'bytecomp
:type '(choice (const nil) function)
:version "23.2")
我走到/opt/local/bin/emacs -batch --eval '(defun my-dest-file-function (filename) (let ((pwd (expand-file-name ".")) (basename (replace-regexp-in-string ".*/" "" filename))) (concat (file-name-as-directory pwd) basename "c"))) (setq byte-compile-dest-file-function (quote my-dest-file-function)) (batch-byte-compile)' /Users/michael/Workshop/project/example/elisp/example1.el
elisp 代码以其展开形式更易于阅读:
(defun my-dest-file-function (filename)
(let ((pwd (expand-file-name "."))
(basename (replace-regexp-in-string ".*/" "" filename)))
(concat (file-name-as-directory pwd) basename "c")))
(setq byte-compile-dest-file-function (quote my-dest-file-function))
(batch-byte-compile)
函数my-dest-file-function
计算正确的文件名,但似乎根本不使用它,也不会使用(batch-byte-compile)
函数。
如何更正上面的 elisp 代码以产生所需的效果?我想避免使用 elisp 代码中的任何单引号来轻松使用shell和Makefile。
我的emacs版本是24.5.1。
答案 0 :(得分:1)
您需要将整个内容包装在progn
:
(progn
(defun my-dest-file-function (filename)
(let ((pwd (expand-file-name "."))
(basename (replace-regexp-in-string ".*/" "" filename)))
(concat (file-name-as-directory pwd) basename "c")))
(setq byte-compile-dest-file-function (quote my-dest-file-function))
(batch-byte-compile))
之前,你只是执行第一个语句defun
,它本身没有任何作用。