emacslatexelispauctex

Emacs/AUCTeX prefix arguments


In LaTeX mode C-c C-c is bound to:

(TeX-command-master &optional OVERRIDE-CONFIRM)

Normally this interactive function runs a command, perhaps a LaTeX compilation, asking for confirmation.

In tex-buf.el it reads:

If a prefix argument OVERRIDE-CONFIRM is given, confirmation will depend on it being positive instead of the entry in `TeX-command-list'.

This is a bit cryptic for me and reading C-h v TeX-command-list didn't help.

How can I pass the prefix argument to "TeX-command-master" so that I avoid all the confirmation requests?


Solution

  • Build & view

    Again, this solution, instead of modifying the behaviour of the TeX-command-master, rewrites it. The rewritten version of the command, named build-view, follows a rather straightforward logic.

    1. If the LaTeX file buffer is not-modified, it runs the default viewer;
    2. If the buffer is dirty, it runs the default LaTeX compiler and, after the build, opens the output in the default viewer.

    Here's the code:

    (defun build-view ()
      (interactive)
      (if (buffer-modified-p)
          (progn  
        (let ((TeX-save-query nil)) 
        (TeX-save-document (TeX-master-file)))
        (setq build-proc (TeX-command "LaTeX" 'TeX-master-file -1))
        (set-process-sentinel  build-proc  'build-sentinel))
        (TeX-view)))
    
    (defun build-sentinel (process event)    
      (if (string= event "finished\n") 
          (TeX-view)
        (message "Errors! Check with C-`")))
    

    You can now type M-x build-view and start the told build-view process or associate it with a new keybinding such as “F2”:

    (add-hook 'LaTeX-mode-hook '(lambda () (local-set-key (kbd "<f2>") 'build-view)))
    

    Note: As suggested by Tyler, TeX-save-query variable is changed locally, therefore the old C-c C-c/ TeX-command-master is unaffected and will keep asking confirmations.

    Do edit this code to make it better or easier to read!