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
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
)
)
)
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)))
(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.)
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.