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

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

[elpa] master 02065be 19/67: swiper.el: Restore original point on cancel


From: Oleh Krehel
Subject: [elpa] master 02065be 19/67: swiper.el: Restore original point on canceling
Date: Sun, 22 Mar 2015 17:33:54 +0000

branch: master
commit 02065be07453d243c6e1b49d5fdd01ba685c8419
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    swiper.el: Restore original point on canceling
    
    * swiper.el (swiper--opoint): New defvar.
    (swiper): Update.
    (swiper--ivy): Update.
    
    Fixes #9.
---
 swiper.el |   33 ++++++++++++++++++++-------------
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/swiper.el b/swiper.el
index afc1642..b838124 100644
--- a/swiper.el
+++ b/swiper.el
@@ -110,11 +110,15 @@
     map)
   "Allows you to go to next and previous hit isearch-style.")
 
+(defvar swiper--opoint
+  "The point when `swiper' starts.")
+
 ;;;###autoload
 (defun swiper (&optional initial-input)
   "`isearch' with an overview.
 When non-nil, INITIAL-INPUT is the initial search pattern."
   (interactive)
+  (setq swiper--opoint (point))
   (if (and (eq 'swiper-completion-method 'helm)
            (featurep 'helm))
       (swiper--helm initial-input)
@@ -133,19 +137,22 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
   (interactive)
   (ido-mode -1)
   (swiper--init)
-  (unwind-protect
-       (let ((res (ivy-read "pattern: "
-                            (swiper--candidates)
-                            initial-input
-                            #'swiper--update-input-ivy)))
-         (goto-char (point-min))
-         (forward-line (1- (read res)))
-         (re-search-forward
-          (ivy--regex ivy-text)
-          (line-end-position)
-          t))
-    (ido-mode 1)
-    (swiper--cleanup)))
+  (let (res)
+    (unwind-protect
+         (setq res (ivy-read "pattern: "
+                             (swiper--candidates)
+                             initial-input
+                             #'swiper--update-input-ivy))
+      (ido-mode 1)
+      (swiper--cleanup)
+      (if (null ivy-exit)
+          (goto-char swiper--opoint)
+        (goto-char (point-min))
+        (forward-line (1- (read res)))
+        (re-search-forward
+         (ivy--regex ivy-text)
+         (line-end-position)
+         t)))))
 
 (defun swiper--helm (&optional initial-input)
   "`isearch' with an overview using `helm'.



reply via email to

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