[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scroll-on-jump 5a6f698b6f 23/31: Cleanup: replace 'if' wit
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scroll-on-jump 5a6f698b6f 23/31: Cleanup: replace 'if' with 'cond' |
Date: |
Thu, 7 Jul 2022 12:03:14 -0400 (EDT) |
branch: elpa/scroll-on-jump
commit 5a6f698b6f27364abb98bc43f096c783087d453f
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Cleanup: replace 'if' with 'cond'
---
scroll-on-jump.el | 371 ++++++++++++++++++++++++++++--------------------------
1 file changed, 191 insertions(+), 180 deletions(-)
diff --git a/scroll-on-jump.el b/scroll-on-jump.el
index 7640faee0b..d22807feae 100644
--- a/scroll-on-jump.el
+++ b/scroll-on-jump.el
@@ -174,66 +174,68 @@ Moving the point when ALSO-MOVE-POINT is set."
(use-curve scroll-on-jump-use-curve))
;; Animated scrolling (early exit on input to avoid annoying lag).
- (if (not (zerop lines-scroll))
- (let
- (
- (is-early-exit t)
- (inhibit-point-motion-hooks t)
- (lines-done-abs 0)
- (lines-scroll-abs (abs lines-scroll)))
- (while-no-input
- (while (< lines-done-abs lines-scroll-abs)
- ;; Inhibit quit in all of this logic except re-display.
- (let
- (
- (inhibit-quit t)
- ;; Number of lines to move for this redraw.
- (step
- (let*
- (
- (time-elapsed (float-time (time-subtract (current-time)
time-init)))
- (factor (min 1.0 (/ time-elapsed time-limit)))
- (lines-target
- (floor
- (cond
- (use-curve
- (scroll-on-jump--interpolate-ease 0.0
lines-scroll-abs factor))
- (t
- (* lines-scroll-abs factor)))))
- (lines-remainder (- lines-target lines-done-abs)))
- ;; Step result, we must move at least one line.
- (* dir (max 1 lines-remainder)))))
-
- ;; Check if this is the last step.
- (setq lines-done-abs (+ lines-done-abs (abs step)))
- (when (> lines-done-abs lines-scroll-abs)
- (setq step (- step (* dir (- lines-done-abs
lines-scroll-abs)))))
-
- ;; Faster alternative to scroll.
- (scroll-on-jump--scroll-by-lines-simple window step nil)
-
- (when also-move-point
- (forward-line step))
-
- (setq lines-scroll (- lines-scroll step)))
-
- ;; Skip the last redraw, so there isn't 2x update when
- ;; the caller moves the point to the final location.
- (when (< lines-done-abs lines-scroll-abs)
- ;; Force `redisplay', without this redrawing can be a little
choppy.
- (redisplay t)))
- (setq is-early-exit nil))
-
- ;; ;; Re-enable when editing logic.
- (when (and (null is-early-exit) (not (zerop lines-scroll)))
- (error "Internal error, 'lines-scroll' should be zero"))
-
- ;; If we exit early because of input.
- (when is-early-exit
- (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil)))
+ (cond
+ ((not (zerop lines-scroll))
+ (let
+ (
+ (is-early-exit t)
+ (inhibit-point-motion-hooks t)
+ (lines-done-abs 0)
+ (lines-scroll-abs (abs lines-scroll)))
+ (while-no-input
+ (while (< lines-done-abs lines-scroll-abs)
+ ;; Inhibit quit in all of this logic except re-display.
+ (let
+ (
+ (inhibit-quit t)
+ ;; Number of lines to move for this redraw.
+ (step
+ (let*
+ (
+ (time-elapsed (float-time (time-subtract
(current-time) time-init)))
+ (factor (min 1.0 (/ time-elapsed time-limit)))
+ (lines-target
+ (floor
+ (cond
+ (use-curve
+ (scroll-on-jump--interpolate-ease 0.0
lines-scroll-abs factor))
+ (t
+ (* lines-scroll-abs factor)))))
+ (lines-remainder (- lines-target lines-done-abs)))
+ ;; Step result, we must move at least one line.
+ (* dir (max 1 lines-remainder)))))
+
+ ;; Check if this is the last step.
+ (setq lines-done-abs (+ lines-done-abs (abs step)))
+ (when (> lines-done-abs lines-scroll-abs)
+ (setq step (- step (* dir (- lines-done-abs
lines-scroll-abs)))))
+
+ ;; Faster alternative to scroll.
+ (scroll-on-jump--scroll-by-lines-simple window step nil)
+
+ (when also-move-point
+ (forward-line step))
+
+ (setq lines-scroll (- lines-scroll step)))
+
+ ;; Skip the last redraw, so there isn't 2x update when
+ ;; the caller moves the point to the final location.
+ (when (< lines-done-abs lines-scroll-abs)
+ ;; Force `redisplay', without this redrawing can be a little
choppy.
+ (redisplay t)))
+ (setq is-early-exit nil))
+
+ ;; ;; Re-enable when editing logic.
+ (when (and (null is-early-exit) (not (zerop lines-scroll)))
+ (error "Internal error, 'lines-scroll' should be zero"))
+
+ ;; If we exit early because of input.
+ (when is-early-exit
+ (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))))
;; Non-animated scrolling (immediate).
- (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil)))
+ (t
+ (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))))
(run-window-scroll-functions window))
@@ -253,90 +255,92 @@ Argument ALSO-MOVE-POINT moves the point while scrolling."
(char-height (frame-char-height (window-frame window))))
;; Animated scrolling (early exit on input to avoid annoying lag).
- (if (not (zerop lines-scroll))
- (let
- (
- (is-early-exit t)
- (inhibit-point-motion-hooks t)
- (px-done-abs 0)
- (px-scroll-abs (abs (* lines-scroll char-height)))
- (px-scroll (* lines-scroll char-height)))
-
- ;; Workaround for situations when the `point' starts at the window
bounds.
- ;; If this happens we can't do any sub-pixel scrolling as the `point'
locks scrolling.
- ;; This is only needed for pixel level scrolling.
- ;;
- ;; We can move arbitrary lines here since the final point is set at
the very end.
- (when also-move-point
- (forward-line dir))
-
- (while-no-input
- (while (< px-done-abs px-scroll-abs)
- ;; Inhibit quit in all of this logic except re-display.
- (let
- (
- (inhibit-quit t)
- ;; Number of pixels to move for this redraw.
- (step
- (let*
- (
- (time-elapsed (float-time (time-subtract (current-time)
time-init)))
- (factor (min 1.0 (/ time-elapsed time-limit)))
- (px-target
- (floor
- (cond
- (use-curve
- (scroll-on-jump--interpolate-ease 0.0
px-scroll-abs factor))
- (t
- (* px-scroll-abs factor)))))
- (px-remainder (- px-target px-done-abs)))
- (* dir px-remainder))))
-
- ;; Check if this is the last step.
- (setq px-done-abs (+ px-done-abs (abs step)))
- (when (> px-done-abs px-scroll-abs)
- (setq step (- step (* dir (- px-done-abs px-scroll-abs)))))
-
- (pcase-let
+ (cond
+ ((not (zerop lines-scroll))
+ (let
+ (
+ (is-early-exit t)
+ (inhibit-point-motion-hooks t)
+ (px-done-abs 0)
+ (px-scroll-abs (abs (* lines-scroll char-height)))
+ (px-scroll (* lines-scroll char-height)))
+
+ ;; Workaround for situations when the `point' starts at the window
bounds.
+ ;; If this happens we can't do any sub-pixel scrolling as the
`point' locks scrolling.
+ ;; This is only needed for pixel level scrolling.
+ ;;
+ ;; We can move arbitrary lines here since the final point is set at
the very end.
+ (when also-move-point
+ (forward-line dir))
+
+ (while-no-input
+ (while (< px-done-abs px-scroll-abs)
+ ;; Inhibit quit in all of this logic except re-display.
+ (let
(
- (`(,_lines-remainder . ,lines-handled)
- (scroll-on-jump--scroll-by-pixels window char-height step
nil)))
+ (inhibit-quit t)
+ ;; Number of pixels to move for this redraw.
+ (step
+ (let*
+ (
+ (time-elapsed (float-time (time-subtract
(current-time) time-init)))
+ (factor (min 1.0 (/ time-elapsed time-limit)))
+ (px-target
+ (floor
+ (cond
+ (use-curve
+ (scroll-on-jump--interpolate-ease 0.0
px-scroll-abs factor))
+ (t
+ (* px-scroll-abs factor)))))
+ (px-remainder (- px-target px-done-abs)))
+ (* dir px-remainder))))
+
+ ;; Check if this is the last step.
+ (setq px-done-abs (+ px-done-abs (abs step)))
+ (when (> px-done-abs px-scroll-abs)
+ (setq step (- step (* dir (- px-done-abs px-scroll-abs)))))
+
+ (pcase-let
+ (
+ (`(,_lines-remainder . ,lines-handled)
+ (scroll-on-jump--scroll-by-pixels window char-height
step nil)))
- ;; Forward lines separately since we might be at end of the
buffer
- ;; and we want to be able to scroll - even if the point has
reached it's limit.
- (when also-move-point
- (forward-line lines-handled))
+ ;; Forward lines separately since we might be at end of the
buffer
+ ;; and we want to be able to scroll - even if the point has
reached it's limit.
+ (when also-move-point
+ (forward-line lines-handled))
- (setq lines-scroll (- lines-scroll lines-handled)))
+ (setq lines-scroll (- lines-scroll lines-handled)))
- (setq px-scroll (- px-scroll step)))
+ (setq px-scroll (- px-scroll step)))
- ;; Skip the last redraw, so there isn't 2x update when
- ;; the caller moves the point to the final location.
- (when (< px-done-abs px-scroll-abs)
- ;; Force `redisplay', without this redrawing can be a little
choppy.
- (redisplay t)))
- (setq is-early-exit nil))
+ ;; Skip the last redraw, so there isn't 2x update when
+ ;; the caller moves the point to the final location.
+ (when (< px-done-abs px-scroll-abs)
+ ;; Force `redisplay', without this redrawing can be a little
choppy.
+ (redisplay t)))
+ (setq is-early-exit nil))
- (cond
- ;; If we exit early because of input.
- (is-early-exit
- ;; Early exit, reset pixel scroll and scroll lines.
- (set-window-vscroll window 0 t)
- (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))
+ (cond
+ ;; If we exit early because of input.
+ (is-early-exit
+ ;; Early exit, reset pixel scroll and scroll lines.
+ (set-window-vscroll window 0 t)
+ (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))
- ;; Sanity check, if this fails there is an issue with internal logic.
- ((not (zerop px-scroll))
- (set-window-vscroll window 0 t)
- (error "Internal error, 'px-scroll' should be zero"))
+ ;; Sanity check, if this fails there is an issue with internal
logic.
+ ((not (zerop px-scroll))
+ (set-window-vscroll window 0 t)
+ (error "Internal error, 'px-scroll' should be zero"))
- ;; Also should never happen.
- ((not (zerop (window-vscroll window t)))
- (set-window-vscroll window 0 t)
- (message "Warning, sub-pixel scroll left set!"))))
+ ;; Also should never happen.
+ ((not (zerop (window-vscroll window t)))
+ (set-window-vscroll window 0 t)
+ (message "Warning, sub-pixel scroll left set!")))))
;; Non-animated scrolling (immediate).
- (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil)))
+ (t
+ (scroll-on-jump--scroll-by-lines-simple window lines-scroll nil))))
(run-window-scroll-functions window))
@@ -372,48 +376,52 @@ Moving the point when ALSO-MOVE-POINT is set."
(height (window-height window))
(lines-scroll 0)
(dir
- (if (< point-prev point-next)
- 1
- -1)))
-
- (if (eq dir 1)
- (let*
- (
- (window-lines-prev (count-screen-lines (window-start window)
point-prev t window))
- (window-lines-next (+ window-lines-prev lines))
- (lines-limit (max (/ height 2) window-lines-prev)))
- (when (>= window-lines-next lines-limit)
- (setq lines-scroll (- window-lines-next lines-limit))
- ;; Clamp lines-scroll by the window end
- ;; Only needed when scrolling down.
- ;;
- ;; Do this so we don't scroll past the end.
- (setq lines-scroll
- (-
- lines-scroll
- (save-excursion
- (goto-char (window-end))
- (forward-line lines-scroll))))))
- (let*
- ( ;; Note that we can't use `window-end' here as we may
- ;; be scrolled past the screen end-point.
- (window-lines-prev
- (- height (count-screen-lines (window-start window) point-prev
t window)))
- (window-lines-next (+ window-lines-prev lines))
- (lines-limit (max (/ height 2) window-lines-prev)))
- (when (>= window-lines-next lines-limit)
- (setq lines-scroll (- lines-limit window-lines-next))
- ;; Clamp lines-scroll by the window start
- ;; Only needed when scrolling up.
- ;;
- ;; Even though scroll can't scroll past the start,
- ;; we don't want to try to animate scrolling up in this case.
- (setq lines-scroll
- (-
- lines-scroll
- (save-excursion
- (goto-char (window-start window))
- (forward-line lines-scroll)))))))
+ (cond
+ ((< point-prev point-next)
+ 1)
+ (t
+ -1))))
+
+ (cond
+ ((eq dir 1)
+ (let*
+ (
+ (window-lines-prev (count-screen-lines (window-start window)
point-prev t window))
+ (window-lines-next (+ window-lines-prev lines))
+ (lines-limit (max (/ height 2) window-lines-prev)))
+ (when (>= window-lines-next lines-limit)
+ (setq lines-scroll (- window-lines-next lines-limit))
+ ;; Clamp lines-scroll by the window end
+ ;; Only needed when scrolling down.
+ ;;
+ ;; Do this so we don't scroll past the end.
+ (setq lines-scroll
+ (-
+ lines-scroll
+ (save-excursion
+ (goto-char (window-end))
+ (forward-line lines-scroll)))))))
+ (t
+ (let*
+ ( ;; Note that we can't use `window-end' here as we may
+ ;; be scrolled past the screen end-point.
+ (window-lines-prev
+ (- height (count-screen-lines (window-start window)
point-prev t window)))
+ (window-lines-next (+ window-lines-prev lines))
+ (lines-limit (max (/ height 2) window-lines-prev)))
+ (when (>= window-lines-next lines-limit)
+ (setq lines-scroll (- lines-limit window-lines-next))
+ ;; Clamp lines-scroll by the window start
+ ;; Only needed when scrolling up.
+ ;;
+ ;; Even though scroll can't scroll past the start,
+ ;; we don't want to try to animate scrolling up in this case.
+ (setq lines-scroll
+ (-
+ lines-scroll
+ (save-excursion
+ (goto-char (window-start window))
+ (forward-line lines-scroll))))))))
(let ((also-move-point (not (eq (point) point-next))))
(scroll-on-jump--scroll-impl window lines-scroll dir
also-move-point)))))
@@ -464,8 +472,8 @@ Argument USE-WINDOW-START detects window scrolling when
non-nil."
(goto-char point-next))
(t ;; Perform animated scroll.
- (if window-start-prev
- (progn
+ (cond
+ (window-start-prev
(setq window-start-next (window-start window))
(unless (eq window-start-prev window-start-next)
(set-window-start window window-start-prev)
@@ -474,14 +482,17 @@ Argument USE-WINDOW-START detects window scrolling when
non-nil."
(lines-scroll
(1- (count-screen-lines window-start-prev
window-start-next t window)))
(dir
- (if (< window-start-prev window-start-next)
- 1
- -1))
+ (cond
+ ((< window-start-prev window-start-next)
+ 1)
+ (t
+ -1)))
(also-move-point (not (eq (point) point-next))))
(scroll-on-jump--scroll-impl window (* dir lines-scroll) dir
also-move-point)))
(prog1 (goto-char point-next)
(redisplay t)))
- (scroll-on-jump-auto-center window point-prev point-next)))))))
+ (t
+ (scroll-on-jump-auto-center window point-prev point-next))))))))
;; ---------------------------------------------------------------------------
- [nongnu] elpa/scroll-on-jump dd2818d906 17/31: Cleanup: make docstring under 80 chars, (continued)
- [nongnu] elpa/scroll-on-jump dd2818d906 17/31: Cleanup: make docstring under 80 chars, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 30dc5f5e50 21/31: Cleanup: remove recursion check, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 28bac2cdc3 22/31: Cleanup: quiet checkdoc warnings for wide docstrings, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 0ce93b3ea6 19/31: readme: remove 'evil-goto-first-line' as 'evil-goto-line' already scrolls, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 000dc41039 25/31: Fix error passing out-of-range point to count-screen-lines, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 99386fc01b 30/31: Cleanup: use brief SPDX license, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 556e9a7a81 28/31: Fix error detecting scroll changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 9767013ca8 13/31: Support wrapping functions that themselves scroll, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 8fde237ae6 31/31: Change URL to codeberg, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump a614bc7f8f 06/31: Fix the case when the windows buffer is not the current-buffer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 5a6f698b6f 23/31: Cleanup: replace 'if' with 'cond',
ELPA Syncer <=
- [nongnu] elpa/scroll-on-jump 1e9e09f0cc 29/31: Fix error counting lines jumping to a point outside buffer range, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump a2d6996a36 24/31: Cleanup: use defgroup, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 7b2919f8d8 27/31: Fix smooth (pixel) scrolling not being used in most cases, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 1f2349edf4 04/31: Fix scrolling down when the point is at the beginning of the buffer, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump e8b79d35d4 09/31: Cleanup: split scroll-on-jump--scroll-impl into it's own function, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 028e672391 03/31: Cleanup: no need for `let*`, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump eb77ab1920 02/31: readme: add a more complete example, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 9c333320ea 05/31: Don't catch and re-raise errors, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 7a51468bdd 14/31: Cleanup: declare variable, ELPA Syncer, 2022/07/07
- [nongnu] elpa/scroll-on-jump 0cf26a15bb 26/31: Cleanup: use window-body-height, ELPA Syncer, 2022/07/07