From: Po Lu Date: Sat, 27 Nov 2021 05:02:10 +0000 (+0800) Subject: Make `pixel-scroll-precision-scroll-up' use existing logic X-Git-Tag: emacs-29.0.90~3649^2~29 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d329014574575b3f98ac68e22bdcb1ab4ddd5419;p=emacs.git Make `pixel-scroll-precision-scroll-up' use existing logic * lisp/pixel-scroll.el (pixel-point-at-unseen-line): Rewrite to use `pixel-point-and-height-at-unseen-line'. (pixel-point-and-height-at-unseen-line): New function. (pixel-scroll-precision-scroll-up): Use existing logic to determine unseen line position. --- diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el index f6d1d0ff8ca..131519a2585 100644 --- a/lisp/pixel-scroll.el +++ b/lisp/pixel-scroll.el @@ -333,12 +333,14 @@ returns nil." (setq pos-list (cdr pos-list)))) visible-pos)) -(defun pixel-point-at-unseen-line () - "Return the character position of line above the selected window. -The returned value is the position of the first character on the -unseen line just above the scope of current window." +(defun pixel-point-and-height-at-unseen-line () + "Return the position and pixel height of line above the selected window. +The returned value is a cons of the position of the first +character on the unseen line just above the scope of current +window, and the pixel height of that line." (let* ((pos0 (window-start)) (vscroll0 (window-vscroll nil t)) + (line-height nil) (pos (save-excursion (goto-char pos0) @@ -350,11 +352,18 @@ unseen line just above the scope of current window." (tem (beginning-of-visual-line 0))) (if (eq tem ppos) (vertical-motion -1)) + (setq line-height (line-pixel-height)) (point)))))) ;; restore initial position (set-window-start nil pos0 t) (set-window-vscroll nil vscroll0 t) - pos)) + (cons pos line-height))) + +(defun pixel-point-at-unseen-line () + "Return the character position of line above the selected window. +The returned value is the position of the first character on the +unseen line just above the scope of current window." + (car (pixel-point-and-height-at-unseen-line))) (defun pixel-scroll-down-and-set-window-vscroll (vscroll) "Scroll down a line and set VSCROLL in pixels. @@ -426,14 +435,9 @@ the height of the current window." (setq delta (- delta current-vscroll)) (set-window-vscroll nil 0 t)) (while (> delta 0) - (set-window-start nil (save-excursion - (goto-char (window-start)) - (when (zerop (vertical-motion -1)) - (set-window-vscroll nil 0) - (signal 'beginning-of-buffer nil)) - (setq delta (- delta (line-pixel-height))) - (point)) - t)) + (let ((position (pixel-point-and-height-at-unseen-line))) + (set-window-start nil (car position) t) + (setq delta (- delta (cdr position))))) (when (< delta 0) (when-let* ((desired-pos (posn-at-x-y 0 (+ (- delta) (window-tab-line-height)