[Tex/LaTex] Compile with emacs and update the view in docview

auctexemacsviewers

I'm using Emacs with AUCTeX under Ubuntu 14.04. My frame is splitted into two windows like this:

 ------------------------------
|                |             |
|                |             |
|       1        |       2     |
|                |             |
|                |             |
 ------------------------------

Currently, C-c C-c only compiles the TeX file which is in window 1 and display errors (if any) in window 2.

I would like this command to automatically load the compiled pdf in window 2 if there isn't any error with the "docview".

By the way, I currently have to press "Enter" after invoking C-c C-c (in order to validate the fact I want to use my default compiler), is it possible to remove this validation part ?

I know I should modify my .emacs file, but I'm very uncomfortable with these configuration files…

Best Answer

For your first question (it's a pity you didn't split the two!), I'd suggest advising the TeX-command-sentinel function. (I don't have enough time to investigate this now; the part where you want the log buffer to show the pdf after successful compilation might be a bit tricky, but definitely doable. The problem might be that window configurations in stock Emacs are rather volatile. There are some Emacs packages addressing that problem, but I don't know any of them. If anyone can solve this problem, feel free to edit this answer!)

For your second question (and you should really split them!), try e.g. this:

(define-key TeX-mode-map (kbd "C-c C-z")
  (lambda ()
    (interactive)
    (TeX-command TeX-command-default 'TeX-master-file)))

This might not be the most robust code ever (for instance, it can't compile the region), but it binds the (normally unused in AUCTeX) C-c C-z key sequence to running the default TeX command on current buffer's master file.

Surprisingly, calling the thing that C-c C-c would suggest is tricky: the command responsible for that is TeX-command-query, and it contains both the logic responsible for choosing the command to run and the interactive query. Very bad practice. One could either (a) copy-paste the first part of this function and change the last part or (b) advise this function so that the meaning of completing-read is temporarily changed (even worse practice!). (In fact, it would be best to file a feature request to AUCTeX developers to split this function in two! Speaking of splitting, this site works best if there's only one question per question.)

BTW, please don't use the .emacs file; it's better to use ~/.emacs.d/init.el.

BTW², did I mention that it would be best to split your two questions into two entries on this site?