0

I am new to Auctex and Emacs. Previously I have been using vim-latex in which the key bindings are easy. For example, I was using Ctrl-Space in Vim to to save the tex file, compile the document and view the document and comeback to my tex file again where I left the cursor. Currently the command for Auctex for compiling and previewing is C-c C-a. After entering this command, Emacs asks me to save the file ( I need to enter 'yes'). So this makes a little bit time.

So my question is: How to define Crtrl-Space in Emacs so that it will ease the Auctex to compile,save and view the document?

  • From my perspective it is a bad thing to rebind C-SPC. That key sequence is globally bound to set-mark-command which is needed to select a region with the keyboard. Note, that the C-c C-a key sequence of AucTeX is quite sensefully designed. The prefix C-c starts major-mode related key sequences and C-c C-a is a library binding standing for "all". I would suggest to bind C-c a for your special command since that is one of the key sequences reserved for you as a user. – Tobias Jan 14 '18 at 20:18
2

So, perhaps you have already found the answer, if so I hope that you were planning to give it here and mark it ;). If not: the proces with which I would approach such a task is: find out in which keymap the bindings are which are already close to what you want; in this case: C-c C-a. Simply ask about them with C-h k C-c C-a You'll see it's in LaTeX-mode-map.

So now you can do this:

(define-key LaTeX-mode-map (kbd "C-SPC")
  (lambda ()
    "Save the buffer and run `TeX-command-run-all`."
    (interactive)
    (save-buffer)
    (TeX-command-run-all nil)))

Thanks by the way, I'm an evil user and I hadn't bothered, since the shortcut I had bound as an alternative for C-c C-a was pretty convenient already. However not having to bother with pressing y RET is definitely an improvement! ;)

[edit]

Tobias' comment below, provides the possibility to also save other documents/files that are part of the Tex master file. If that is what you prefer, use the following binding. There save-buffer is replaced by TeX-save-document. With the let-binding of TeX-save-query it saves modified buffers silently if they are part of the master document. If you want to be asked whether these files should be saved or not remove the let-binding of TeX-save-query.

(define-key LaTeX-mode-map (kbd "C-SPC")
  (lambda ()
    "Save the buffer and run `TeX-command-run-all`."
    (interactive)
    (let (TeX-save-query) (TeX-save-document (TeX-master-file)))
    (TeX-command-run-all nil)))
  • (save-buffer) is insufficient. Use (let (TeX-save-query) (TeX-save-document (TeX-master-file))) instead. – Tobias Jan 14 '18 at 13:05
  • That is a nice suggestion, thank you! However for me, it's not the behaviour I want. I don't like the command to silently save other documents I may have standing edits in. Perhaps the OP does however, so this suggestion is definitely valuable. I'll add it as an option to my answer. – bklaase Jan 14 '18 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.