Emacs: Auto Save
Real Auto Save File
put this in emacs init.
(defun xah-save-all-unsaved () "Save all unsaved files. no ask. Version 2019-11-05" (interactive) (save-some-buffers t )) ;; when switching out of emacs, all unsaved files will be saved (add-hook 'focus-out-hook 'xah-save-all-unsaved)
disable emacs's “#auto-save#” backup
;; stop creating those #auto-save# files (setq auto-save-default nil)
auto-save-mode, however, it's not what you think.
auto-save-mode periodically saves a copy of your file with the name
When you save the file, those #files# are deleted automatically.
In case of crash or electricity outage, when you open a file afterward, emacs will detect those #files# and ask if you want to recover.
But the problem is, even if no crash, in lots of situations (such as sync to server), you'll find those #files# annoying, because they are often symbolic links to non-existent files, and will cause tools like rsync to complain or choke some dir walk scripts.
See also: Emacs: Turn Off Backup
stop emacs from creating .#lock file links
emacs backup is so annoying. even when you have it off (setq auto-save-default nil) , it still creates temp # files. which crashes script that traverse dir.
(setq create-lockfiles nil)
This will completely stop emacs from creating temoporary symbolic link file named “#something”.
(disable lock file may be a problem if you have situations where a file is being edited by different people or instances of emacs.)
2018-10-12 thanks to Dale Hagglund [ https://twitter.com/DaleHagglund/status/1050786629844004865 accessed: 2018-10-12] for create-lockfiles
alternative solution and problem
You can set emacs to auto save files directly, instead of creating those #filename#.
Put the following in your emacs init:
(setq auto-save-default t) (setq auto-save-visited-file-name t)
However, this does not work well. Emacs still generates those #files#, this time, named like this:
.#xxtemp.201601134145.44920.el -> email@example.com:1452244010
If you have scripts going thru your machine, you get this error:
error: cannot open /home/john/web/.#vocabulary.html No such file or directory
(info "(elisp) Auto-Saving")
There are probably ways to fix this, with hooks or timer, but i haven't looked into.
thanks to xfq [https://github.com/xfq/] and finalpatch [http://www.weibo.com/u/1885517634]
thanks to http://irreal.org/blog/?p=4867, Anna Pawlicka (@AnnaPawlicka)
- Emacs init file
- What's Major Mode
- What's Minor Mode
- M-x customize
- Organize Init File
- Byte Compile Elisp
- What's Hook
- Avoid Lambda in Hook
- Environment Variables in Emacs
- Check OS, Version, Host Name
- Check Defined/Loaded
- Define Keys
- Set Mouse Buttons
- Tabs, Space, Indentation Setup
- auto bracket pair
- Copy/Cut Line If No Selection
- Isearch space for - _
- Ido Completion
- Icomplete Completion
- Move Cursor by camelCase
- Stop Cursor Going into Minibuffer Prompt
- Sync Clipboard with Linux X11
- Default Major Mode
- Auto Backup Off
- Auto Save
- Restore Opened Files
- Save Cursor Position
- Dired Customization
- Open Recently Opened
- Open Last Closed File
- Show Line Numbers
- Show Cursor Position
- Visual Line Mode, Wrap Lines
- High Light Current Line
- Make Whitespaces Visible
- Set Default Window Size
- Font Setup
- Line Spacing
- Set Color Theme
- Highlight Paren
- Show lambda as λ
- Color CSS Hex Code