2013-03-31 41 views
3

有在.emacs中获得二郎项目路径defun,我怎么能执行一个shell命令执行以下操作:在emacs中使用钢筋?

cd *~/erlang-project-folder* 
make 

我用钢筋搭建我的项目,并且有一个Makefile尽一切努力。

我可以通过覆盖erlang-compile-function来编译,但我对Emacs Lisp不熟悉,请帮忙。

这里是我的.emacs:

(defun erlang-project-dir() 
    (let* ((src-path (file-name-directory (buffer-file-name))) 
     (pos (string-match "/src/" src-path))) 
    (if pos (substring src-path 0 (+ 1 pos)) src-path))) 

;; there is an error: wrong type argument: commandp 
(defun my-inferior-erlang-compile() 
    (shell-command. 
    (concat (concat (concat "cd" erlang-project-dir) "; make")))) 

(defvar erlang-compile-function 'my-inferior-erlang-compile) 

回答

3

依靠目录结构相反的,它是更好地尝试找到rebar.config文件是在项目的根目录下。

(defun my-find-rebar-root() 
    (let ((dir (locate-dominating-file default-directory "rebar.config"))) 
    (or dir default-directory))) 

之后,你可以使用这个功能编译:这可以通过下面的代码来实现

(defun my-inferior-erlang-compile() 
    (interactive) 
    (let ((default-directory (my-find-rebar-root))) 
    (compile "make"))) 

虽然,我不知道该make是正确的命令在这里 - 也许是更好地使用rebar compile而不是?

P.S.我希望,我会找到一些空闲时间,并将在EDE中完成螺纹钢的支持 - 在这种情况下,它将成为与项目工作相同的统一界面。

+0

嗨,@亚历克斯,谢谢。但是'(defvar erlang-compile-function'my-inferior-erlang-compile)'报告“错误的类型参数:commandp,my-inferior-erlang-compile” – goofansu

+0

啊,看起来使用劣erlang编译来编译erlang环境中的缓冲区,而不是执行外部shell命令。我会建议绑定一些键来调用编译函数,例如'(defun my-erlang-mode-hook()(local-set-key [f9]'my-inferior-erlang-compile)) (add- hook'erlang-mode-hook'my-erlang-mode-hook)' –

+0

我编辑了代码,添加了'(interactive)',所以这个命令将被视为命令... –

相关问题