在当前缓冲区中执行(re-search-forward str)
之后,在某些情况下最好有一个简单的方法返回到先前的缓冲区位置。对于缓冲区更改,行为应该类似于 (undo)
。因此,如果我向前搜索两次,首先从位置 A 到 B,然后从 B 到 C,我想按一个键返回一步(从 C 到 B),然后再次按该键将使我处于一个..
最佳答案
如果您在 Lisp 代码中使用 re-search-forward
(您可能应该这样做,如果您确实在使用它,即使它是一个命令),那么做 不 设置标记以便能够返回到起点。
相反,只需将起始位置 ((point)
) 保存为变量 beg
,然后使用 goto-char beg
.
请参阅 (elisp) The Mark
中的这段:
Novice Emacs Lisp programmers often try to use the mark for the
wrong purposes. The mark saves a location for the user's
convenience. An editing command should not alter the mark unless
altering the mark is part of the user-level functionality of the
command. (And, in that case, this effect should be documented.)
To remember a location for internal use in the Lisp program, store
it in a Lisp variable. For example:
(let ((beg (point)))
(forward-line 1)
(delete-region beg (point))).
关于emacs - 在 Emacs 中撤消缓冲区搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20873465/