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

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

[elpa] master 4d40f88 255/399: swiper.el (swiper--isearch-function): Spe


From: Oleh Krehel
Subject: [elpa] master 4d40f88 255/399: swiper.el (swiper--isearch-function): Speedup for big files
Date: Sat, 20 Jul 2019 14:57:35 -0400 (EDT)

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

    swiper.el (swiper--isearch-function): Speedup for big files
    
    Collect only point positions, not the lines themselves.
    
    * ivy.el (ivy--remove-props):
    (ivy--format):
    (ivy--wnd-cands-to-str): Adapt to the case when the candidates aren't 
strings.
    
    Perhaps the call to `ivy--format-minibuffer-line' can be moved to
    `ivy-format-function'. This can result in a cleaner (and possibly more
    flexible) code. But then every instance of `ivy-format-function' has
    to be rewritten to apply `ivy--format-minibuffer-line'.
    
    * ivy-test.el (swiper--isearch-format): Update.
    
    * swiper.el (swiper-isearch-action): Adapt.
    (swiper--line-at-point): Add.
    (swiper--isearch-format): Update.
---
 ivy-test.el |  8 +-------
 ivy.el      | 16 +++++++++++-----
 swiper.el   | 36 +++++++++++++++++++++---------------
 3 files changed, 33 insertions(+), 27 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 06441ab..dad5616 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1115,13 +1115,7 @@ a buffer visiting a file."
     (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)))))
+      (should (equal cands '(3 9 15 20 25 30 35)))
       (dotimes (index len)
         (should (string= (substring-no-properties
                           (swiper--isearch-format
diff --git a/ivy.el b/ivy.el
index 19bcda8..ce53a9a 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1788,7 +1788,8 @@ found, it falls back to the key t."
 
 (defun ivy--remove-props (str &rest props)
   "Return STR with text PROPS destructively removed."
-  (remove-list-of-text-properties 0 (length str) props str)
+  (ignore-errors
+    (remove-list-of-text-properties 0 (length str) props str))
   str)
 
 ;;** Entry Point
@@ -3614,7 +3615,10 @@ CANDS is a list of strings."
     (ivy-set-index (max (1- ivy--length) 0)))
   (if (null cands)
       (setf (ivy-state-current ivy-last) "")
-    (setf (ivy-state-current ivy-last) (copy-sequence (nth ivy--index cands)))
+    (let ((cur (nth ivy--index cands)))
+      (setf (ivy-state-current ivy-last) (if (stringp cur)
+                                             (copy-sequence cur)
+                                           cur)))
     (let* ((bnd (ivy--minibuffer-index-bounds
                  ivy--index ivy--length ivy-height))
            (wnd-cands (cl-subseq cands (car bnd) (cadr bnd)))
@@ -3629,9 +3633,11 @@ CANDS is a list of strings."
 (defun ivy--wnd-cands-to-str (wnd-cands)
   (let ((str (concat "\n"
                      (funcall ivy-format-function
-                              (mapcar
-                               #'ivy--format-minibuffer-line
-                               wnd-cands)))))
+                              (condition-case nil
+                                  (mapcar
+                                   #'ivy--format-minibuffer-line
+                                   wnd-cands)
+                                (error wnd-cands))))))
     (put-text-property 0 (length str) 'read-only nil str)
     str))
 
diff --git a/swiper.el b/swiper.el
index ec73b5e..ea2d913 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1268,14 +1268,10 @@ come back to the same place as when \"a\" was initially 
entered.")
                 (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
+            (let ((pos (if swiper-goto-start-of-match
                            (match-beginning 0)
                          (point))))
-              (put-text-property 0 1 'point pos line)
-              (push line cands))))
+              (push pos cands))))
         (setq ivy--old-re re)
         (when idx-found
           (ivy-set-index idx-found))
@@ -1283,9 +1279,9 @@ come back to the same place as when \"a\" was initially 
entered.")
 
 (defun swiper-isearch-action (x)
   "Move to X for `swiper-isearch'."
-  (if (> (length x) 0)
+  (if (numberp x)
       (with-ivy-window
-        (goto-char (get-text-property 0 'point x))
+        (goto-char x)
         (isearch-range-invisible (line-beginning-position)
                                  (line-end-position))
         (unless (eq ivy-exit 'done)
@@ -1349,6 +1345,15 @@ When not running `swiper-isearch' already, start it."
    (ivy-state-current ivy-last)
    (ivy-state-buffer ivy-last)))
 
+(defun swiper--line-at-point (pt)
+  (save-excursion
+    (goto-char pt)
+    (let ((s (buffer-substring
+              (line-beginning-position)
+              (line-end-position))))
+      (put-text-property 0 1 'point pt s)
+      s)))
+
 (defun swiper--isearch-format (index length cands regex current buffer)
   (let* ((half-height (/ ivy-height 2))
          (i (1- index))
@@ -1358,13 +1363,13 @@ When not running `swiper-isearch' already, start it."
     (with-current-buffer buffer
       (while (and (>= i 0)
                   (swiper--isearch-same-line-p
-                   (nth i cands)
-                   current))
+                   (swiper--line-at-point (nth i cands))
+                   (swiper--line-at-point current)))
         (cl-decf i)
         (cl-incf j))
       (while (and (>= i 0)
                   (< len half-height))
-        (setq s (nth i cands))
+        (setq s (swiper--line-at-point (nth i cands)))
         (unless (swiper--isearch-same-line-p s (car res))
           (push (ivy--format-minibuffer-line s) res)
           (cl-incf len))
@@ -1372,7 +1377,8 @@ When not running `swiper-isearch' already, start it."
       (setq res (nreverse res))
       (let ((current-str
              (ivy--add-face
-              (ivy--format-minibuffer-line current)
+              (ivy--format-minibuffer-line
+               (swiper--line-at-point current))
               'ivy-current-match))
             (start 0))
         (dotimes (_ (1+ j))
@@ -1386,12 +1392,12 @@ When not running `swiper-isearch' already, start it."
       (setq i (1+ index))
       (while (and (< i length)
                   (swiper--isearch-same-line-p
-                   (nth i cands)
-                   current))
+                   (swiper--line-at-point (nth i cands))
+                   (swiper--line-at-point current)))
         (cl-incf i))
       (while (and (< i length)
                   (< len ivy-height))
-        (setq s (nth i cands))
+        (setq s (swiper--line-at-point (nth i cands)))
         (unless (swiper--isearch-same-line-p s (car res))
           (push (ivy--format-minibuffer-line s) res)
           (cl-incf len))



reply via email to

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