Hot answers tagged

56

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 ...


32

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) (when (...


20

Just select the entire buffer (C-x h) and use write-region.


16

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) (auto-save-mode))) 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 ...


15

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 ...


13

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 ...


13

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)


8

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 Documentation: Number of input events between auto-saves. Zero means disable autosaving due to number of characters typed. ...


7

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 ...


7

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 ...


6

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) ...


6

There is focus-autosave-mode now. It's available via MELPA. Why not give it a chance to do the hacking for you‽


6

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-...


5

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 ...


5

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.


4

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'." (interactive) (save-current-buffer (dolist (buffer (buffer-list t)) ...


4

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


4

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-make-do-save (let* ((regex (format "^%s" (regexp-quote default-directory))) (buffers (cl-remove-if-not (lambda (b) (...


4

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") "NOTE: `directory-...


4

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") (when buffer-file-name (diff-no-select buffer-file-name (current-buffer) nil 'noasync) (with-current-buffer "*Diff*" (and (search-forward-...


4

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, ...


4

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 ...


4

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.


3

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 ...


3

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 'hook) (defun save-buffer-and-call-interactive-hooks (&optional arg) (interactive "p") (save-buffer arg) (when (called-interactively-p 'all) ;; run ...


3

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 ...


3

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) (with-temp-buffer (insert name) ...


3

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 (buffer-name) "_" (format-time-string "%Ft%T") ".repl"))) (read-file-name "Save buffer to file: " ...


3

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 ...


3

(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 prefer the :w command behaviour


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