Re: [emcs] Emacs 平顺卷动

楼主: luminary (abyss)   2016-04-05 11:07:29
这边提供两种方法:
第1种是换页时卷动数行,并且在其间穿插些许的延迟。
这样看起来就有平滑卷动的效果。
(defun smooth-scroll (increment)
(scroll-up increment) (sit-for 0.05)
(scroll-up increment) (sit-for 0.02)
(scroll-up increment) (sit-for 0.02)
(scroll-up increment) (sit-for 0.05)
(scroll-up increment) (sit-for 0.06)
(scroll-up increment))
(global-set-key [(mouse-5)] '(lambda () (interactive) (smooth-scroll 1)))
(global-set-key [(mouse-4)] '(lambda () (interactive) (smooth-scroll -1)))
(define-key evil-normal-state-map (kbd "C-f") '(lambda () (interactive) (smooth-scroll 1)))
(define-key evil-normal-state-map (kbd "C-b") '(lambda () (interactive) (smooth-scroll -1)))
第2种是一次卷动 1/n 行。
(defun DE-visual-scroll-up (&optional arg)
(interactive)
(if (pos-visible-in-window-p (point-max))
(message "End of buffer")
(unless arg
(setq arg 1))
(let ((cur (point))
pos visible)
(setq pos
(save-excursion
(while (and (search-forward "\n" nil t)
(= (length (pos-visible-in-window-p
(point) nil t)) 2)))
(1- (point))))
(setq visible
(pos-visible-in-window-p pos nil t))
;; if point is fully visible, we can go there
(when (and (= (length visible) 2)
(not (= pos cur)))
(goto-char pos))
;; if point is partly visible, we only go there if we absolutely
;; have to (point is already at the top)
(when (and (= pos cur)
(null (pos-visible-in-window-p (1- (point)))))
(forward-line 1))
(set-window-vscroll nil (+ (window-vscroll) arg)))))
(defun DE-visual-scroll-down (&optional arg)
(interactive)
(if (pos-visible-in-window-p (point-min))
(message "Beginning of buffer")
(unless arg
(setq arg 1))
(let ((cur (point))
pos visible)
(setq pos
(save-excursion
(while (and (search-backward "\n" nil t)
(= (length (pos-visible-in-window-p (point) nil t)) 2)))
(+ 1 (point))))
(setq visible
(pos-visible-in-window-p pos nil t))
(when (and (= (length visible) 2)
(not (= pos cur)))
(goto-char pos))
(when (and (= pos cur)
(null (pos-visible-in-window-p
(save-excursion (forward-line 1) (point)))))
(goto-char (1- (point))))
(when (zerop (window-vscroll))
(message "vscroll is 0. Reverting to scroll-down.")
(scroll-down arg))
(set-window-vscroll nil (- (window-vscroll) arg)))))
(global-set-key (kbd "C-f") '(lambda () (interactive) (DE-visual-scroll-up 0.3)))
(global-set-key (kbd "C-b") '(lambda () (interactive) (DE-visual-scroll-down 0.3)))
不过这种方法对电脑速度的要求比较高。
当然了,如果想要用第2种方法可是卷快一点的话,
可以调高键盘触发速率,
或者把两种方法结合起来用。
※ 引述《yea107 (ㄚ隆)》之铭言:
: 我目前是在mac上用spacemacs,
: 搭配GUI的状况下,用触控板可以像sublime一样平顺卷动
: (虽然还是没有sublime顺@@...)
: 不过用按键例如说C-f就会直接跳下一页
: 我想要把C-f改成向下平顺卷动的话应该要怎么设定呢?
: 谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com