如果仅从当前所在位置滚动几行,则可以使用此滚动窗口而不移动点:
(defun scroll-in-place (scroll-up)
"Scroll window up (or down) without moving point (if possible).
SCROLL-Up is non-nil to scroll up one line, nil to scroll down."
(interactive)
(let ((pos (point))
(col (current-column))
(up-or-down (if scroll-up 1 -1)))
(scroll-up up-or-down)
(if (pos-visible-in-window-p pos)
(goto-char pos)
(if (or (eq last-command 'next-line)
(eq last-command 'previous-line))
(move-to-column temporary-goal-column)
(move-to-column col)
(setq temporary-goal-column col))
(setq this-command 'next-line))))
;;;; ------------------------------------------------------------------------
(defun scroll-up-in-place ()
"Scroll window up without moving point (if possible)."
(interactive)
(scroll-in-place t))
;;;; ------------------------------------------------------------------------
(defun scroll-down-in-place ()
"Scroll window up without moving point (if possible)."
(interactive)
(scroll-in-place nil))
(global-set-key (read-kbd-macro "M-<down>") 'scroll-up-in-place)
(global-set-key (read-kbd-macro "M-<up>") 'scroll-down-in-place)
如果我要移至文件的完全不同的部分(或完全移至不同的文件),则有时会使用breadcrumb
很多其他软件包来执行类似的操作。
如果需要在视觉上同时看到两个代码区域,则将框架水平分成两个窗口,然后在完成后丢弃第二个窗口。
不过,大多数情况下,我仅使用两个框架,一个框架是我当前的工作框架,另一个框架是我的参考框架,用于在相同或其他文件之间跳转。