【问题标题】:Browsing through previous-compilation errors during a new compilation?在新编译期间浏览以前的编译错误?
【发布时间】:2012-11-07 13:09:04
【问题描述】:

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

有两件事不适合我:

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

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

【问题讨论】:

  • 考虑到它是可编程的,答案是肯定的。
  • 能否请您准确解释当前答案缺少哪些细节?
  • @Francesco - 忘记添加解释什么不起作用 - 在 cmets 中添加到您的答案中。

标签: c++ emacs ide compilation


【解决方案1】:

这是一个似乎可以满足您所有要求的解决方案:

  • *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))))

【讨论】:

  • 2 件事对我不起作用: 1. 当第二次编译正在进行时,M-g M-g (nex-error) 功能不起作用。 2. 我将我的 emacs 分成 5 个不均匀的窗口(split-windows-horizo​​ntally),编译“窗口”的大小是原来的两倍(dbl moniotr 设置)。当我启动编译时,它总是出现在最后一个双编译窗口中。现在它会为自己打开新窗口。
  • 至于问题1,你有没有尝试过next-error按照其内联帮助中描述的方式使用?首先在要用作源的编译缓冲区中运行next-error(在您的情况下为*compilation-old*),然后next-error 的所有连续调用都将使用此缓冲区。
  • 对于问题2,我不明白你想在双倍大小的窗口中看到哪个缓冲区;旧的还是正在运行的?
  • 1.即使我第一次在旧编译中运行 next-error 仍然存在。 (你能在你的机器上测试它吗?makefile with sleep inside +损坏的文件编译就足够了)
  • 从 2 开始。我希望在新编译完成时看到旧编译。我想看新的(可能命名为旧编译)。
【解决方案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)

【讨论】:

  • 还是同样的问题: 1. (next-error) 只在新窗口中使用编译错误。即使我从第二个旧编译缓冲区执行(下一个错误)。
【解决方案3】:

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

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

【讨论】:

  • 这听起来是一种合理的方法。但我不能手动完成。此外,当新编译完成时,我希望它覆盖旧的错误列表。也许我们可以修改编译命令以编译到一些临时缓冲区并在完成后将其移动到*编译*?
猜你喜欢
  • 1970-01-01
  • 2013-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
  • 2021-08-16
  • 1970-01-01
  • 2015-01-21
相关资源
最近更新 更多