Я использую компиляцию, чтобы вытащить новые файлы из исходного дерева с помощью меркуриального «hg pull». Я выполняю сохранение всех буферов перед нажатием и хотел бы «обновить все открытые буферы» после завершения компиляции «pulling». Я попытался экспериментировать с функциями компиляции-финиширования, но выяснил, что функции, добавленные в список, будут исполняться после «каждой» компиляции. Поскольку я использую компиляцию для поиска идентификаторов «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)
Спасибо Том. Мне хотелось бы увидеть результаты компиляции в окне компиляций. Не могли бы вы подробнее рассказать о том, как использовать функцию set compilation-finish-function? – SFbay007
Сделайте попытку, а затем задайте новый вопрос о любых проблемах, с которыми вы сталкиваетесь. Также, возможно, вы должны принять ответ Тома. – andy256
Функция компиляции-финиширования устарела с момента выпуска Emacs 22. В документации рекомендуется добавить к компиляции-финиш-функции hook. @ andy256: почему вы рекомендуете ответчику принять ответ, который он еще не уверен, действительно решает проблему? –