]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `pixel-scroll-precision-scroll-up' use existing logic
authorPo Lu <luangruo@yahoo.com>
Sat, 27 Nov 2021 05:02:10 +0000 (13:02 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 27 Nov 2021 05:03:54 +0000 (13:03 +0800)
* 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.

lisp/pixel-scroll.el

index f6d1d0ff8ca7ba115ee2f398e99788f5be952e55..131519a2585bb3b651136f3e23a39578b6528e96 100644 (file)
@@ -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)