How to setup emacs so that I can browse through previous-compilation errors during new compilation?
如何设置emacs,以便在新的编译期间浏览以前的编译错误?
Two things don't work for me:
有两件事对我不起作用:
-
M-g M-g (next-error) function is not working when second compilation is in-progress.
当正在进行第二次编译时,M-g M-g(下一个错误)函数不能工作。
-
I have my emacs split into 5 uneven windows (split-windows-horizontally), the compilation "window" is double the size (dbl monitor setup). When I launch compilation it always appeared in the last double compilation window. Now it opens a new window for itself.
我将emacs分为5个不均匀的窗口(分割窗口-水平窗口),编译“窗口”是大小的两倍(dbl监视器设置)。当我启动编译时,它总是出现在最后的双编译窗口中。现在它为自己打开了一个新窗口。
3 个解决方案
#1
3
Here is a solution which seems to fulfill all your requirements:
这里有一个解决方案似乎可以满足你所有的要求:
- the
*compilation-old*
buffer always stays in the same window - *编译旧*缓冲区始终保持在同一个窗口中
-
next-error
does not break - next-error不会破坏
- all successive compilation outputs are appended at the end of
*compilation-old*
when the compilation process terminates - 所有后续的编译输出都将在编译过程终止时的*编译旧*末尾附加
(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))))
#2
2
Putting the following in your init file will rename the compilation buffer to *compilation-old*
when the compile command terminates.
将以下内容放入init文件将在编译命令终止时将编译缓冲区重命名为* compile -old*。
Please note that this will not work if you run the new compilation process from the old compilation buffer (since compile
will in this case reuse the buffer instead of creating a new one)
请注意,如果从旧的编译缓冲区运行新的编译过程,这将不起作用(因为在本例中,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)
#3
0
It's a bit of a Kludge, but try this:
这有点复杂,但试试这个:
Before starting the new compilation, save (write, C-x C-w) the current compilation buffer to a file. If the buffer for the new file looses it "compilation-mode" setting, simply turn compilation-mode back on (M-x compilation-mode).
在开始新的编译之前,将当前的编译缓冲区保存(写,C-x C-w)到一个文件中。如果新文件的缓冲区打开了“编译模式”设置,只需将编译模式重新打开(M-x编译模式)。
#1
3
Here is a solution which seems to fulfill all your requirements:
这里有一个解决方案似乎可以满足你所有的要求:
- the
*compilation-old*
buffer always stays in the same window - *编译旧*缓冲区始终保持在同一个窗口中
-
next-error
does not break - next-error不会破坏
- all successive compilation outputs are appended at the end of
*compilation-old*
when the compilation process terminates - 所有后续的编译输出都将在编译过程终止时的*编译旧*末尾附加
(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))))
#2
2
Putting the following in your init file will rename the compilation buffer to *compilation-old*
when the compile command terminates.
将以下内容放入init文件将在编译命令终止时将编译缓冲区重命名为* compile -old*。
Please note that this will not work if you run the new compilation process from the old compilation buffer (since compile
will in this case reuse the buffer instead of creating a new one)
请注意,如果从旧的编译缓冲区运行新的编译过程,这将不起作用(因为在本例中,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)
#3
0
It's a bit of a Kludge, but try this:
这有点复杂,但试试这个:
Before starting the new compilation, save (write, C-x C-w) the current compilation buffer to a file. If the buffer for the new file looses it "compilation-mode" setting, simply turn compilation-mode back on (M-x compilation-mode).
在开始新的编译之前,将当前的编译缓冲区保存(写,C-x C-w)到一个文件中。如果新文件的缓冲区打开了“编译模式”设置,只需将编译模式重新打开(M-x编译模式)。