如何设置emacs以便在新编辑期间浏览以前的编译错误?
有两件事对我不起作用:
当第二次编译正在进行时,M-g M-g(下一个错误)功能不起作用。
我将我的emacs拆分为5个不均匀的窗口(水平分割窗口),编译“窗口”是大小的两倍(dbl监视器设置)。当我启动编译时,它总是出现在最后一个双编译窗口中。现在它为自己打开了一个新窗口。
答案 0 :(得分:3)
这是一个似乎满足您所有要求的解决方案:
*compilation-old*
缓冲区始终保持在同一窗口中next-error
不会破坏*compilation-old*
的末尾(defun my-compilation-finish-function (buffer msg)
;; Don't do anything if we are in a derived mode
(when (with-current-buffer buffer (eq major-mode 'compilation-mode))
;; Insert the last compilation output at the end of *compilation-old*
(if (get-buffer "*compilation-old*")
(with-current-buffer "*compilation-old*"
(save-excursion
(goto-char (point-max))
(insert-buffer buffer)))
(with-current-buffer buffer
(rename-buffer "*compilation-old*")))))
(add-hook 'compilation-finish-functions 'my-compilation-finish-function)
(defadvice compile (around my-compile-show-old activate)
"Show the *compilation-old* buffer after starting the compilation"
(let ((buffer (current-buffer)))
(when (get-buffer "*compilation-old*")
(pop-to-buffer "*compilation-old*")
(switch-to-buffer "*compilation*"))
ad-do-it
(when (get-buffer "*compilation-old*")
(switch-to-buffer "*compilation-old*")
(pop-to-buffer buffer))))
答案 1 :(得分:2)
将以下内容放在init文件中会在编译命令终止时将编译缓冲区重命名为*compilation-old*
。
请注意,如果从旧的编译缓冲区运行新的编译过程,这将不起作用(因为compile
将在这种情况下重用缓冲区而不是创建新的缓冲区)
(defun my-rename-compilation-buffer (buffer message)
;; Don't do anything if we are in a derived mode
(when (with-current-buffer buffer (eq major-mode 'compilation-mode))
(let* ((old-compilation-buffer-name "*compilation-old*")
(old-compilation-buffer (get-buffer old-compilation-buffer-name)))
;; Kill old compilation buffer if necessary
(when old-compilation-buffer
(kill-buffer old-compilation-buffer))
;; Rename the current compilation buffer
(with-current-buffer buffer
(rename-buffer old-compilation-buffer-name)))))
(add-hook 'compilation-finish-functions 'my-rename-compilation-buffer)
答案 2 :(得分:0)
这有点像Kludge,但试试这个:
在开始新编译之前,将当前编译缓冲区(写入,C-x C-w)保存到文件中。如果新文件的缓冲区失去了“编译模式”设置,只需重新打开编译模式(M-x编译模式)。