Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
13 votes

How do I automatically save org-mode buffers?

I see many answers that are more complicated, this worked for me: `(add-hook 'auto-save-hook 'org-save-all-org-buffers)` Auto Save defaults to running after 30 seconds of inactivity (and in other ...
Karim Nassar's user avatar
5 votes
Accepted

What are the '.#' links for?

Symbolic links of the form “.#*” are not auto-save files, their purpose is to prevent the simultaneous editing of the same file. See Interlocking and File Locks in the Emacs Manual.
dliotev's user avatar
  • 66
4 votes
Accepted

Saving file everytime leaving insert mode in evil-mode

(add-hook 'evil-insert-state-exit-hook (lambda () (call-interactively #'save-buffer))) This will call the underlying command of C-x C-s. You can also call evil-write if you ...
Felipe Lema's user avatar
4 votes
Accepted

Make Emacs diff files before asking to save

I've used a function like this for something similar: (defun current-buffer-matches-file-p () "Return t if the current buffer is identical to its associated file." (autoload 'diff-no-select "diff"...
glucas's user avatar
  • 20.6k
4 votes
Accepted

How can I get Emacs to save the changes automatically each X seconds?

You probably do not want it to save every N sec but to do that only after Emacs has been idle for N sec. To do that, customize user option auto-save-timeout to the number of seconds, and turn on ...
Drew's user avatar
  • 77.8k
4 votes
Accepted

Saving very big files

Emacs-22.1 was released on June 2 2007, so it qualifies as ancient. AFAIK the usual 32bit build of Emacs is currently limited to 512MB buffers (tho there's a compilation option to push this limit to ...
Stefan's user avatar
  • 26.5k
3 votes
Accepted

Save REPL buffer as file?

Here is a starting point. Modify the date format and other components of the filename to taste. (defun save-buffer-copy (filename) (interactive (list (let ((fn (concat (...
Harald Hanche-Olsen's user avatar
3 votes

Increment file name and create a new version of the file

The following elisp code should define a function write-file-increment doing what you want, except for the "preserving length" part. If the file name does not contain a number, it adds "-1". Apart ...
T. Verron's user avatar
  • 4,293
3 votes
Accepted

How to increase a magic number in a file buffer on each save

C-h f time-stamp: time-stamp is an autoloaded interactive compiled Lisp function in `time-stamp.el'. (time-stamp) Probably introduced at or before Emacs version 19.31. Update the time stamp ...
rpluim's user avatar
  • 5,315
3 votes
Accepted

Resolving the conflict when the file on disk has been changed

As you're familiar with ediff you can also: M-x ediff-current-file Start ediff between current buffer and its file on disk. This command can be used instead of `revert-buffer'. If there is ...
phils's user avatar
  • 51.5k
3 votes

Fix 'changed on disk'/'Reread from disk' when file has not changed

When Emacs detects that a file has changed , it calls ask-user-about-supersession-threat. The default implementation of this function shows the “FILENAME changed on disk; \ really edit the buffer?” ...
Gilles 'SO- stop being evil''s user avatar
3 votes

How to run an `after-save-hook` only when the buffer has been saved manually

Here's an alternative solution: (defcustom after-save-interactively-hook nil "Normal hook that is run after a buffer is saved interactively to its file. See `run-hooks'." :group 'files :type '...
Nordlöw's user avatar
  • 507
3 votes
Accepted

How do I save raw bytes into a file?

At a minimum, if by default your buffers are multibyte, you will need to toggle this specific buffer to unibyte; you also need to set the file coding system of the buffer to raw-text: (with-temp-...
NickD's user avatar
  • 30.4k
2 votes

Automatically show diff before saving file

What about something like this? #+BEGIN_SRC emacs-lisp (defun my-diff () (let ((temp-file (make-temp-file "gpgdiff-")) (contents (buffer-string)) (current-file (buffer-file-name))) (...
John Kitchin's user avatar
  • 11.9k
2 votes
Accepted

Emacs freezes when saving org file in org-mode

Today I did another upgrade of org-mode and now it works. Must have been a local bug. Thanks for your help @choroba
Ajned's user avatar
  • 744
2 votes
Accepted

Ask for saving contents if scratch buffer is modified before exit

persistent-scratch is another package which saves and restores the contents of the *scratch* buffer. The following is a possible setup. (use-package persistent-scratch :ensure t :commands ...
Swarnendu Biswas's user avatar
2 votes

Ask for saving contents if scratch buffer is modified before exit

You could use the (bundled) savehist package to save and restore the scratch contents: (use-package savehist :init (savehist-mode) :config (defun my-savehist-scratch () (with-current-...
unhammer's user avatar
  • 1,159
2 votes

Ask for saving contents if scratch buffer is modified before exit

This is a commonly asked question. It might be a duplicate here (dunno). There are various tweaks or libraries that some users use to provide what you are asking - you will likely get some answers ...
Drew's user avatar
  • 77.8k
2 votes
Accepted

How to auto-format an Elisp file on save?

Since asking this question I've written an auto-formatter that runs on save. Other elisp formatting tools I found caused a *lot* of right-shift and didn't seem well maintained. See: elisp-autofmt. ...
ideasman42's user avatar
  • 8,826
2 votes
Accepted

Syncronize on save

shadowfile.el could help. Note, that it cooperates with Tramp since Emacs 26.2 only.
Michael Albinus's user avatar
2 votes

How to increase a magic number in a file buffer on each save

Easily done via a file-local variable save-count. The only drawback is that you cannot define the format of the magick number freely but you are bound to the format of file-local variables. (defvar ...
Tobias's user avatar
  • 33.2k
2 votes

"Auto-Confirmation: Automatically Saying Yes" but how?

Try customizing (or binding) compilation-ask-about-save to nil. C-h v tells you: compilation-ask-about-save is a variable defined in compile.el. Its value is t Documentation: Non-nil means M-x ...
Drew's user avatar
  • 77.8k
1 vote

How can I save files in Emacs on OSX and preserve the file creation date?

Found the solution here. You need (setq backup-by-copying t) in your emacs configuration file. This only applies to OSX and Windows.
James Gatz's user avatar
1 vote

why is save-buffer asking for a chmod?

Do the following: M-: (setq debug-on-quit t) RET reproduce the problem when asked whether to perform the chmod, hit C-g hopefully this will give you a backtrace showing which code is doing that. If ...
Stefan's user avatar
  • 26.5k
1 vote

Automatically save moved file to new location

This doesn't answer the question as posed, but one option that you have for moving a file that is being visited by a buffer is to use dired. Files that are being visited by a buffer automatically ...
nispio's user avatar
  • 8,235
1 vote
Accepted

Delete auto-save file when killing Emacs without saving buffer

I think the problem is that save-buffers-kill-emacs asks that yes-or-no question. When you're asked that you must either answer yes or no or use C-g to quit (in this case, quit exiting). You could ...
Drew's user avatar
  • 77.8k
1 vote

Rewriting all file when save some changes

You say "linux line separator" (by which I assume you mean it uses Unix-style LF line separators) yet your snapshot shows (DOS) in the modeline, hence CRLF line separators. My crystal ball tells me ...
Stefan's user avatar
  • 26.5k
1 vote

How to avoid accidentally writing temporary source-block-edit-buffers to file

There is already a built-in default keyboard shortcut to save edits (made in the editing buffer) to the parent buffer; i.e., C-x C-s -- which calls org-edit-src-save. There are many ways to handle ...
lawlist's user avatar
  • 19.2k
1 vote
Accepted

Tramp: Cannot Save File

I've been testing other versions of Emacs for Mac, and it seems this error was somehow caused by the Emacs version I was using. I was using these binaries. I tested other Emacs versions: Aquamacs, ...
Guilherme Salomé's user avatar
1 vote

Tramp: Cannot Save File

Emacs saves files by creating a new file with a temporary name, deleting the old file, and then renaming the new file to the correct name. This is less error-prone; you won't end up with content from ...
db48x's user avatar
  • 18.2k

Only top scored, non community-wiki answers of a minimum length are eligible