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

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

[elpa] master c4c1878 121/167: Fix swiper preselect issue with similar o


From: Oleh Krehel
Subject: [elpa] master c4c1878 121/167: Fix swiper preselect issue with similar or identical lines
Date: Tue, 08 Dec 2015 10:50:26 +0000

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

    Fix swiper preselect issue with similar or identical lines
    
    * ivy.el (ivy--preselect-index): Allow PRESELECT to be an integer.
    
    * swiper.el (swiper--anchor):
    (swiper--len): Remove unused defvar.
    (swiper--init): Update.
    (swiper--ivy): Set PRESELECT to `line-number-at-pos'.
    
    Fixes #290
---
 ivy.el    |   16 +++++++++-------
 swiper.el |   43 +++++++++++++++++++------------------------
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/ivy.el b/ivy.el
index bf89836..92b87fd 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1293,13 +1293,15 @@ When MATCHER is non-nil it's used instead of 
`cl-remove-if-not'."
                  candidates))))
     (when matcher
       (setq candidates (funcall matcher "" candidates))))
-  (or (cl-position preselect candidates :test #'equal)
-      (and (stringp preselect)
-           (let ((re (regexp-quote preselect)))
-             (cl-position-if
-              (lambda (x)
-                (string-match re x))
-              candidates)))))
+  (cond ((integerp preselect)
+         preselect)
+        ((cl-position preselect candidates :test #'equal))
+        ((stringp preselect)
+         (let ((re (regexp-quote preselect)))
+           (cl-position-if
+            (lambda (x)
+              (string-match re x))
+            candidates)))))
 
 ;;* Implementation
 ;;** Regex
diff --git a/swiper.el b/swiper.el
index 56247ed..eec7434 100644
--- a/swiper.el
+++ b/swiper.el
@@ -298,19 +298,11 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
   (interactive)
   (swiper--ivy initial-input))
 
-(defvar swiper--anchor nil
-  "A line number to which the search should be anchored.")
-
-(defvar swiper--len 0
-  "The last length of input for which an anchoring was made.")
-
 (declare-function evil-jumper--set-jump "ext:evil-jumper")
 
 (defun swiper--init ()
   "Perform initialization common to both completion methods."
   (setq swiper--opoint (point))
-  (setq swiper--len 0)
-  (setq swiper--anchor (line-number-at-pos))
   (when (bound-and-true-p evil-jumper-mode)
     (evil-jumper--set-jump)))
 
@@ -348,24 +340,27 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
   (setq swiper-invocation-face
         (plist-get (text-properties-at (point)) 'face))
   (let ((candidates (swiper--candidates))
-        (preselect (buffer-substring-no-properties
-                    (line-beginning-position)
-                    (line-end-position)))
+        (preselect
+         (if (bound-and-true-p visual-line-mode)
+             (concat " " (buffer-substring-no-properties
+                          (line-beginning-position)
+                          (line-end-position)))
+           (1- (line-number-at-pos))))
         (minibuffer-allow-text-properties t))
     (unwind-protect
-        (ivy-read
-         "Swiper: "
-         candidates
-         :initial-input initial-input
-         :keymap swiper-map
-         :preselect preselect
-         :require-match t
-         :update-fn #'swiper--update-input-ivy
-         :unwind #'swiper--cleanup
-         :action #'swiper--action
-         :re-builder #'swiper--re-builder
-         :history 'swiper-history
-         :caller 'swiper)
+         (ivy-read
+          "Swiper: "
+          candidates
+          :initial-input initial-input
+          :keymap swiper-map
+          :preselect preselect
+          :require-match t
+          :update-fn #'swiper--update-input-ivy
+          :unwind #'swiper--cleanup
+          :action #'swiper--action
+          :re-builder #'swiper--re-builder
+          :history 'swiper-history
+          :caller 'swiper)
       (when (null ivy-exit)
         (goto-char swiper--opoint)))))
 



reply via email to

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