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

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

[elpa] master 9a9e3e4 251/399: ivy-test.el (swiper--isearch-format): Add


From: Oleh Krehel
Subject: [elpa] master 9a9e3e4 251/399: ivy-test.el (swiper--isearch-format): Add test
Date: Sat, 20 Jul 2019 14:57:34 -0400 (EDT)

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

    ivy-test.el (swiper--isearch-format): Add test
    
    * swiper.el (swiper-isearch-function): Extract.
    
    The test can be further improved by testing the string
    properties. However, it would become very verbose.
    
    Re #2069
---
 ivy-test.el | 27 ++++++++++++++++++++++++
 swiper.el   | 69 ++++++++++++++++++++++++++++++++-----------------------------
 2 files changed, 63 insertions(+), 33 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index ff76dcb..06441ab 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1105,6 +1105,33 @@ a buffer visiting a file."
        ("C-s" "Foo" "C-n RET")))
     "Foo\nfoo|\nFOO\n")))
 
+(ert-deftest swiper--isearch-format ()
+  (setq swiper--isearch-point-history
+        (list
+         (cons "" 1)))
+  (with-temp-buffer
+    (insert
+     "line0\nline1\nline line\nline line\nline5")
+    (let* ((input "li")
+           (cands (swiper--isearch-function input))
+           (len (length cands)))
+      (should (equal cands '(#("line0" 0 1 (point 3))
+                             #("line1" 0 1 (point 9))
+                             #("line line" 0 1 (point 15))
+                             #("line line" 0 1 (point 20))
+                             #("line line" 0 1 (point 25))
+                             #("line line" 0 1 (point 30))
+                             #("line5" 0 1 (point 35)))))
+      (dotimes (index len)
+        (should (string= (substring-no-properties
+                          (swiper--isearch-format
+                           index len
+                           cands
+                           input
+                           (nth index cands)
+                           (current-buffer)))
+                         "line0\nline1\nline line\nline line\nline5"))))))
+
 (ert-deftest ivy-use-selectable-prompt ()
   (let ((ivy-use-selectable-prompt t)
         (completing-read-function #'ivy-completing-read))
diff --git a/swiper.el b/swiper.el
index 8850090..60d1dc4 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1235,39 +1235,42 @@ come back to the same place as when \"a\" was initially 
entered.")
 (defun swiper-isearch-function (str)
   "Collect STR matches in the current buffer for `swiper-isearch'."
   (with-ivy-window
-    (let* ((case-fold-search (ivy--case-fold-p str))
-           (re-full (funcall ivy--regex-function str))
-           (re (ivy-re-to-str re-full)))
-      (unless (string= re "")
-        (let ((re (if (string-match "\\`\\(.*\\)[\\]|\\'" re)
-                      (match-string 1 re)
-                    re))
-              (pt-hist (cdr (assoc str swiper--isearch-point-history)))
-              cands
-              idx-found
-              (idx 0))
-          (save-excursion
-            (goto-char (point-min))
-            (while (re-search-forward re nil t)
-              (unless idx-found
-                (when (or
-                       (eq (match-beginning 0) pt-hist)
-                       (>= (match-beginning 0) (cdar 
swiper--isearch-point-history)))
-                  (push (cons str (match-beginning 0)) 
swiper--isearch-point-history)
-                  (setq idx-found idx)))
-              (cl-incf idx)
-              (let ((line (buffer-substring
-                           (line-beginning-position)
-                           (line-end-position)))
-                    (pos (if swiper-goto-start-of-match
-                             (match-beginning 0)
-                           (point))))
-                (put-text-property 0 1 'point pos line)
-                (push line cands))))
-          (setq ivy--old-re re)
-          (when idx-found
-            (ivy-set-index idx-found))
-          (setq ivy--old-cands (nreverse cands)))))))
+    (swiper--isearch-function str)))
+
+(defun swiper--isearch-function (str)
+  (let* ((case-fold-search (ivy--case-fold-p str))
+         (re-full (funcall ivy--regex-function str))
+         (re (ivy-re-to-str re-full)))
+    (unless (string= re "")
+      (let ((re (if (string-match "\\`\\(.*\\)[\\]|\\'" re)
+                    (match-string 1 re)
+                  re))
+            (pt-hist (cdr (assoc str swiper--isearch-point-history)))
+            cands
+            idx-found
+            (idx 0))
+        (save-excursion
+          (goto-char (point-min))
+          (while (re-search-forward re nil t)
+            (unless idx-found
+              (when (or
+                     (eq (match-beginning 0) pt-hist)
+                     (>= (match-beginning 0) (cdar 
swiper--isearch-point-history)))
+                (push (cons str (match-beginning 0)) 
swiper--isearch-point-history)
+                (setq idx-found idx)))
+            (cl-incf idx)
+            (let ((line (buffer-substring
+                         (line-beginning-position)
+                         (line-end-position)))
+                  (pos (if swiper-goto-start-of-match
+                           (match-beginning 0)
+                         (point))))
+              (put-text-property 0 1 'point pos line)
+              (push line cands))))
+        (setq ivy--old-re re)
+        (when idx-found
+          (ivy-set-index idx-found))
+        (setq ivy--old-cands (nreverse cands))))))
 
 (defun swiper-isearch-action (x)
   "Move to X for `swiper-isearch'."



reply via email to

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