2016-06-07 62 views
0

我需要输出由batch-compile生成的elisp字节码到自定义目录。定制值byte-compile-dest-file-function似乎这是相关的:如何将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) 

的:

(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的代码更容易在其展开的形式读去函数my-dest-file-function计算正确的文件名,但它似乎根本没有被使用,也没有使用(batch-byte-compile)函数。

如何纠正上述elisp代码以产生所需的效果?我想避免在代码中使用任何单引号来轻松地使用shell和Makefiles。

我的emacs版本是24.5.1。

+0

请参阅[设置字节编译目标文件函数](http://stackoverflow.com/questions/13957049/setting-byte-compile-dest-file-function) –

+0

'batch-byte-compile'旨在被调用用'-f'。我猜你应该使用不同的编译功能。 – tripleee

+0

@tripleee这个用法是合法的,请参阅Brian对实际问题的回答。 –

回答

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,这确实对自己什么都没有。

+0

啊,我太亲近了! ;)这正是我需要知道的,非常感谢你! –