aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPo Lu2021-12-01 09:33:35 +0800
committerPo Lu2021-12-01 09:35:10 +0800
commit034d8a3ea8437a6ef88d33275e2a5818380afd74 (patch)
treecc2b55d508c850f65676f192fc08e69304a11705
parentaa0162ddfa30842a6dc5d5eebfae8f77aa7b15b9 (diff)
downloademacs-034d8a3ea8437a6ef88d33275e2a5818380afd74.tar.gz
emacs-034d8a3ea8437a6ef88d33275e2a5818380afd74.zip
Make pixel scrolling faster
* lisp/pixel-scroll.el (pixel-scroll-precision-scroll-down): Get rid of big motion loop. (pixel-scroll-precision-scroll-up): Stop subtracting height of window lines.
-rw-r--r--lisp/pixel-scroll.el79
1 files changed, 31 insertions, 48 deletions
diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el
index 5ffa8caa71c..f514a010ad0 100644
--- a/lisp/pixel-scroll.el
+++ b/lisp/pixel-scroll.el
@@ -375,59 +375,42 @@ Otherwise, redisplay will reset the window's vscroll."
375 "Scroll the current window down by DELTA pixels. 375 "Scroll the current window down by DELTA pixels.
376Note that this function doesn't work if DELTA is larger than 376Note that this function doesn't work if DELTA is larger than
377the height of the current window." 377the height of the current window."
378 (when-let* ((posn (posn-at-point)) 378 (let* ((desired-pos (posn-at-x-y 0 (+ delta
379 (current-y (cdr (posn-x-y posn))) 379 (window-tab-line-height)
380 (min-y (+ (frame-char-height) 380 (window-header-line-height))))
381 (window-tab-line-height) 381 (object (posn-object desired-pos))
382 (window-header-line-height))) 382 (desired-start (posn-point desired-pos))
383 (cursor-height (line-pixel-height)) 383 (desired-vscroll (cdr (posn-object-x-y desired-pos)))
384 (window-height (window-text-height nil t)) 384 (next-pos (save-excursion
385 (next-height (save-excursion 385 (goto-char desired-start)
386 (vertical-motion 1) 386 (when (zerop (vertical-motion 1))
387 (line-pixel-height)))) 387 (signal 'end-of-buffer nil))
388 (if (and (> delta 0) 388 (point))))
389 (<= cursor-height window-height)) 389 (if (and (< (point) next-pos)
390 (while (< (- current-y min-y) delta) 390 (let ((pos-visibility (pos-visible-in-window-p next-pos nil t)))
391 (vertical-motion 1) 391 (or (eq (length pos-visibility) 2)
392 (setq current-y (+ current-y 392 (when-let* ((posn (posn-at-point next-pos))
393 (line-pixel-height))) 393 (edges (window-edges nil t))
394 (when (eobp) 394 (usable-height (- (nth 3 edges)
395 (signal 'end-of-buffer nil))) 395 (nth 1 edges))))
396 (when (< (- (cdr (posn-object-width-height posn)) 396 (> (cdr (posn-object-width-height posn))
397 (cdr (posn-object-x-y posn))) 397 usable-height)))))
398 (- window-height next-height)) 398 (goto-char next-pos))
399 (vertical-motion 1) 399 (if (or (consp object) (stringp object))
400 (setq posn (posn-at-point) 400 ;; We are either on an overlay or a string, so set vscroll
401 current-y (cdr (posn-x-y posn))) 401 ;; directly.
402 (while (< (- current-y min-y) delta) 402 (set-window-vscroll nil (+ (window-vscroll nil t)
403 (vertical-motion 1) 403 delta)
404 (setq current-y (+ current-y 404 t)
405 (line-pixel-height))) 405 (unless (eq (window-start) desired-start)
406 (when (eobp) 406 (set-window-start nil desired-start t))
407 (signal 'end-of-buffer nil))))) 407 (set-window-vscroll nil desired-vscroll t))))
408 (let* ((desired-pos (posn-at-x-y 0 (+ delta
409 (window-tab-line-height)
410 (window-header-line-height))))
411 (object (posn-object desired-pos))
412 (desired-start (posn-point desired-pos))
413 (desired-vscroll (cdr (posn-object-x-y desired-pos))))
414 (if (or (consp object) (stringp object))
415 ;; We are either on an overlay or a string, so set vscroll
416 ;; directly.
417 (set-window-vscroll nil (+ (window-vscroll nil t)
418 delta)
419 t)
420 (unless (eq (window-start) desired-start)
421 (set-window-start nil desired-start t))
422 (set-window-vscroll nil desired-vscroll t)))))
423 408
424(defun pixel-scroll-precision-scroll-up (delta) 409(defun pixel-scroll-precision-scroll-up (delta)
425 "Scroll the current window up by DELTA pixels." 410 "Scroll the current window up by DELTA pixels."
426 (let* ((edges (window-edges nil t nil t)) 411 (let* ((edges (window-edges nil t nil t))
427 (max-y (- (nth 3 edges) 412 (max-y (- (nth 3 edges)
428 (nth 1 edges) 413 (nth 1 edges)))
429 (window-tab-line-height)
430 (window-header-line-height)))
431 (usable-height max-y)) 414 (usable-height max-y))
432 (when-let* ((posn (posn-at-point)) 415 (when-let* ((posn (posn-at-point))
433 (current-y (+ (cdr (posn-x-y posn)) 416 (current-y (+ (cdr (posn-x-y posn))