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

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

[elpa] master 4c3ecb4 157/348: Restore window position after using swipe


From: Oleh Krehel
Subject: [elpa] master 4c3ecb4 157/348: Restore window position after using swiper.
Date: Sat, 8 Apr 2017 11:03:47 -0400 (EDT)

branch: master
commit 4c3ecb4d739df379dd01ac8c7dc17080e608dac3
Author: Stephen Whipple <address@hidden>
Commit: Stephen Whipple <address@hidden>

    Restore window position after using swiper.
    
    This prevents a "jumping" behavior which occurs when variables
    such as `scroll-conservatively' are set to a high value.
    
    * swiper.el (swiper--current-match-start): Hold the window-start
    position for restoration.
    (swiper--action): If `swiper-action-recenter' is nil, then restore
    the window-start that was used during selection.
---
 swiper.el | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/swiper.el b/swiper.el
index 65f3690..d941f73 100644
--- a/swiper.el
+++ b/swiper.el
@@ -409,11 +409,13 @@ When REVERT is non-nil, regenerate the current 
*ivy-occur* buffer."
 
 (defvar swiper--current-line nil)
 (defvar swiper--current-match-start nil)
+(defvar swiper--current-window-start nil)
 
 (defun swiper--init ()
   "Perform initialization common to both completion methods."
   (setq swiper--current-line nil)
   (setq swiper--current-match-start nil)
+  (setq swiper--current-window-start nil)
   (setq swiper--opoint (point))
   (when (bound-and-true-p evil-mode)
     (evil-set-jump)))
@@ -574,7 +576,8 @@ Matched candidates should have `swiper-invocation-face'."
                                      (line-end-position))
             (unless (and (>= (point) (window-start))
                          (<= (point) (window-end (ivy-state-window ivy-last) 
t)))
-              (recenter))))
+              (recenter))
+            (setq swiper--current-window-start (window-start))))
         (swiper--add-overlays re)))))
 
 (defun swiper--add-overlays (re &optional beg end wnd)
@@ -651,8 +654,9 @@ WND, when specified is the window."
                  ln)
         (re-search-forward re (line-end-position) t)
         (swiper--ensure-visible)
-        (when swiper-action-recenter
-          (recenter))
+        (if swiper-action-recenter
+            (recenter)
+          (set-window-start (selected-window) swiper--current-window-start))
         (when (/= (point) swiper--opoint)
           (unless (and transient-mark-mode mark-active)
             (when (eq ivy-exit 'done)



reply via email to

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