emacs - 在 Emacs 中撤消缓冲区搜索

标签 emacs elisp

在当前缓冲区中执行(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/

相关文章:

regex - 如何让 emacs 正则表达式识别带行号和不带行号的路径

c - 使用emacs获取函数原型(prototype)

emacs - 没有 INITVALUE 的 defvar

elisp - 为 emacs 模式添加动态扩展的单词

emacs - 如何在 emacs 中撤消 call-last-kbd-macro

emacs - 如何使用自动完成功能完成 yasnippets

emacs - 复制和粘贴一行的有效方法

emacs - 如何在emacs中以基本模式加载文件

vim - 我想改变文本在任何文本编辑器中的内部表示方式

emacs - 如何在 dired 模式下获取文件夹路径?