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 differences between the modified buffer and the saved file.
The key I've bound for this actually runs a custom function, in order to produce a unified diff, and ...
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 save-buffer-now activate)
(when (and buffer-file-name (buffer-modified-p)) (save-buffer)))
(defadvice other-window (before other-window-now activate)
A quick hack, which I'm not sure will satisfy your use-case would be
(add-hook 'auto-save-hook 'org-save-all-org-buffers nil t)
As long as the Org agenda buffer is open, all org buffers will be saved periodically (it equivalent to what would happen if s was ...
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 the function with your script name. It uses shell-command-to-string to put the command line output somewhere; you could also just use shell-command if that's ...
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 works
substring-no-properties removes any text properties from a given string. kill-ring is a list of strings; we're using mapcar to apply substring-no-properties ...
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 non-related scenarios documented in the manual)
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 code'.
Its value is 300
Number of input events between auto-saves.
Zero means disable autosaving due to number of characters typed.
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 you know which commands you're interested in, you could simply test the this-command variable in your hook function, to see whether its value is a member of your ...
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 each one.
You can answer `y' to save, `n' not to save, `C-r' to look at the
buffer in question with `view-buffer' before deciding or `d' to
view the ...
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 variables in savehist-additional-variables whose values are propertized strings.
In other words, you can read the file it saves even in an Emacs version (e.g. 20) ...
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-buffers)
Alternatively, you could save all org-buffers after each edit, say after a deadline is added:
(advice-add 'org-deadline :after 'org-save-all-org-...
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 backup-directory-alist (list '("." . "/path/to/backups")))
backup-directory-alist is a list of pairs (PATTERN . PATH) where PATTERN is a regexp matching the file ...
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 save all agenda buffers that are
currently open, based on `org-agenda-files'."
(dolist (buffer (buffer-list t))
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:
(let* ((regex (format "^%s" (regexp-quote default-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 meant to be an all inclusive solution -- it is just an idea put on paper so to speak:
(defvar backup-repo (directory-file-name "/private/tmp")
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")
(diff-no-select buffer-file-name (current-buffer) nil 'noasync)
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 auto-save-mode.
See the Emacs manual (C-h r), node Auto Save and its children, especially node Auto Save Control.
See also the Elisp manual, node Auto-Saving, ...
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 2GB at the cost of performance), and IIRC on Emacs<24 a similar limit applied to 64bit versions of Emacs.
So better ditch Apple's bundled Emacs and install ...
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?” prompt. The call is made from C code, so you can't customize the way it's called, but you can make the function examine the situation more closely and not prompt ...
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.
(defun save-buffer-and-call-interactive-hooks (&optional arg)
(when (called-interactively-p 'all) ;; run ...
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 then that would touch the affected files. Would you have expected that? After all it doesn't seem creating a snapshot should touch files in the working ...
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 from that case, the position of the number in the filename shouldn't matter.
(defun tv/increment-number-in-file-name (name)
Here is a starting point. Modify the date format and other components of the filename to taste.
(defun save-buffer-copy (filename)
(list (let ((fn (concat
(read-file-name "Save buffer to file: "
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 pointing to them.
But my suggestion is to not use *scratch* the way you are using it - maybe not use it at all. Instead, use C-x C-f foo.el or whatever, which ...
This will call the underlying command of C-x C-s. You can also call evil-write if you prefer the :w command behaviour