我想问一下,是否有一种通用的方法可以让Emacs在每次大的移动之前,比如向下滚动,向上滚动一页,跳到一行,跳到新的缓冲区,搜索文本……之前,将当前位置推到标记环上,这样我就可以更容易地跳回历史了?
我当前的解决方案是对一些相关函数执行def-advice操作(如下面的示例代码所示),但它没有涵盖所有情况,并且我不知道还应该执行哪些def-advice操作
请分享你在这个问题上的经验。任何帮助都将不胜感激。
(defun my-set-mark ()
(interactive)
(push-mark (point) t nil))
(defadvice find-file (before set-mark activate) (my-set-mark))
(defadvice goto-char (before set-mark activate) (my-set-mark))
(defadvice goto-line (before set-mark activate) (my-set-mark))
(defadvice isearch-update (before set-mark activate) (my-set-mark))
(defadvice beginning-of-buffer (before set-mark activate) (my-set-mark))
(defadvice end-of-buffer (before set-mark activate) (my-set-mark))发布于 2016-08-26 21:54:27
这是一个老套的解决方案,应该可以工作,但它可能会减慢Emacs的速度。我不确定我会推荐使用它,因为它有点核,但如果你想让这种行为自动进行,你可能需要一个核解决方案。
这是未经测试的,因此可能需要调整。
;; Variable to store the current point
(defvar last-point nil)
(defvar last-buffer nil)
;; What constitutes a "large movement", in characters.
(defvar large-movement 1000)
(defun store-last-point ()
(setq last-point (point))
(setq last-buffer (current-buffer)))
(defun magnitude (number)
;; Couldn't find a built-in magnitude function.
;; If anyone knows one, feel free to edit.
(if (>= number 0)
number
(- 0 number)))
(defun push-mark-if-large-movement ()
;; If point is in the same buffer and has moved
;; significantly, push mark at the original location
(if (and (eq last-buffer (current-buffer))
(> (magnitude (- last-point (point))) large-movement))
(push-mark last-point)))
(add-hook 'pre-command-hook 'store-last-point)
(add-hook 'post-command-hook 'push-mark-if-large-movement)请注意,这将阻止您使用多个大移动来选择较大的文本部分。如果你想解决这个问题,你需要在push-mark-if-large-movement命令中添加一个检查(也就是说,如果标记是活动的,就不要按下标记)。
https://stackoverflow.com/questions/39000917
复制相似问题