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

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

[nongnu] elpa/iedit ac51555341 282/301: New feature: ignore hidden occur


From: ELPA Syncer
Subject: [nongnu] elpa/iedit ac51555341 282/301: New feature: ignore hidden occurrences
Date: Mon, 10 Jan 2022 22:59:10 -0500 (EST)

branch: elpa/iedit
commit ac51555341163ed74423fd1aca88a56579dce10b
Author: Victor Ren <victorhge@gmail.com>
Commit: Victor <victorhge@gmail.com>

    New feature: ignore hidden occurrences
    
    Ignore hidden matches if `search-invisible' is nil.
    New mode function `iedit-toggle-search-invisible'.
    
    The behavior is borrowed from 'isearch'.
---
 iedit-lib.el   | 45 +++++++++++++++++++++++++++++++++++----------
 iedit-tests.el | 26 +++++++++++++++++++++++++-
 iedit.el       | 30 +++++++++++++++++++++++++++++-
 3 files changed, 89 insertions(+), 12 deletions(-)

diff --git a/iedit-lib.el b/iedit-lib.el
index 52c7f5b999..1c388e49a7 100755
--- a/iedit-lib.el
+++ b/iedit-lib.el
@@ -3,7 +3,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2021-01-06 11:23:22 Victor Ren>
+;; Time-stamp: <2021-01-13 22:27:53 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous rectangle refactoring
 ;; Version: 0.9.9.9
@@ -130,6 +130,17 @@ If no-nil, matching is case sensitive.  If nil and 
`case-replace'
 is no-nil, iedit try to preserve the case pattern of each
 occurrence.")
 
+(defvar iedit-search-invisible search-invisible
+  "search-invisible while matching.
+Either nil, t, or 'open.  'open means the same as t except that
+opens hidden overlays. ")
+
+(defvar iedit-lib-skip-invisible-count 0
+  "This is buffer local varible which is the number of skipped invisible 
occurrence. ")
+
+(defvar iedit-lib-skip-filtered-count 0
+  "This is buffer local varible which is the number of filtered occurrence. ")
+
 (defvar iedit-hiding nil
   "This is buffer local variable which indicates whether buffer lines are 
hided. ")
 
@@ -208,6 +219,8 @@ It replaces `inhibit-modification-hooks' which prevents 
calling
 (make-variable-buffer-local 'iedit-occurrence-context-lines)
 (make-variable-buffer-local 'iedit-occurrence-index)
 (make-variable-buffer-local 'iedit-lib-quit-func)
+(make-variable-buffer-local 'iedit-lib-skip-invisible-count)
+(make-variable-buffer-local 'iedit-lib-skip-filtered-count)
 
 (defconst iedit-occurrence-overlay-name 'iedit-occurrence-overlay-name)
 (defconst iedit-invisible-overlay-name 'iedit-invisible-overlay-name)
@@ -314,10 +327,13 @@ Return the number of occurrences."
   (setq iedit-aborting nil)
   (setq iedit-occurrences-overlays nil)
   (setq iedit-read-only-occurrences-overlays nil)
+  (setq iedit-lib-skip-invisible-count 0)
+  (setq iedit-lib-skip-filtered-count 0)
   ;; Find and record each occurrence's markers and add the overlay to the 
occurrences
   (let ((counter 0)
         (case-fold-search (not iedit-case-sensitive))
-       (length 0))
+               (search-invisible iedit-search-invisible)
+               (length 0))
     (save-excursion
       (save-window-excursion
         (goto-char end)
@@ -327,15 +343,22 @@ Return the number of occurrences."
         (while (re-search-forward occurrence-regexp end t)
           (let ((beginning (match-beginning 0))
                 (ending (match-end 0)))
-           (if (and (> length 0) (/= (- ending beginning) length))
-               (throw 'not-same-length 'not-same-length)
-             (setq length (- ending beginning)))
-            (if (text-property-not-all beginning ending 'read-only nil)
-                (push (iedit-make-read-only-occurrence-overlay beginning 
ending)
-                      iedit-read-only-occurrences-overlays)
+                       (if (and (> length 0) (/= (- ending beginning) length))
+                               (throw 'not-same-length 'not-same-length)
+                         (setq length (- ending beginning)))
+                       (cond
+             ((text-property-not-all beginning ending 'read-only nil)
+              (push (iedit-make-read-only-occurrence-overlay beginning ending)
+                    iedit-read-only-occurrences-overlays))
+                        ((not (or (eq search-invisible t)
+                                          (not (isearch-range-invisible 
beginning ending))))
+                         (setq iedit-lib-skip-invisible-count (1+ 
iedit-lib-skip-invisible-count)))
+                        ((not (funcall isearch-filter-predicate beginning 
ending))
+                         (setq iedit-lib-skip-filtered-count (1+ 
iedit-lib-skip-filtered-count)))
+                        (t
               (push (iedit-make-occurrence-overlay beginning ending)
-                    iedit-occurrences-overlays))
-            (setq counter (1+ counter))))))
+                    iedit-occurrences-overlays)
+                         (setq counter (1+ counter))))))))
     (iedit-update-index)
     counter))
 
@@ -420,6 +443,8 @@ there are."
   "Clean up occurrence overlay, invisible overlay and local variables."
   (remove-hook 'post-command-hook 'iedit-update-occurrences-2 t)
   (remove-overlays nil nil iedit-occurrence-overlay-name t)
+  ;; Close overlays opened by `isearch-range-invisible'
+  (isearch-clean-overlays)
   (iedit-show-all)
   (remove-hook 'before-revert-hook iedit-lib-quit-func t)
   (remove-hook 'kbd-macro-termination-hook iedit-lib-quit-func t)
diff --git a/iedit-tests.el b/iedit-tests.el
index 569cbd202b..e79f65bebc 100644
--- a/iedit-tests.el
+++ b/iedit-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2020-11-21 21:09:39 Victor Ren>
+;; Time-stamp: <2021-01-13 23:06:19 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Version: 0.9.9.9
 ;; X-URL: https://github.com/victorhge/iedit
@@ -441,6 +441,30 @@ fob")))))
      (iedit-toggle-case-sensitive)
      (should (= 1 (length iedit-occurrences-overlays))))))
 
+(ert-deftest iedit-toggle-search-invisible-test ()
+  (with-iedit-test-fixture
+"foo
+* foo
+** foo"
+   (lambda ()
+     (iedit-mode) ; turn off iedit-mode
+        (outline-mode)
+        (forward-line 1)
+        (call-interactively 'outline-hide-subtree)
+        (setq iedit-search-invisible t)
+        (goto-char 1)
+        (iedit-mode)
+     (should (= 3 (length iedit-occurrences-overlays)))
+        (should (= 0 iedit-lib-skip-invisible-count))
+     (iedit-toggle-search-invisible)
+     (should (= 2 (length iedit-occurrences-overlays)))
+        (should (null iedit-search-invisible))
+        (should (= 1 iedit-lib-skip-invisible-count))
+        (iedit-toggle-search-invisible)
+        (should (= 3 (length iedit-occurrences-overlays)))
+        (should (= 0 iedit-lib-skip-invisible-count))
+        (should (eq 'open iedit-search-invisible)))))
+
 (ert-deftest iedit-case-preserve-test ()
   (with-iedit-test-fixture
 "foo
diff --git a/iedit.el b/iedit.el
index e2f0c4a39e..edc1a8e212 100644
--- a/iedit.el
+++ b/iedit.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2010 - 2019, 2020 Victor Ren
 
-;; Time-stamp: <2021-01-06 11:14:51 Victor Ren>
+;; Time-stamp: <2021-01-13 22:39:04 Victor Ren>
 ;; Author: Victor Ren <victorhge@gmail.com>
 ;; Keywords: occurrence region simultaneous refactoring
 ;; Version: 0.9.9.9
@@ -300,6 +300,7 @@ This is like `describe-bindings', but displays only Iedit 
keys."
     (define-key map (kbd "M-n") 'iedit-expand-down-to-occurrence)
     (define-key map (kbd "M-G") 'iedit-apply-global-modification)
     (define-key map (kbd "M-C") 'iedit-toggle-case-sensitive)
+       (define-key map (kbd "M-S") 'iedit-toggle-search-invisible)
     map)
   "Keymap used within overlays in Iedit mode.")
 
@@ -795,6 +796,33 @@ prefix, bring the top of the region back down one 
occurrence."
                (iedit-printable occurrence-regexp))
       (force-mode-line-update))))
 
+(defun iedit-toggle-search-invisible ()
+  "Toggle search-invisible matching occurrences. "
+  (interactive)
+  (setq iedit-search-invisible
+        (if iedit-search-invisible
+            nil
+                 (or search-invisible 'open)))
+  (if iedit-buffering
+      (iedit-stop-buffering))
+  (let ((occurrence-string (iedit-current-occurrence-string)))
+  (when occurrence-string
+    (remove-overlays nil nil iedit-occurrence-overlay-name t)
+    (iedit-show-all)
+       (isearch-clean-overlays)
+    (let* ((occurrence-regexp (iedit-regexp-quote occurrence-string))
+           (begin (car iedit-initial-region))
+           (end (cadr iedit-initial-region))
+           (counter (iedit-make-occurrences-overlays occurrence-regexp begin 
end)))
+      (message "iedit %s. %d matches for \"%s\""
+               (if iedit-search-invisible
+                   "matching invisible"
+                 "matching visible")
+               counter
+               (iedit-printable occurrence-regexp))
+         (setq iedit-last-occurrence-local occurrence-string)
+      (force-mode-line-update)))))
+
 (provide 'iedit)
 
 ;;; iedit.el ends here



reply via email to

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