问题描述
当您输入命令时,Emacs将撤消您最近对缓冲区进行更改的一部分。当您再次输入时,它会撤消另一个工作。
When you enter the command , Emacs undoes some part of your recent changes to a buffer. When you enter again, it undoes another chunk of work.
我已经阅读了,但它的确是如何工作的,这是模糊的。该手册说连续字符插入命令通常被分组在一个单个撤销记录,但它并不解释如何决定构成组的字符插入命令的数量。一个组中的字符数似乎是随机的。
I have read the Emacs manual entry on Undo but it is vague about exactly how it works. The manual says "Consecutive character insertion commands are usually grouped together into a single undo record" but it does not explain how it decides the number of character insertion commands that constitute a group. The number of characters it puts in a group seems random.
任何人都可以解释Emacs用于将字符分组到撤销记录中的算法?
Can anyone explain the algorithm Emacs uses to group characters into undo records?
推荐答案
The logic for setting undo boundaries is mostly in self-insert-command
which is implemented in cmds.c
. You'll have to read the code for the full story, but basically:
- 只要输入字符,就会有一个撤消边界每20个字符你输入。
- 但是,如果你发出一个不同的编辑命令(例如杀死一个字),这将导致立即添加一个撤消边界,重置字符数
- 某些毛茸茸的插入(由
internal_self_insert
确定)会立即添加一个撤消边界,并且字符数复位。阅读代码,看起来好像是:(1)在覆盖模式
中,如果你用一个具有不同宽度的字符,例如在标签上打字(2)如果插入的字符导致缩写被扩展; (3)如果您键入的字符导致auto-fill-mode
插入缩进。 - 此外,任何编辑命令撤销边界可以通过调用
undo-boundary
来请求它是一个好主意。这不会导致字符数被重置。
- As long as you are just typing characters, there's an undo boundary every 20 characters you type.
- But if you issue a different editing command (you kill a word, for example), this causes an undo boundary to be added immediately, resetting the character count.
- Certain "hairy" insertions (as determined by
internal_self_insert
) cause an an undo boundary to be added immediately, and the character count to be reset. Reading the code, it looks as though these are: (1) inoverwrite-mode
, if you overwrote a character with one that has a different width, e.g. typing over a tab; (2) if the character you inserted caused an abbreviation to be expanded; (3) if the character you typed causedauto-fill-mode
to insert indentation. - In addition, any editing command that decides it would be a good idea to have an undo boundary can request it by calling
undo-boundary
. This does not cause the character count to be reset.
这篇关于Emacs如何确定撤消的工作单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!