2

我正在使用 compile 使用 mercurial“hg pull”从源树中提取新文件。我在拉取之前执行所有缓冲区的保存,并希望在编译“拉取”完成后“刷新所有打开的缓冲区”。我尝试使用编译完成函数进行试验,但发现添加到列表中的函数将在“每次”编译后执行。由于我使用编译来搜索 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) 
4

2 回答 2

1

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

一、不要使用编译。而是使用其他方法之一来调用 shell 命令,例如 shell-command 或 start-process 或 call-process。我认为这可能是首选;我不明白为什么你需要在这里使用 compile 。

二、设置compile-finish-function。

于 2013-08-14T20:11:19.883 回答
0

如果你想同步运行一个 shell 命令,然后查看它的输出,它可能shell-command-to-stringcompile.

于 2013-08-15T14:18:57.413 回答