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?

dalanicolai
  • 6,108
  • 7
  • 23
alper
  • 1,238
  • 11
  • 30
  • 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 '22 at 10:55
  • @CSM I was using following solution https://emacs.stackexchange.com/questions/65050/how-to-automatically-accept-please-answer-y-or-n-process-latex-for-document/65076#65076 in `after-save-hook`. I like to see changes right away on the pdf – alper Nov 11 '22 at 11:31

1 Answers1

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.

dalanicolai
  • 6,108
  • 7
  • 23