Emacs 等待编译完成

Emacs 等待编译完成,emacs,elisp,Emacs,Elisp,我正在使用compile使用mercurial“hg pull”从源代码树中提取新文件。 我在拉取之前执行所有缓冲区的保存,并希望在编译“拉取”完成后“刷新所有打开的缓冲区”。 我尝试了编译完成函数,但发现添加到列表中的函数将在“每次”编译后执行。因为我使用compile来搜索id“gid”,所以我不想每次搜索都刷新打开的文件。 在命令内部刷新打开的文件之前,如何等待编译完成,而不是在命令外部的每次编译中刷新打开的文件。 代码如下: ; From http://www.emacswiki.org

我正在使用compile使用mercurial“hg pull”从源代码树中提取新文件。 我在拉取之前执行所有缓冲区的保存,并希望在编译“拉取”完成后“刷新所有打开的缓冲区”。 我尝试了编译完成函数,但发现添加到列表中的函数将在“每次”编译后执行。因为我使用compile来搜索id“gid”,所以我不想每次搜索都刷新打开的文件。 在命令内部刷新打开的文件之前,如何等待编译完成,而不是在命令外部的每次编译中刷新打开的文件。 代码如下:

; 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) 

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

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


设置编译完成函数。

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

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


第二,设置编译完成功能。

如果您想同步运行shell命令,然后查看其输出,那么使用
shell命令来字符串
可能比
compile
更容易,如果您想同步运行shell命令,然后查看其输出,使用
shell命令来字符串
可能比使用
compile

更容易。我想在“编译”窗口中查看编译结果。您能详细介绍一下如何使用集合编译完成函数吗?尝试一下,然后就您遇到的任何问题提出一个新问题。另外,也许您应该接受Tom的答案。compilation-finish-function自Emacs 22以来一直被弃用。文档建议改为添加到编译完成函数挂钩中@andy256:为什么你建议提问者接受一个他还不确定问题是否真的解决了的答案?Andy,在这里提问之前,我已经尝试过使用shell命令了。正如我所说,出于许多不同的原因,我需要编译窗口。我计划使用这个方法来执行其他shell命令,比如make/push/pull…等等,Aaron,我已经对你提到的这个函数进行了研究,但是发现你可以在我绑定到F1的函数的“外部”将其他函数挂接到它。因为我也在为“gid”使用编译,所以我不知道;我不希望每次编译时都刷新打开的文件,但只能在按F1键时刷新。谢谢Tom。我想在“编译”窗口中查看编译结果。您能详细介绍一下如何使用集合编译完成函数吗?尝试一下,然后就您遇到的任何问题提出一个新问题。另外,也许您应该接受Tom的答案。compilation-finish-function自Emacs 22以来一直被弃用。文档建议改为添加到编译完成函数挂钩中@andy256:为什么你建议提问者接受一个他还不确定问题是否真的解决了的答案?Andy,在这里提问之前,我已经尝试过使用shell命令了。正如我所说,出于许多不同的原因,我需要编译窗口。我计划使用这个方法来执行其他shell命令,比如make/push/pull…等等,Aaron,我已经对你提到的这个函数进行了研究,但是发现你可以在我绑定到F1的函数的“外部”将其他函数挂接到它。因为我也在为“gid”使用编译,所以我不知道;我不希望每次编译时都刷新打开的文件,但只能在按F1键时刷新。谢谢您的回复。但是,正如我上面解释的,我想要编译窗口,因为它显示了更多信息。我只需要一种方法来查找编译何时在我的函数“内部”完成。我不希望“每次”编译完成时都执行与我函数相关的函数。谢谢您的回复。但是,正如我上面解释的,我想要编译窗口,因为它显示了更多信息。我只需要一种方法来查找编译何时在我的函数“内部”完成。我不希望“每次”编译完成时都执行与me函数相关的函数。