Latex、Emacs:错误时自动打开 *TeX Help* 缓冲区并在纠正错误后关闭它? [英] Latex, Emacs: automatically open *TeX Help* buffer on error and close it after correction of the error?

查看:15
本文介绍了Latex、Emacs:错误时自动打开 *TeX Help* 缓冲区并在纠正错误后关闭它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了由 Ivan Andrus 在 Emacs latexmk 函数将我抛入空缓冲区 以便在编译过程中出现错误时自动打开 *TeX Help* 缓冲区 (Cc抄送).更正错误并再次编译后,*TeX Help* 缓冲区保持打开状态(尽管错误已更正).有什么方法可以调整函数(不幸的是,我没有 elisp 编程经验),以便在错误解决时关闭 *TeX Help* 缓冲区,如果错误未解决则更新(并且仍然打开)?这将节省大量的输入,如 C-c ' 显示 *TeX Help* 缓冲区和 C-x 1 再次隐藏它.

I use the function TeX-parse-error defined by Ivan Andrus at the bottom of Emacs latexmk function throws me into an empty buffer in order to automatically open the *TeX Help* buffer when there was an error during the compilation (C-c C-c). After correcting an error and compiling again, the *TeX Help* buffer remains open (although the error has been corrected). Is there any way to adjust the function (unfortunately, I'm not experienced in elisp programming) so that the *TeX Help* buffer is closed if the error was resolved and updated (and still open) if the error wasn't resolved? That would save a lot of typing like C-c ' to show the *TeX Help* buffer and C-x 1 to hide it again.

推荐答案

首先,我们定义一个函数,它会找到 *TeX Help* 缓冲区,如果存在,则关闭其窗口,然后杀死缓冲区:

First, let's define a function that finds the *TeX Help* buffer, if it exists, closes its window, and then kills the buffer:

(defun demolish-tex-help ()
  (interactive)
  (if (get-buffer "*TeX Help*") ;; Tests if the buffer exists
      (progn ;; Do the following commands in sequence
        (if (get-buffer-window (get-buffer "*TeX Help*")) ;; Tests if the window exists
            (delete-window (get-buffer-window (get-buffer "*TeX Help*")))
          ) ;; That should close the window
        (kill-buffer "*TeX Help*") ;; This should kill the buffer
        )
    )
  )

现在,您必须在调用用于编译的任何函数时调用它.以其他页面的示例为例,您可以将 Ivan Andrus 的函数修改为:

Now, you have to call this when you call whatever function it is that you use to compile. Taking the example from that other page, you can modify Ivan Andrus's function to be:

(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk"
                 (TeX-command-expand "latexmk %t" 'TeX-master-file)
                 master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
       (demolish-tex-help)
       (minibuffer-message "latexmk done")))))

(add-hook 'LaTeX-mode-hook
          (lambda () (local-set-key (kbd "C-0") #'run-latexmk)))

(注意:这实际上对我不起作用,因为我的 latexmk 搞砸了,所以我还没有成功测试它.但如果 Ivan 的版本对你有用,那么这也应该.)

(Note: This doesn't actually work for me, because my latexmk is screwed up, so I haven't successfully tested it. But if Ivan's version worked for you, then this should too.)

所以现在,任何时候你用这个函数调用 latexmk(例如,通过点击 C-0),一旦编译完成,它就会检查错误.如果有错误,它会自动打开帮助窗口并获取第一个错误.如果没有,它检查帮助缓冲区是否打开;如果是,则关闭该窗口并终止缓冲区.

So now, any time you call latexmk with this function (by hitting C-0, for example), once the compilation is done, it checks for errors. If there were errors, it automatically opens the Help window and gets the first error. If there were none, it checks to see if the Help buffer is open; if so, it closes that window and kills the buffer.

这篇关于Latex、Emacs:错误时自动打开 *TeX Help* 缓冲区并在纠正错误后关闭它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆