sams emacs 24 hour 读书笔记3

本文介绍了Emacs编辑器中的错误恢复机制,包括撤销命令的使用及特点;详细讲解了两种备份模式:单一备份和编号备份,以及如何配置备份设置;还介绍了如何从崩溃中恢复未保存的工作,包括自动保存文件的恢复方法。

Hour 5: Recovering from Errors

"Undo commands of Emacs are commands that later can be undone themselves."

一个undo的例子

插入1,2,3,4,每行一个

undo两次


插入5


然后undo一次,你会看到5被撤销掉了,当你插入5时,undo序列被打断,继续undo会添加3,4


自动备份

关于备份:备份只会发生在eamcs打开文件时的第一次保存

There are two different ways Emacs can do these backups:

  • Single backup--In this mode only one backup is kept of the file. When you edit the file for the second time in Emacs, the first backup is overwritten. The filename used for the backup is the original filename with a tilde (~) appended to the end of the file. (This is the default.)
  • Numbered backup--In this mode, each new backup is numbered consecutively; thus, you might have several backups of the same file. The filename used for the backups is the original with .~42~ appended (for the 42nd backup of the file).
If you would like Emacs to do a single backup (and it doesn't already), you must insert the following lines into your .emacs file:

 (setq make-backup-files t) 
(setq version-control 'never) 
Finally, if you want Emacs to make numbered backups, you must insert the following lines into your .emacs file:

(setq make-backup-files t) 
(setq version-control t) 

Configuring Numbered Backups

为了避免磁盘空间充斥着备份文件,emacs提供了两个变量用于配置

kept-old-versions 缺省值为2    Emacs在创建一个新的编号备份时将为文件保留的最老版本的个数

kept-new-versions 缺省值为2        Emacs在创建一个新的编号备份时将为文件保留的最新版本的个数

示例配置:

(setq kept-old-versions 1) 
(setq kept-new-versions 5) 

Keeping All the Backup Files in One Directory

从sams的cd里把backup-dir拷出来,在.emacs里加入

(require 'backup-dir) 
(setq bkup-backup-directory-info 
      '((t "/home/blackie/.backups" ok-create full-path))) 

Recovering from a Crash

前面讲的内容无法帮助从灾难中获取既上次保存之后的内容
I strongly suggest that you save your files often, which would make the amount of data lost in this case smaller. But fortunately Emacs helps you here too. Emacs saves your files once in a while: normally, every 300 keystrokes or when you have been inactive for 30 seconds
自动保存的文件会以#filename#命名

Recovering an Autosave File

使用M-x 然后键入recover-file

然后写名字,并回车

并不需要写#


写yes即可

Recovering Sessions

如果在事故前编辑了许多文件,这就需要用recover-session来帮助整个的恢复工作了,能够减轻负担

Press M-x and type recover-session. Emacs now shows you a list of all the session files, sorted by date


In this buffer, you can press Enter on top of a session to see which files it contains


To get back to the session buffer, simply kill the buffer with the information about the session. You do this by pressing C-x k (kill-buffer) and pressing the Enter key.



yes即可

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值