gpt4 book ai didi

emacs - 等待编译完成

转载 作者:行者123 更新时间:2023-12-05 05:27:39 25 4
gpt4 key购买 nike

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

最佳答案

编译是异步的。因此,您有两个选择。

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

二、设置compilation-finish-function。

关于emacs - 等待编译完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18241100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com