tutorial on temporary files and backup files for Emacs

Source: Internet
Author: User
Tags save file


Instead of editing the file itself, Macs copies the contents of the edited file to a temporary buffer in emacs (buffer), and when we edit it, we only make changes to the contents of the buffer. To make it easier to respond when needed, Emacs automatically generates additional secondary files, the most common of which are temporary files and backup files.

Temporary files (auto-save file)

The file name of the temporary file for Emacs is surrounded by a "#", which is typically a file that Emacs automatically saves when it is edited in Emacs, and he generates a file in the same directory as #file-name# in the editing file. This file will be deleted by Emacs after we save the file. The purpose of this file is to prevent the loss from exiting unexpectedly when editing.

1. Use [c-x,c-f] in Emacs to open the file you want to edit (Test-file.txt)
2. Edit content in open buffer
3. Emacs automatically detects whether the buffer changes, if the change will automatically Auto-save
4. At this point we can see the temporary file in the same directory as the edited file:
#test-file.txt#
5. Use [C-x,c-s] to save the current buffer
6. Content in current buffer is written to file, #test-file.txt# disappears--automatically deleted by Emacs
If you don't want to generate this temporary file There is also a way to turn off the automatic save feature and add the following line to the. emacs file you started.

Code
1
(setq auto-save-default nil);; The default value is T, to turn off changing the default value directly with nil
Of course, it is generally not recommended to shut down, because after the exception exits, if you want to restore the content of your hard work, it can help, you just open in Emacs you want to restore the file, and then restore it.


1. Open the file you want to recover, such as: Test.txt
2. [M-x]
3. Input: Recover-file carriage return
4. Confirm Recovery
It's still good to use.

Back up file (backup files)

When the backup file is saved for the first time, if the saved file already exists, Emacs automatically renames the currently existing file as the backup file and replaces the original file with the contents of the current buffer in a file with the same name. The backup file uses a "~" as a suffix (for example, file-name~). The approximate process is as follows:


1. Open the file, such as: MitchellChu.txt
2. Edit ... (This involves temporary file problems, ignoring)
3. Issue a Save order within Emacs
4. Emacs first saves the MitchellChu.txt as: mitchellchu.txt~
5. After the save is complete, Emacs writes the contents of the current buffer to MitchellChu.txt
Note: At this point the MitchellChu.txt is no longer the original file, but all the files connected to the original file are now taken over by this new file.
Of course, the above process is customizable, for example, we can ask Emacs to back up files by copying rather than renaming them, and setting a variable in. emacs or Emacs:

;; Adding the following line in the. emacs file indicates the use of Copy mode
(setq backup-by-copying t);; Default is nil, use copy mode after opening

;;;;;;;;;;;;;;;
;; If you're in Emacs,
;; You can change the pattern by setting the value of the variable directly.
;;;;;;;;;;;;;;;

;; [M-x]
;; Set-variable
;; Backup-by-copying
;; T
;; Enter, you can modify the mode
Ditto here, it is recommended not to modify this value, because the way of renaming Mitchell personal feeling is better than copy mode.

The backup file defaults to the first time that Emacs is written, that is, when Emacs is opened and saved for the first time, the edits are saved multiple times and cannot produce multiple backup actions. However, the next time that you reopen Emacs and perform the same action again, Emacs will overwrite the last backup file (if any) on the first save. This may be something you don't want, at which point you can set up a different backup file for each time. The specific operation involves more parameters, this function does not feel much useful, here is not to repeat, if interested, you can see: Version-control.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.