3

I'm using Emacs and Windows 10 and I am fairly new to both Emacs and elisp (and I am not a programmer).

I'm looking for a way to automatically save a buffer immediately after any modification regardless of how small it is.

One method I found to do this involves using the package "real–auto–save" found in the melpa package library which can save a file up to a second after a modification.

Is there a way to automatically save buffers without the use of extraneous packages?

  • 1
    Are you aware of the standard autosave files? Could these achieve what you need? Do you really need to save to the original file after each keystroke? Or do you really want to minimise the risk of losing any significant change? – mikado Oct 8 '18 at 19:29
  • No I don't know anything about the standard autosave files will look it up. I need autosave after any change to a buffer because it is the first step of a larger setup involving editing tex files with AUCTeX and having instant preview of the pdf output. My grand aim is to do math using my voice which for me requires a 'live preview' of the output of latex source files. To do that requires that I first save the latex source file after a change, then compile the latex file and then auto refresh/revert the buffer with the pdf output. But step one is to autosave the file – esc123 Oct 8 '18 at 20:04
  • I know that there a number of latex preview modes around. I don't have experience of them, but you might find that your problem has already been solved. – mikado Oct 8 '18 at 20:18
  • 1
    Why don't you want to use packages that don't come with Emacs? – zck Oct 8 '18 at 21:21
  • @mikado the only package that looked suitable was "latex preview pane" but this does not support the real-time preview I'm looking for – esc123 Oct 9 '18 at 14:48
1

To automatically save buffer after each modification, add the following elisp snippet to emacs config

(defun savebuf(begin end length)
  (if (and (buffer-file-name) (buffer-modified-p))
       (save-buffer)))
(add-hook 'after-change-functions 'savebuf)

documentation for change hooks: https://www.gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html

example snippets: https://www.emacswiki.org/emacs/ChangeHook

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.