1

I am using following full-auto-save () (https://www.emacswiki.org/emacs/AutoSave) to save all buffers on Auto-Save.

(defun full-auto-save ()
  (interactive)
  (save-excursion
    (dolist (buf (buffer-list))
      (set-buffer buf)
      (if (and (buffer-file-name) (buffer-modified-p))
          (basic-save-buffer)))))

(add-hook 'auto-save-hook 'full-auto-save)

I have a ~2000 lines of a tex file, where after each save I run pdflatex to compile my latex file in combination with emac's auto-backup feature. Hence in the backup auto-saving causes pdflatex to run every few second along with writing the large file as backup while I am typing, which leads Emacs to freeze.

Is it possible to prevent auto-save for specific modes disable it for a specific mode, such as LaTeX-mode, but keep it enabled for other modes?

2
  • Is it possible to not automatically run pdflatex when a PDF buffer is is autosaved, but only on a manual save? Possibly by checking that target file for '#' or checking the buffer-modified-p flag (which isn't cleared by autosaves, only manual saves, IIRC)
    – CSM
    Nov 11, 2022 at 10:55
  • @CSM I was using following solution emacs.stackexchange.com/questions/65050/… in after-save-hook. I like to see changes right away on the pdf
    – alper
    Nov 11, 2022 at 11:31

1 Answer 1

3

I guess, after the set-buffer, just add the condition using unless to only save a buffer 'when not' the major`mode is a member of the list of modes that you would like to exclude, as follows:

(defun full-auto-save ()
  (interactive)
  (save-excursion
    (dolist (buf (buffer-list))
      (set-buffer buf)
      (unless (memq major-mode '(latex-mode))
        (if (and (buffer-file-name) (buffer-modified-p))
            (basic-save-buffer))))))

This code excludes for LaTeX-mode, but you can add other modes to that list.

7
  • If I want to apply this multiple major modes , can I add their names into major-mode '(LaTeX-mode)?
    – alper
    Nov 11, 2022 at 8:57
  • Exactly! (see the last line of the answer) Nov 11, 2022 at 8:58
  • Thanks, seperated by just space right like (memq major-mode '(LaTeX-mode git-commit-mode)?
    – alper
    Nov 11, 2022 at 9:07
  • Yes (this is some text required to fill up this comment) Nov 11, 2022 at 9:09
  • 1
    Its latex-mode ; using latex-mode instead of LaTeX-mode solved it
    – alper
    Nov 11, 2022 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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