等待编译完成 [英] Waiting on compilation to finish

查看:119
本文介绍了等待编译完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用编译从源代码树中使用汞hg拉来提取新文件。
我在拉之前执行所有缓冲区的保存,并希望在编译拉完成后刷新所有打开的缓冲区。
我尝试使用编译完成功能,但发现添加到列表中的函数将在每个编译之后执行。因为我使用编译来搜索IDgid,我不想在每个搜索上刷新打开的文件。
如果在命令之前刷新打开的文件only,而不是在命令之外的每个编译上,我该如何等待编译完成。
这是代码:

I am using compile to pull new files from source tree using mercurial "hg pull". I am performing a save of all buffers before the pull and would like to "refresh all opened buffers" after the compilation "pulling" finishes. I tried experimenting with compilation-finish-functions but found out that the functions added to the list will be executed after "every" compilation. Since I use compile to search IDs "gid" I don't want to refresh opened files on every search. How can I wait on compilation to finish before refreshing opened files "only" while inside a command and not on every compile outside of the command. Here is the code:

; From http://www.emacswiki.org/emacs/CompileCommand
(defun compile-pkg (&optional command startdir)
  "Compile a package, moving up to the parent directory
  containing configure.ac, if it exists. Start in startdir if defined,
  else start in the current directory."
  (interactive)
  (let ((dirname) (dir-buffer nil))
    (setq startdir (expand-file-name (if startdir startdir ".")))
    (setq command  (if command command compile-command))
    (setq dirname (upward-find-file "Makefile" startdir))
;    (setq dirname (if dirname dirname (upward-find-file "Makefile" startdir)))
;    (setq dirname (if dirname dirname (expand-file-name ".")))
    ; We've now worked out where to start. Now we need to worry about
    ; calling compile in the right directory
    (save-excursion
      (setq dir-buffer (find-file-noselect dirname))
      (set-buffer dir-buffer)
      (compile command)
      (kill-buffer dir-buffer)
      )))

(defun upward-find-file (filename &optional startdir)
  "Move up directories until we find a certain filename. If we
  manage to find it, return the containing directory. Else if we
  get to the toplevel directory and still can't find it, return
  nil. Start at startdir or . if startdir not given"
  (let ((dirname (expand-file-name
                  (if startdir startdir ".")))
        (found nil) ; found is set as a flag to leave loop if we find it
        (top nil))  ; top is set when we get
                    ; to / so that we only check it once
    ; While we've neither been at the top last time nor have we found
    ; the file.
    (while (not (or found top))
      ; If we're at / set top flag.
      (if (string= (expand-file-name dirname) "/")
          (setq top t))
      ; Check for the file
      (if (file-exists-p (expand-file-name filename dirname))
          (setq found t)
        ; If not, move up a directory
        (setq dirname (expand-file-name ".." dirname))))
    ; return statement
    (if found (concat dirname "/") nil)))

(defun compile-hgpull ()
  (interactive)
  (save-all-buffers)
  (compile-pkg "hg pull -u")
; if (compile finished) -> (revert-all-buffers)
  )

(global-set-key [f1]    'compile-hgpull) 


推荐答案

编译是异步的。所以,你有两个选择。

compile is async. So, you have two choices.

一,不要使用编译。而是使用其他方法之一调用shell命令,如shell命令或启动进程或调用进程。我认为这可能是首选;我不明白为什么你需要在这里使用编译。

One, don't use compile. Instead use one of the other ways to invoke a shell command, like shell-command or start-process or call-process. I think this is probably preferred; I don't see why you'd need to use compile here.

两个,设置编译完成功能。

Two, set compilation-finish-function.

这篇关于等待编译完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆