8

如何设置 emacs 以便在新编译期间浏览以前的编译错误?

有两件事对我不起作用:

  1. Mg Mg (next-error) 功能在第二次编译正在进行时不起作用。

  2. 我将我的 emacs 分成 5 个不均匀的窗口(split-windows-horizo​​ntally),编译“窗口”的大小是两倍(dbl 监视器设置)。当我启动编译时,它总是出现在最后一个双编译窗口中。现在它为自己打开了一个新窗口。

4

3 回答 3

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))))
于 2012-11-08T08:11:33.320 回答
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)
于 2012-11-19T15:46:48.100 回答
0

这有点像 Kludge,但试试这个:

在开始新的编译之前,将当前编译缓冲区保存(写入,Cx Cw)到一个文件中。如果新文件的缓冲区丢失了“编译模式”设置,只需重新打开编译模式(Mx 编译模式)。

于 2012-11-07T14:38:40.220 回答