如何重新定位*编译*缓冲区(在 Cc Cx 上)?此文档没有流程

如何重新定位*编译*缓冲区(在 Cc Cx 上)?此文档没有流程

我有一个.tex/.Rnw使用 makefile 编译的文档。在编译过程中,我想使用C-c C-l(对于标准.tex文件)重新定位输出缓冲区,以便我可以跟踪它。但是,这给了我(Emacs 24,Ubuntu 12.10):No process for this document.我猜这是因为不再与 LaTeX 关联(make可以做任何事情)。输出缓冲区称为*compilation*,因此如果可以定义C-c C-l重新定位此输出缓冲区,那就可以解决问题。

答案1

好的,我看了一下TeX-recenter-output-buffer并做了相应的调整(我不是 elisp 程序员,所以...请小心使用)。

;; recenter *compilation* buffer (adjusted from TeX-recenter-output-buffer)
(defun compile-recenter-output-buffer (line)
  "Redisplay *compilation* buffer of compile job output so that most recent
output can be seen. The last line of the buffer is displayed on line LINE
of the window, or at bottom if LINE is nil."
  (interactive "P")
  (let ((buffer (get-buffer "*compilation*"))); adjusted
    (if buffer
    (let ((old-buffer (current-buffer)))
      (pop-to-buffer buffer t t); adjusted
      (bury-buffer buffer)
      (goto-char (point-max))
      (recenter (if line
            (prefix-numeric-value line)
              (/ (window-height) 2)))
      (pop-to-buffer old-buffer nil t)); adjusted
      (message "No *compilation* buffer found."))))

然后我将其绑定到C-c ovia (global-set-key (kbd "C-c o") 'compile-recenter-output-buffer)

答案2

您可以定义该函数的自定义应用程序tex-recenter-output-buffer

(defun recenter-compilation-buffer (linenum)
  (interactive "P")
  (let ((compilation-buffer (get-buffer "*compilation*"))
        (window))
    (if (null compilation-buffer)
       (message "No compilation buffer")
      (setq window (display-buffer compilation-buffer))
      (save-selected-window
         (select-window window)
         (bury-buffer compilation-buffer)
         (goto-char (point-max))
         (recenter (if linenum
                   (prefix-numeric-value linenum)
                (/ (window-height) 2)))))))

然后,将其作为钩子添加到 LaTeX 模式:

(add-hook 'tex-mode-hook
        '(lambda ()
           (local-set-key "\C-c\C-l" 'recenter-compilation-buffer)))

答案3

我假设您正在调用compile而不是使用 AUCTeX。正如您所猜测的那样,这完全绕过了 AUCTeX。使用 AUCTeX 的方法是将以下内容添加到您的.emacs.

(add-to-list 'TeX-command-list
 ("Make"               ;; The command you use to invoke it: C-c C-c Make RET
  "make pdf"           ;; The make command to run
  TeX-run-TeX nil t    ;; TeX-run-TeX tells it to parse error as if from TeX
  :help "Run make to build everything")

这样做还有一个好处,就是允许 AUCTeX 解析错误。如果你的 make 文件发出编译器类型错误,那么你可以更改TeX-run-TeXTeX-run-compile它将在编译模式缓冲区中运行。请参阅文档以了解其他选项。

相关内容