Hot answers tagged

56 votes
Accepted

How to view diff when emacs suggests to recover this file?

After running recover-this-file and accepting the autosave version, you'll have a modified buffer containing the autosave contents. At this point you can use M-x diff-buffer-with-file RET to see the ...
user avatar
  • 43.8k
32 votes
Accepted

How to auto-save buffers when Emacs loses focus?

Unfortunately, this exact behavior isn't possible in Emacs <= 24.3, but you can save on window/buffer change using defadvice (as detailed on bbatsov's blog): (defadvice switch-to-buffer (before ...
user avatar
  • 4,968
20 votes
Accepted

How to save a copy of a buffer to a file?

Just select the entire buffer (C-x h) and use write-region.
user avatar
  • 879
16 votes
Accepted

How do I automatically save org-mode buffers?

A quick hack, which I'm not sure will satisfy your use-case would be (add-hook 'org-agenda-mode-hook (lambda () (add-hook 'auto-save-hook 'org-save-all-org-buffers nil t) ...
user avatar
  • 4,440
16 votes
Accepted

Execute external script upon save when in a certain mode?

Here's a simple setup that you can modify that allows you to sync org files to your Raspberry Pi, based on your bash script (untested, of course, because I have neither a Pi nor your script). Modify ...
user avatar
  • 31.1k
14 votes
Accepted

Strip text properties in savehist

Add the following to your init-file: (defun unpropertize-kill-ring () (setq kill-ring (mapcar 'substring-no-properties kill-ring))) (add-hook 'kill-emacs-hook 'unpropertize-kill-ring) How it ...
user avatar
  • 14.2k
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 ...
user avatar
8 votes

Automatically saving the current file after typing a certain number of characters

Emacs has an auto-save feature that can be adapted to suit your needs. You can customize auto-save-interval to determine how many characters: auto-save-interval is a variable defined in `C source ...
user avatar
  • 31.1k
7 votes
Accepted

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

Firstly you need to define what "saved manually" actually means. It could cover multiple commands, to my mind. M-x apropos-command RET save\|write RET probably includes all the typical cases. Once ...
user avatar
  • 43.8k
7 votes

How do I automatically save org-mode buffers?

You can save all org buffers whenever a particular agenda function is called. For instance, to save all org buffers after you quit the agenda: (advice-add 'org-agenda-quit :before 'org-save-all-org-...
user avatar
7 votes

How to save multiple buffers

After making the changes you can save the open buffers using save-some-buffers. This is bound C-x s by default. Here is what the docs say. Save some modified file-visiting buffers. Asks user about ...
user avatar
  • 581
6 votes

Strip text properties in savehist

One simple solution is to use savehist-20.el. It is a version of savehist.el that works with all Emacs versions (20+). It automatically strips history elements of properties, and it does not save ...
user avatar
  • 70.2k
6 votes

How to auto-save buffers when Emacs loses focus?

There is focus-autosave-mode now. It's available via MELPA. Why not give it a chance to do the hacking for you‽
user avatar
  • 4,793
5 votes

Backup saved buffers to Dropbox (or other specific directory)

Emacs has a built-in backup mechanism, which is what makes all the "~" files Emacs likes to leave around anywhere. You can tell Emacs to put all the backup files in a single directory with (setq ...
user avatar
  • 12.2k
5 votes

How to save multiple buffers

M-x ibuffer * u S is quite convenient for this as well, because you can add/remove selected buffers with m or u before saving with S.
user avatar
  • 781
4 votes

How do I automatically save org-mode buffers?

I use the following snippet to automatically save all the agenda mode buffers after a new capture, but you could hook it anywhere you'd like: (defun my/save-all-agenda-buffers () "Function used to ...
user avatar
  • 2,579
4 votes

How to auto-save buffers when Emacs loses focus?

(add-to-list 'focus-out-hook (lambda () (save-some-buffers t nil))) This will save all unsaved buffers visiting file, on emacs 24.4
user avatar
4 votes
Accepted

Save all open files in current folder and subfolders

I just added this feature to helm-make. Give it a go and let me know if it works as you wanted, you just need to set the custom: (setq helm-make-do-save t) Here's the code that does it: (when helm-...
user avatar
  • 13.6k
4 votes
Accepted

Backup saved buffers to Dropbox (or other specific directory)

Here is a very rudimentary example (tested on OSX, and may work on other Unix flavor systems). It is possible to write an entire library surrounding this concept, and this example is certainly not ...
user avatar
  • 17.8k
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"...
user avatar
  • 19.4k
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 ...
user avatar
  • 70.2k
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 ...
user avatar
  • 25.4k
4 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.
user avatar
  • 56
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?” ...
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 '...
user avatar
  • 415
3 votes

Weird Prompt: file has changed since visited or saved. Save anyway? (yes or no)

Even though I don't have the file open anywhere else, and I am sure nothing else has changed the file. You are probably mistaken about that. E.g. if you sometimes create snapshot stashes with Magit ...
user avatar
  • 24.4k
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 ...
user avatar
  • 4,113
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 (...
user avatar
3 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 ...
user avatar
  • 70.2k
3 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 ...
user avatar

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