Emacs的三种行滚动方式

第一种,光标到达屏幕边缘触发滚动。这是Emacs默认的滚动方式。

第二种,光标粘住某一行(stick the text line),直到该行离开屏幕,光标停留在屏幕边缘。

(global-set-key  [(meta down)] (lambda (&optional n) (interactive "p")
                              (scroll-up (or n 1))))

(global-set-key  [(meta up)] (lambda (&optional n) (interactive "p")
                              (scroll-down (or n 1))))

第三种,光标停留在屏幕上的某一行(stick the absolut line),无论怎么滚动,光标都不会移动。

;; scroll functions
(defun hold-line-scroll-up()
  "Scroll the page with the cursor in the same line"
  (interactive)
  ;; move the cursor also
  (let ((tmp (current-column)))
    (scroll-up 1)
    (line-move-to-column tmp)
    (forward-line 1)
    )
  )

(defun hold-line-scroll-down()
  "Scroll the page with the cursor in the same line"
  (interactive)
  ;; move the cursor also
  (let ((tmp (current-column)))
    (scroll-down 1)
    (line-move-to-column tmp)
    (forward-line -1)
    )
  )

(global-set-key (kbd "M-n") 'hold-line-scroll-up)
(global-set-key (kbd "M-p") 'hold-line-scroll-down)

这三种方式,第一种太简单了。第二、三种各有优缺点,所以绑定到不同的按键组合。