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

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

[elpa] master d260c48 322/399: swiper.el: Obey search-invisible


From: Oleh Krehel
Subject: [elpa] master d260c48 322/399: swiper.el: Obey search-invisible
Date: Sat, 20 Jul 2019 14:57:49 -0400 (EDT)

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

    swiper.el: Obey search-invisible
    
    When `search-invisible' is nil, `swiper' and `swiper-isearch' will not
    match hidden text (e.g. hidden Org outlines).
    
    Fixes #1739
---
 swiper.el | 58 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 24 deletions(-)

diff --git a/swiper.el b/swiper.el
index 0ee0a9f..7c645c2 100644
--- a/swiper.el
+++ b/swiper.el
@@ -497,7 +497,7 @@ numbers; replaces calculating the width from buffer line 
count."
                               (1+ (floor (log n-lines 10)))))
       (setq swiper--format-spec
             (format "%%-%dd " swiper--width))
-      (let ((line-number 0)
+      (let ((line-number 1)
             (advancer (if swiper-use-visual-line
                           (lambda (arg) (line-move arg t))
                         #'forward-line))
@@ -506,18 +506,20 @@ numbers; replaces calculating the width from buffer line 
count."
           (goto-char (point-min))
           (swiper-font-lock-ensure)
           (while (< (point) (point-max))
-            (let ((str (swiper--line)))
-              (setq str (ivy-cleanup-string str))
-              (let ((line-number-str
-                     (format swiper--format-spec (cl-incf line-number))))
-                (if swiper-include-line-number-in-search
-                    (setq str (concat line-number-str str))
+            (when (swiper-match-usable-p)
+              (let ((str (swiper--line)))
+                (setq str (ivy-cleanup-string str))
+                (let ((line-number-str
+                       (format swiper--format-spec line-number)))
+                  (if swiper-include-line-number-in-search
+                      (setq str (concat line-number-str str))
+                    (put-text-property
+                     0 1 'display line-number-str str))
                   (put-text-property
-                   0 1 'display line-number-str str))
-                (put-text-property
-                 0 1 'swiper-line-number line-number-str str))
-              (push str candidates))
-            (funcall advancer 1))
+                   0 1 'swiper-line-number line-number-str str))
+                (push str candidates)))
+            (funcall advancer 1)
+            (cl-incf line-number))
           (nreverse candidates))))))
 
 (defvar swiper--opoint 1
@@ -728,7 +730,7 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
   (setq swiper-invocation-face
         (plist-get (text-properties-at (point)) 'face))
   (let ((preselect
-         (if swiper-use-visual-line
+         (if (or swiper-use-visual-line (null search-invisible))
              (count-screen-lines
               (point-min)
               (save-excursion (beginning-of-visual-line) (point)))
@@ -1267,6 +1269,13 @@ come back to the same place as when \"a\" was initially 
entered.")
   (with-ivy-window
     (swiper--isearch-function str)))
 
+(defun swiper-match-usable-p ()
+  (or search-invisible
+      (not (cl-find-if
+            (lambda (ov)
+              (invisible-p (overlay-get ov 'invisible)))
+            (overlays-at (point))))))
+
 (defun swiper--isearch-function (str)
   (let* ((case-fold-search (ivy--case-fold-p str))
          (re-full (funcall ivy--regex-function str))
@@ -1282,17 +1291,18 @@ come back to the same place as when \"a\" was initially 
entered.")
         (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 ((pos (if swiper-goto-start-of-match
-                           (match-beginning 0)
-                         (point))))
-              (push pos cands))))
+            (when (swiper-match-usable-p)
+              (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 ((pos (if swiper-goto-start-of-match
+                             (match-beginning 0)
+                           (point))))
+                (push pos cands)))))
         (setq ivy--old-re re)
         (when idx-found
           (ivy-set-index idx-found))



reply via email to

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