~/.emacs

(setq last-target "all")

(defun call-make (&optional target) "Call `make' with specified target"
  (if (eq target nil)
      (progn
        (setq last-target (read-from-minibuffer "Build target: " last-target))
        (compile (concat "make -k " last-target))
        )
    (progn (compile "make -k all tags")
           (visit-tags-table "./TAGS"))))

;; Automatic build package in working directory
;; invoke "make" if Makefile is found
;; or do "configure" first if script found
(defun build() "Call configure; make in current directory."
(interactive)
(progn
  (if (get-buffer "*compilation*")
      (kill-buffer "*compilation*"))
  (setq output-buf (get-buffer-create "*compilation*"))
  (princ (type-of output-buf))
  (if (file-exists-p (expand-file-name "Makefile"))
      (call-make)
    (if (file-exists-p (expand-file-name "./configure"))
        (set-process-sentinel
         (start-process "configure" output-buf (expand-file-name "./configure"))
         (lambda (proc event)
           (if (string= event "finished/n")
               (progn (call-make "all tags")
                      (visit-tags-table "./TAGS"))
         )))
      (call-make) ; intended for calling default targets
      ))))

启动时自动检测当前目录是否有 Makefile 或 configure。如果存在其中之一则尝试构建软件包。使用异步进程 start-process 命令
其中 set-process-sentinel 为第一个进程(configure)设置一个事件句柄,当这个进程结束的时候(事件为 "finished/n"),自动调用 lambda 表达式指定的响应过程,既开始执行 make。
第一次写 elisp 脚本,似乎也不是那么难:)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值