这不是关于如何使用 C-u C 空间的标记环的问题。
我想要的是逐步向后导航位置历史记录。 “步骤”是指任何单个 atomic 游标在缓冲区中移动。例如,光标在行的中间,我发出 3 次 C-f 将其向前移动 3 个字符,然后发出 C-e 跳到行尾。现在我想通过先“撤消”C-e 然后 3 个前 C-f 来返回。所以,我按下某个键,它会将光标带到发出 C-e 的地方,然后返回一个字符,依此类推。这就像在缓冲区中的每个光标移动上推送标记,然后使用 C-u C 空间,但自动且噪音较小。
如何在 Emacs 中实现?
最佳答案
默认情况下,Emacs 不会在任何地方记录这些移动,因此为了执行您想要的操作,您需要记录缓冲区位置。有点像
(defvar my-positions-history nil)
(make-variable-buffer-local 'my-positions-history)
(add-hook 'post-command-hook 'my-record-positions)
(defun my-record-positions ()
(unless (and my-positions-history
(equal (point) (marker-position (car my-positions-history))))
(push (point-marker) my-positions-history)))
请注意,这将创建大量标记,这会显着降低 Emacs 的速度。使用 (point)
而不是 (point-marker)
可以解决这个问题,但是这些位置不会跟踪对缓冲区的修改,因此它们可能不会让您返回如果缓冲区在您执行此 Action 后被修改,则返回您所在的位置。
然后你可以添加这样的命令
(defun my-undo-movement ()
(interactive)
(while (and my-positions-history
(equal (point) (marker-position (car my-positions-history))))
(pop my-positions-history))
(when my-positions-history
(goto-char (pop my-positions-history))))
关于emacs - 在 Emacs 中逐步向后导航位置历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13564506/