Re: [emcs] Emacs 平順捲動

看板Editor (編輯器(vim/emacs))作者 (abyss)時間8年前 (2016/04/05 11:07), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
這邊提供兩種方法: 第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改成向下平順捲動的話應該要怎麼設定呢? : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.227.179.229 ※ 文章網址: https://www.ptt.cc/bbs/Editor/M.1459825651.A.F8C.html
文章代碼(AID): #1N0olp-C (Editor)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
文章代碼(AID): #1N0olp-C (Editor)