summaryrefslogtreecommitdiff
path: root/lisp/pixel-scroll.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-01-09 15:29:25 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2018-01-09 15:29:25 -0800
commitddb26f79b20329ada5f5bc6e1742807d029e06c0 (patch)
tree4eb2572b11bba0c4fa7fc388dc2f65648be89b5e /lisp/pixel-scroll.el
parent0b33768053184ceadda0ca6dc431969e664cd17e (diff)
parent7668717d6fecd610d71b54a33708038b2ede8cce (diff)
downloademacs-ddb26f79b20329ada5f5bc6e1742807d029e06c0.tar.gz
emacs-ddb26f79b20329ada5f5bc6e1742807d029e06c0.tar.bz2
emacs-ddb26f79b20329ada5f5bc6e1742807d029e06c0.zip
Merge from origin/emacs-26
7668717d6f Merge from Gnulib 9e4d523427 * lisp/epg.el (epg-start-sign): Replace obsolete functions. 26c58f31a8 Small fix for erc-logging-enabled 34b41e3bc6 Quieten semantic normal usage e25f961e37 Avoid irrelevant hyperlink in doc string of 'epa-pinentry-... ec2636513c * doc/misc/tramp.texi (Remote processes): Mention gdb rest... 918a052a42 Query background for gnome terminal version 3.22 (Bug#29716) 1dfc27576a Make pixel-wise scrolling less laggy f92264fc2a Fix child frame placement issues (bug#29953) a5f718c4c5 ; * doc/lispref/text.texi (Change Hooks): Fix last change. e876f5f9fb Describe the precise interaction of complex primitives wit... 3a22097cf6 Fix valgrind report in call-interactively d5f1c87bfe * src/editfns.c (Fsave_excursion): Doc fix. (Bug#30001) b8d74c4578 Fix mark-defun when there's no spaces between successive d... a377c652b5 Fix Dired display and operations on file names with raw bytes d9d6e8a04c ; Comments related to src/termcap.c f8a07fa6b1 Improve documentation of 'gdb-many-windows' f82400798e Fix failures in smerge-mode on MS-Windows
Diffstat (limited to 'lisp/pixel-scroll.el')
-rw-r--r--lisp/pixel-scroll.el71
1 files changed, 48 insertions, 23 deletions
diff --git a/lisp/pixel-scroll.el b/lisp/pixel-scroll.el
index bfc48bac2e2..d362419e0fc 100644
--- a/lisp/pixel-scroll.el
+++ b/lisp/pixel-scroll.el
@@ -82,6 +82,27 @@ case you need scrolling resolution of a pixel, set to 1. After a
pixel scroll, typing \\[next-line] or \\[previous-line] scrolls the window to make it
fully visible, and undoes the effect of the pixel-level scroll.")
+(defvar pixel-dead-time 0.1
+ "Minimal interval in seconds before next smooth scrolling.
+If another scrolling request arrives within this period, scrolling
+will be carried out without pixel resolution. If zero, scrolling
+is always with pixel resolution.")
+
+(defvar pixel-last-scroll-time 0
+ "Time when the last scrolling was made, in second since the epoch.")
+
+(defun pixel-scroll-in-rush-p ()
+ "Return non-nil if next scroll should be non-smooth.
+When scrolling request is delivered soon after the previous one,
+user is in hurry. When the time since last scroll is larger than
+`pixel-dead-time', we are ready for another smooth scroll, and this
+function returns nil."
+ (let* ((current-time (float-time))
+ (scroll-in-rush-p (< (- current-time pixel-last-scroll-time)
+ pixel-dead-time)))
+ (setq pixel-last-scroll-time current-time)
+ scroll-in-rush-p))
+
;;;###autoload
(define-minor-mode pixel-scroll-mode
"A minor mode to scroll text pixel-by-pixel.
@@ -104,35 +125,39 @@ if ARG is omitted or nil."
This is an alternative of `scroll-up'. Scope moves downward."
(interactive)
(or arg (setq arg 1))
- (dotimes (ii arg) ; move scope downward
- (let ((amt (if pixel-resolution-fine-flag
- (if (integerp pixel-resolution-fine-flag)
- pixel-resolution-fine-flag
- (frame-char-height))
- (pixel-line-height))))
- (if (pixel-eob-at-top-p) ; when end-of-the-buffer is close
- (scroll-up 1) ; relay on robust method
- (while (pixel-point-at-top-p amt) ; prevent too late (multi tries)
- (vertical-motion 1)) ; move point downward
- (pixel-scroll-pixel-up amt))))) ; move scope downward
+ (if (pixel-scroll-in-rush-p)
+ (scroll-up arg)
+ (dotimes (ii arg) ; move scope downward
+ (let ((amt (if pixel-resolution-fine-flag
+ (if (integerp pixel-resolution-fine-flag)
+ pixel-resolution-fine-flag
+ (frame-char-height))
+ (pixel-line-height))))
+ (if (pixel-eob-at-top-p) ; when end-of-the-buffer is close
+ (scroll-up 1) ; relay on robust method
+ (while (pixel-point-at-top-p amt) ; prevent too late (multi tries)
+ (vertical-motion 1)) ; move point downward
+ (pixel-scroll-pixel-up amt)))))) ; move scope downward
(defun pixel-scroll-down (&optional arg)
"Scroll text of selected window down ARG lines.
This is and alternative of `scroll-down'. Scope moves upward."
(interactive)
(or arg (setq arg 1))
- (dotimes (ii arg)
- (let ((amt (if pixel-resolution-fine-flag
- (if (integerp pixel-resolution-fine-flag)
- pixel-resolution-fine-flag
- (frame-char-height))
- (pixel-line-height -1))))
- (while (pixel-point-at-bottom-p amt) ; prevent too late (multi tries)
- (vertical-motion -1)) ; move point upward
- (if (or (pixel-bob-at-top-p amt) ; when beginning-of-the-buffer is seen
- (pixel-eob-at-top-p)) ; for file with a long line
- (scroll-down 1) ; relay on robust method
- (pixel-scroll-pixel-down amt)))))
+ (if (pixel-scroll-in-rush-p)
+ (scroll-down arg)
+ (dotimes (ii arg)
+ (let ((amt (if pixel-resolution-fine-flag
+ (if (integerp pixel-resolution-fine-flag)
+ pixel-resolution-fine-flag
+ (frame-char-height))
+ (pixel-line-height -1))))
+ (while (pixel-point-at-bottom-p amt) ; prevent too late (multi tries)
+ (vertical-motion -1)) ; move point upward
+ (if (or (pixel-bob-at-top-p amt) ; when beginning-of-the-buffer is seen
+ (pixel-eob-at-top-p)) ; for file with a long line
+ (scroll-down 1) ; relay on robust method
+ (pixel-scroll-pixel-down amt))))))
(defun pixel-bob-at-top-p (amt)
"Return non-nil if window-start is at beginning of the current buffer.