emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/consult 6337747fd0: Use consult--maybe-recenter instead


From: ELPA Syncer
Subject: [elpa] externals/consult 6337747fd0: Use consult--maybe-recenter instead of recenter to reduce movement/jumpiness
Date: Fri, 16 Jun 2023 09:57:47 -0400 (EDT)

branch: externals/consult
commit 6337747fd0cc273bb8c34ad8040cab0e9ccc0091
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Use consult--maybe-recenter instead of recenter to reduce movement/jumpiness
---
 CHANGELOG.org |  1 +
 consult.el    | 22 +++++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 659b1ccc58..134efd9354 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -15,6 +15,7 @@
   Similarly, the =INCLUDE= and =EXCLUDE= arguments of =consult--buffer-query= 
are also
   case sensitive.
 - Do not preview remote files by default, see =consult-preview-excluded-files=.
+- Use =consult--maybe-recenter= instead of =recenter= in 
=consult-after-jump-hook=.
 
 * Version 0.34 (2023-04-21)
 
diff --git a/consult.el b/consult.el
index d84c821dca..14619d50db 100644
--- a/consult.el
+++ b/consult.el
@@ -156,13 +156,14 @@ of the line after the prompt."
 nil shows all `custom-available-themes'."
   :type '(repeat (choice symbol regexp)))
 
-(defcustom consult-after-jump-hook '(recenter)
+(defcustom consult-after-jump-hook (list #'consult--maybe-recenter)
   "Function called after jumping to a location.
 
-Commonly used functions for this hook are `recenter' and
-`reposition-window'.  You may want to add a function which pulses the
-current line, e.g., `pulse-momentary-highlight-one-line' is supported on
-Emacs 28 and newer.  The hook called during preview and for the jump
+Commonly used functions for this hook are
+`consult--maybe-recenter', `recenter' and `reposition-window'.
+You may want to add a function which pulses the current line,
+e.g., `pulse-momentary-highlight-one-line' is supported on Emacs
+28 and newer.  The hook called during preview and for the jump
 after selection."
   :type 'hook)
 
@@ -556,6 +557,11 @@ We use invalid characters outside the Unicode range.")
 
 ;;;; Miscellaneous helper functions
 
+(defun consult--maybe-recenter ()
+  "Maybe recenter current window if point is outside of visible region."
+  (when (or (< (point) (window-start)) (> (point) (window-end nil t)))
+    (recenter)))
+
 (defun consult--key-parse (key)
   "Parse KEY or signal error if invalid."
   (unless (key-valid-p key)
@@ -1451,7 +1457,7 @@ See `isearch-open-necessary-overlays' and 
`isearch-open-overlay-temporary'."
       restore)))
 
 (defun consult--jump-1 (pos)
-  "Go to POS and recenter."
+  "Go to POS, switch buffer and widen if necessary."
   (if (and (markerp pos) (not (marker-buffer pos)))
       ;; Only print a message, no error in order to not mess
       ;; with the minibuffer update hook.
@@ -1466,7 +1472,9 @@ See `isearch-open-necessary-overlays' and 
`isearch-open-overlay-temporary'."
       (goto-char pos))))
 
 (defun consult--jump (pos)
-  "Push current position to mark ring, go to POS and recenter."
+  "Jump to POS.
+First push current position to mark ring, then move to new
+position and run `consult-after-jump-hook'."
   (when pos
     ;; Extract marker from list with with overlay positions, see 
`consult--line-match'
     (when (consp pos) (setq pos (car pos)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]