默认情况下,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)
可以解决此问题,但这些位置不会跟踪对缓冲区的修改,因此如果在执行此动作后修改了缓冲区,它们可能不会将您带回您所在的位置。
然后你可以添加一个命令,如
(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))))