diff options
| author | Juri Linkov | 2023-11-20 19:57:57 +0200 |
|---|---|---|
| committer | Juri Linkov | 2023-11-20 19:57:57 +0200 |
| commit | 9d292262f55cd016a1a59f4d4ef31446bb2ba9c6 (patch) | |
| tree | f7def64147b0769a09687741c4df871e8d1a5a2f | |
| parent | 5024ee1ad18904bc0a0e7a8f740164157649af5e (diff) | |
| download | emacs-9d292262f55cd016a1a59f4d4ef31446bb2ba9c6.tar.gz emacs-9d292262f55cd016a1a59f4d4ef31446bb2ba9c6.zip | |
Improve invisibility handling in isearch-lazy-highlight (bug#40808)
* lisp/isearch.el (isearch-lazy-highlight-invisible): New variable.
(isearch-lazy-highlight-new-loop, isearch-lazy-highlight-search)
(isearch-lazy-highlight-match, isearch-lazy-highlight-buffer-update): Use it.
* lisp/replace.el (replace-highlight): Let-bind isearch-invisible
to search-invisible.
* test/lisp/isearch-tests.el (isearch--test-invisible): New test.
| -rw-r--r-- | lisp/isearch.el | 18 | ||||
| -rw-r--r-- | lisp/replace.el | 1 | ||||
| -rw-r--r-- | test/lisp/isearch-tests.el | 151 |
3 files changed, 165 insertions, 5 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el index 4d231fba469..4672440bdff 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el | |||
| @@ -4054,6 +4054,7 @@ since they have special meaning in a regexp." | |||
| 4054 | (defvar isearch-lazy-highlight-point-max nil) | 4054 | (defvar isearch-lazy-highlight-point-max nil) |
| 4055 | (defvar isearch-lazy-highlight-buffer nil) | 4055 | (defvar isearch-lazy-highlight-buffer nil) |
| 4056 | (defvar isearch-lazy-highlight-case-fold-search nil) | 4056 | (defvar isearch-lazy-highlight-case-fold-search nil) |
| 4057 | (defvar isearch-lazy-highlight-invisible nil) | ||
| 4057 | (defvar isearch-lazy-highlight-regexp nil) | 4058 | (defvar isearch-lazy-highlight-regexp nil) |
| 4058 | (defvar isearch-lazy-highlight-lax-whitespace nil) | 4059 | (defvar isearch-lazy-highlight-lax-whitespace nil) |
| 4059 | (defvar isearch-lazy-highlight-regexp-lax-whitespace nil) | 4060 | (defvar isearch-lazy-highlight-regexp-lax-whitespace nil) |
| @@ -4099,6 +4100,8 @@ by other Emacs features." | |||
| 4099 | isearch-lazy-highlight-window-group)) | 4100 | isearch-lazy-highlight-window-group)) |
| 4100 | (not (eq isearch-lazy-highlight-case-fold-search | 4101 | (not (eq isearch-lazy-highlight-case-fold-search |
| 4101 | isearch-case-fold-search)) | 4102 | isearch-case-fold-search)) |
| 4103 | (not (eq isearch-lazy-highlight-invisible | ||
| 4104 | isearch-invisible)) | ||
| 4102 | (not (eq isearch-lazy-highlight-regexp | 4105 | (not (eq isearch-lazy-highlight-regexp |
| 4103 | isearch-regexp)) | 4106 | isearch-regexp)) |
| 4104 | (not (eq isearch-lazy-highlight-regexp-function | 4107 | (not (eq isearch-lazy-highlight-regexp-function |
| @@ -4177,6 +4180,7 @@ by other Emacs features." | |||
| 4177 | isearch-lazy-highlight-wrapped nil | 4180 | isearch-lazy-highlight-wrapped nil |
| 4178 | isearch-lazy-highlight-last-string isearch-string | 4181 | isearch-lazy-highlight-last-string isearch-string |
| 4179 | isearch-lazy-highlight-case-fold-search isearch-case-fold-search | 4182 | isearch-lazy-highlight-case-fold-search isearch-case-fold-search |
| 4183 | isearch-lazy-highlight-invisible isearch-invisible | ||
| 4180 | isearch-lazy-highlight-regexp isearch-regexp | 4184 | isearch-lazy-highlight-regexp isearch-regexp |
| 4181 | isearch-lazy-highlight-lax-whitespace isearch-lax-whitespace | 4185 | isearch-lazy-highlight-lax-whitespace isearch-lax-whitespace |
| 4182 | isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace | 4186 | isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace |
| @@ -4226,8 +4230,10 @@ Attempt to do the search exactly the way the pending Isearch would." | |||
| 4226 | (isearch-forward isearch-lazy-highlight-forward) | 4230 | (isearch-forward isearch-lazy-highlight-forward) |
| 4227 | ;; Count all invisible matches, but highlight only | 4231 | ;; Count all invisible matches, but highlight only |
| 4228 | ;; matches that can be opened by visiting them later | 4232 | ;; matches that can be opened by visiting them later |
| 4229 | (search-invisible (or (not (null isearch-lazy-count)) | 4233 | (search-invisible |
| 4230 | 'can-be-opened)) | 4234 | (or (not (null isearch-lazy-count)) |
| 4235 | (and (eq isearch-lazy-highlight-invisible 'open) | ||
| 4236 | 'can-be-opened))) | ||
| 4231 | (retry t) | 4237 | (retry t) |
| 4232 | (success nil)) | 4238 | (success nil)) |
| 4233 | ;; Use a loop like in `isearch-search'. | 4239 | ;; Use a loop like in `isearch-search'. |
| @@ -4247,7 +4253,9 @@ Attempt to do the search exactly the way the pending Isearch would." | |||
| 4247 | (when (or (not isearch-lazy-count) | 4253 | (when (or (not isearch-lazy-count) |
| 4248 | ;; Recheck the match that possibly was intended | 4254 | ;; Recheck the match that possibly was intended |
| 4249 | ;; for counting only, but not for highlighting | 4255 | ;; for counting only, but not for highlighting |
| 4250 | (let ((search-invisible 'can-be-opened)) | 4256 | (let ((search-invisible |
| 4257 | (and (eq isearch-lazy-highlight-invisible 'open) | ||
| 4258 | 'can-be-opened))) | ||
| 4251 | (funcall isearch-filter-predicate mb me))) | 4259 | (funcall isearch-filter-predicate mb me))) |
| 4252 | (let ((ov (make-overlay mb me))) | 4260 | (let ((ov (make-overlay mb me))) |
| 4253 | (push ov isearch-lazy-highlight-overlays) | 4261 | (push ov isearch-lazy-highlight-overlays) |
| @@ -4396,9 +4404,9 @@ Attempt to do the search exactly the way the pending Isearch would." | |||
| 4396 | ;; value `open' since then lazy-highlight | 4404 | ;; value `open' since then lazy-highlight |
| 4397 | ;; will open all overlays with matches. | 4405 | ;; will open all overlays with matches. |
| 4398 | (if (not (let ((search-invisible | 4406 | (if (not (let ((search-invisible |
| 4399 | (if (eq search-invisible 'open) | 4407 | (if (eq isearch-lazy-highlight-invisible 'open) |
| 4400 | 'can-be-opened | 4408 | 'can-be-opened |
| 4401 | search-invisible))) | 4409 | isearch-lazy-highlight-invisible))) |
| 4402 | (funcall isearch-filter-predicate mb me))) | 4410 | (funcall isearch-filter-predicate mb me))) |
| 4403 | (setq isearch-lazy-count-invisible | 4411 | (setq isearch-lazy-count-invisible |
| 4404 | (1+ (or isearch-lazy-count-invisible 0))) | 4412 | (1+ (or isearch-lazy-count-invisible 0))) |
diff --git a/lisp/replace.el b/lisp/replace.el index ac677db2feb..ff7ca1145b8 100644 --- a/lisp/replace.el +++ b/lisp/replace.el | |||
| @@ -2755,6 +2755,7 @@ to a regexp that is actually used for the search.") | |||
| 2755 | (isearch-regexp-lax-whitespace | 2755 | (isearch-regexp-lax-whitespace |
| 2756 | replace-regexp-lax-whitespace) | 2756 | replace-regexp-lax-whitespace) |
| 2757 | (isearch-case-fold-search case-fold) | 2757 | (isearch-case-fold-search case-fold) |
| 2758 | (isearch-invisible search-invisible) | ||
| 2758 | (isearch-forward (not backward)) | 2759 | (isearch-forward (not backward)) |
| 2759 | (isearch-other-end match-beg) | 2760 | (isearch-other-end match-beg) |
| 2760 | (isearch-error nil) | 2761 | (isearch-error nil) |
diff --git a/test/lisp/isearch-tests.el b/test/lisp/isearch-tests.el index e71f0a5785f..693f15336f2 100644 --- a/test/lisp/isearch-tests.el +++ b/test/lisp/isearch-tests.el | |||
| @@ -39,6 +39,157 @@ | |||
| 39 | (isearch-done)) | 39 | (isearch-done)) |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | ;; Search invisible. | ||
| 43 | |||
| 44 | (declare-function outline-hide-sublevels "outline") | ||
| 45 | |||
| 46 | (ert-deftest isearch--test-invisible () | ||
| 47 | (require 'outline) | ||
| 48 | (with-temp-buffer | ||
| 49 | (set-window-buffer nil (current-buffer)) | ||
| 50 | (insert "\n1\n" | ||
| 51 | (propertize "2" 'invisible t) | ||
| 52 | (propertize "3" 'inhibit-isearch t) | ||
| 53 | "\n* h\n4\n\n") | ||
| 54 | (outline-mode) | ||
| 55 | (outline-hide-sublevels 1) | ||
| 56 | (goto-char (point-min)) | ||
| 57 | |||
| 58 | (let ((isearch-lazy-count nil) | ||
| 59 | (search-invisible t) | ||
| 60 | (inhibit-message t)) | ||
| 61 | |||
| 62 | (isearch-forward-regexp nil 1) | ||
| 63 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 64 | (should (eq (point) 3)) | ||
| 65 | |||
| 66 | (isearch-lazy-highlight-start) | ||
| 67 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 68 | '(2))) | ||
| 69 | |||
| 70 | (isearch-repeat-forward) | ||
| 71 | (should (eq (point) 5)) | ||
| 72 | (should (get-char-property 4 'invisible)) | ||
| 73 | (isearch-repeat-forward) | ||
| 74 | (should (eq (point) 12)) | ||
| 75 | (should (get-char-property 11 'invisible)) | ||
| 76 | |||
| 77 | (goto-char isearch-opoint) | ||
| 78 | (isearch-done t) | ||
| 79 | |||
| 80 | (isearch-forward-regexp nil 1) | ||
| 81 | (setq isearch-invisible nil) ;; isearch-toggle-invisible | ||
| 82 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 83 | |||
| 84 | (isearch-lazy-highlight-start) | ||
| 85 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 86 | '(2))) | ||
| 87 | |||
| 88 | (goto-char isearch-opoint) | ||
| 89 | (isearch-done t) | ||
| 90 | |||
| 91 | (isearch-forward-regexp nil 1) | ||
| 92 | (setq isearch-invisible 'open) ;; isearch-toggle-invisible | ||
| 93 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 94 | (should (eq (point) 3)) | ||
| 95 | |||
| 96 | (isearch-lazy-highlight-start) | ||
| 97 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 98 | '(2 11))) | ||
| 99 | |||
| 100 | (let ((isearch-hide-immediately t)) | ||
| 101 | (isearch-repeat-forward) | ||
| 102 | (should (eq (point) 12)) | ||
| 103 | (should-not (get-char-property 11 'invisible)) | ||
| 104 | (isearch-delete-char) | ||
| 105 | (should (get-char-property 11 'invisible))) | ||
| 106 | |||
| 107 | (let ((isearch-hide-immediately nil)) | ||
| 108 | (isearch-repeat-forward) | ||
| 109 | (should (eq (point) 12)) | ||
| 110 | (should-not (get-char-property 11 'invisible)) | ||
| 111 | (isearch-delete-char) | ||
| 112 | (should-not (get-char-property 11 'invisible))) | ||
| 113 | |||
| 114 | (goto-char isearch-opoint) | ||
| 115 | (isearch-done t) | ||
| 116 | (isearch-clean-overlays) | ||
| 117 | (should (get-char-property 11 'invisible))) | ||
| 118 | |||
| 119 | (let ((isearch-lazy-count t) | ||
| 120 | (search-invisible t) | ||
| 121 | (inhibit-message t)) | ||
| 122 | |||
| 123 | (isearch-forward-regexp nil 1) | ||
| 124 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 125 | (should (eq (point) 3)) | ||
| 126 | |||
| 127 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 128 | (isearch-lazy-highlight-start) | ||
| 129 | (isearch-lazy-highlight-buffer-update) | ||
| 130 | (should (eq isearch-lazy-count-invisible nil)) | ||
| 131 | (should (eq isearch-lazy-count-total 3)) | ||
| 132 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 133 | '(2))) | ||
| 134 | |||
| 135 | (isearch-repeat-forward) | ||
| 136 | (should (eq (point) 5)) | ||
| 137 | (should (get-char-property 4 'invisible)) | ||
| 138 | (isearch-repeat-forward) | ||
| 139 | (should (eq (point) 12)) | ||
| 140 | (should (get-char-property 11 'invisible)) | ||
| 141 | |||
| 142 | (goto-char isearch-opoint) | ||
| 143 | (isearch-done t) | ||
| 144 | |||
| 145 | (isearch-forward-regexp nil 1) | ||
| 146 | (setq isearch-invisible nil) ;; isearch-toggle-invisible | ||
| 147 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 148 | |||
| 149 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 150 | (isearch-lazy-highlight-start) | ||
| 151 | (isearch-lazy-highlight-buffer-update) | ||
| 152 | (should (eq isearch-lazy-count-invisible 2)) | ||
| 153 | (should (eq isearch-lazy-count-total 1)) | ||
| 154 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 155 | '(2))) | ||
| 156 | |||
| 157 | (goto-char isearch-opoint) | ||
| 158 | (isearch-done t) | ||
| 159 | |||
| 160 | (isearch-forward-regexp nil 1) | ||
| 161 | (setq isearch-invisible 'open) ;; isearch-toggle-invisible | ||
| 162 | (isearch-process-search-string "[0-9]" "[0-9]") | ||
| 163 | (should (eq (point) 3)) | ||
| 164 | |||
| 165 | (setq isearch-lazy-count-invisible nil isearch-lazy-count-total nil) | ||
| 166 | (isearch-lazy-highlight-start) | ||
| 167 | (isearch-lazy-highlight-buffer-update) | ||
| 168 | (should (eq isearch-lazy-count-invisible 1)) | ||
| 169 | (should (eq isearch-lazy-count-total 2)) | ||
| 170 | (should (equal (seq-uniq (mapcar #'overlay-start isearch-lazy-highlight-overlays)) | ||
| 171 | '(2 11))) | ||
| 172 | |||
| 173 | (let ((isearch-hide-immediately t)) | ||
| 174 | (isearch-repeat-forward) | ||
| 175 | (should (eq (point) 12)) | ||
| 176 | (should-not (get-char-property 11 'invisible)) | ||
| 177 | (isearch-delete-char) | ||
| 178 | (should (get-char-property 11 'invisible))) | ||
| 179 | |||
| 180 | (let ((isearch-hide-immediately nil)) | ||
| 181 | (isearch-repeat-forward) | ||
| 182 | (should (eq (point) 12)) | ||
| 183 | (should-not (get-char-property 11 'invisible)) | ||
| 184 | (isearch-delete-char) | ||
| 185 | (should-not (get-char-property 11 'invisible))) | ||
| 186 | |||
| 187 | (goto-char isearch-opoint) | ||
| 188 | (isearch-done t) | ||
| 189 | (isearch-clean-overlays) | ||
| 190 | (should (get-char-property 11 'invisible))))) | ||
| 191 | |||
| 192 | |||
| 42 | ;; Search functions. | 193 | ;; Search functions. |
| 43 | 194 | ||
| 44 | (defun isearch--test-search-within-boundaries (pairs) | 195 | (defun isearch--test-search-within-boundaries (pairs) |