让emacs的compile更聪明一些——另一个为xul开发而写的emacs扩展

最近一直在为xul写 yasnippet的snippet,包括javascript的和XUL的,区区从来不抱怨XULrunner程序开发没有IDE,因为emacs已经够快了(调试功能还是想要D~)。

有个问题以前就很想解决。那就是改进emacs的compile。

举例来说吧,如果目录树如下:
顶层目录ext
代码目录ext/src
文档目录ext/doc
你正在编写的代码文件是ext/src/main.js

那如果用M-x compile的话,emacs会尝试找寻ext/src/Makefile,因为当前目录是ext/src
可是一般的Makefile都在顶层目录,这样就会常常出错。。
以前区区处理的方法是时刻开着Makefile的buffer,要编译时选切换buffer,由于有ido-mode加入区区emacs很熟练,这个操作并不是很耗时。。。。

有个ede的emacs扩展也有类似的功能,所以刚区区考察了一下ede的info文档,结论是不太合适~

目录区区的目标是尽可能优化自己XUL的编写的效率,所以有了下面的改写版compile,改进工作还会继续:

(defun jr--compile-get-proper-dir (dir)
  (let ((newdir dir)
        (found nil))
    (while (and (not found)
                (> (length newdir) 1))
      (if (file-exists-p (concat newdir "Makefile"))
          (setq found t)
        (if (string-match "^[a-zA-Z]:[///]$" newdir)
            (setq newdir "")
          (setq newdir (file-name-as-directory (expand-file-name ".." newdir)))
        )))
    (if found newdir dir)))

(defun jr-compile (command &optional comint)
  "Joyer alter the //[compile] command, automatic search upward dirs to find
a Makefile"
  (interactive
   (list
    (let ((command (eval compile-command)))
      (if (or compilation-read-command current-prefix-arg)
      (read-from-minibuffer "Jr-Compile command: "
                command nil nil
                (if (equal (car compile-history) command)
                    '(compile-history . 1)
                  'compile-history))
    command))
    (consp current-prefix-arg)))
  (unless (equal command (eval compile-command))
    (setq compile-command command))
  (save-some-buffers (not compilation-ask-about-save) nil)
  (setq compilation-directory (jr--compile-get-proper-dir default-directory))
  (let ((default-directory compilation-directory))
    (compilation-start command comint)))
(global-set-key [f7] 'jr-compile)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值