unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 14013@debbugs.gnu.org
Subject: bug#14013: 24.3.50; dired-isearch-filenames-regexp is matching text outside filenames
Date: Wed, 15 Jun 2022 19:34:39 +0300	[thread overview]
Message-ID: <86a6ad6i2c.fsf@mail.linkov.net> (raw)
In-Reply-To: <86mtelbua2.fsf@mail.linkov.net> (Juri Linkov's message of "Thu,  09 Jun 2022 20:30:45 +0300")

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

> BTW, do you think that such regexps as ".*" and "^.*$"
> should be supported not only in Dired buffers, but also
> when making replacements in rectangular regions?
> E.g. C-x SPC ... C-M-% .* RET RET should effectively
> clear the region, etc.

After a small refactoring, searching in rectangular regions
is implemented as well:


[-- Attachment #2: isearch-search-fun-in-noncontiguous-region.patch --]
[-- Type: text/x-diff, Size: 4712 bytes --]

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 7650ebcfce..2fd172e75c 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -4455,18 +4518,45 @@ minibuffer-lazy-highlight-setup
         (funcall after-change nil nil nil)))))
 
 \f
+(defun isearch-search-fun-in-noncontiguous-region (search-fun region-bounds)
+  "Return the function that searches inside noncontiguous regions."
+  (apply-partially
+   #'search-within-boundaries
+   search-fun
+   (lambda (pos)
+     (seq-some (lambda (b) (and (>= pos (car b)) (<= pos (cdr b))))
+               region-bounds))
+   (lambda (pos)
+     (let* ((bounds (flatten-list region-bounds))
+            found)
+       (unless isearch-forward
+         (setq bounds (nreverse bounds)))
+       (while (and bounds (not found))
+         (if (if isearch-forward (< pos (car bounds)) (> pos (car bounds)))
+             (setq found (car bounds))
+           (setq bounds (cdr bounds))))
+       found))))
+
 (defun isearch-search-fun-in-text-property (search-fun property)
   "Return the function to search inside text that has the specified PROPERTY.
 The function will limit the search for matches only inside text which has
 this property in the current buffer.
 The argument SEARCH-FUN provides the function to search text, and
 defaults to the value of `isearch-search-fun-default' when nil."
-  (lambda (string &optional bound noerror count)
+  (apply-partially
+   #'search-within-boundaries
+   search-fun
+   (lambda (pos) (get-text-property pos property))
+   (lambda (pos) (if isearch-forward
+                     (next-single-property-change pos property)
+                   (previous-single-property-change pos property)))))
+
+(defun search-within-boundaries ( search-fun get-fun next-fun
+                                  string &optional bound noerror count)
   (let* ((old (point))
          ;; Check if point is already on the property.
-           (beg (when (get-text-property
-                       (if isearch-forward old (max (1- old) (point-min)))
-                       property)
+         (beg (when (funcall get-fun (if isearch-forward old
+                                       (max (1- old) (point-min))))
                 old))
          end found (i 0)
          (subregexp
@@ -4480,30 +4570,23 @@ isearch-search-fun-in-text-property
                        (throw 'subregexp t))))))))
     ;; Otherwise, try to search for the next property.
     (unless beg
-        (setq beg (if isearch-forward
-                      (next-single-property-change old property)
-                    (previous-single-property-change old property)))
+      (setq beg (funcall next-fun old))
       (when beg (goto-char beg)))
     ;; Non-nil `beg' means there are more properties.
     (while (and beg (not found))
       ;; Search for the end of the current property.
-        (setq end (if isearch-forward
-                      (next-single-property-change beg property)
-                    (previous-single-property-change beg property)))
+      (setq end (funcall next-fun beg))
       ;; Handle ^/$ specially by matching in a temporary buffer.
       (if subregexp
           (let* ((prop-beg
                   (if (or (if isearch-forward (bobp) (eobp))
-                            (null (get-text-property
-                                   (+ (point) (if isearch-forward -1 0))
-                                   property)))
+                          (null (funcall get-fun (+ (point)
+                                                    (if isearch-forward -1 0)))))
                       ;; Already at the beginning of the field.
                       beg
                     ;; Get the real beginning of the field when
                     ;; the search was started in the middle.
-                      (if isearch-forward
-                          (previous-single-property-change beg property)
-                        (next-single-property-change beg property))))
+                    (funcall next-fun beg)))
                  (substring (buffer-substring prop-beg end))
                  (offset (if isearch-forward prop-beg end))
                  match-data)
@@ -4532,12 +4615,10 @@ isearch-search-fun-in-text-property
                      noerror count)))
       ;; Get the next text property.
       (unless found
-          (setq beg (if isearch-forward
-                        (next-single-property-change end property)
-                      (previous-single-property-change end property)))
+        (setq beg (funcall next-fun end))
         (when beg (goto-char beg))))
     (unless found (goto-char old))
-      found)))
+    found))
 
 \f
 (defun isearch-resume (string regexp word forward message case-fold)

  reply	other threads:[~2022-06-15 16:34 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-20 23:39 bug#14013: 24.3.50; dired-isearch-filenames-regexp is matching text outside filenames Michael Heerdegen
2013-03-20 23:59 ` Juri Linkov
2013-03-21  0:35   ` Michael Heerdegen
2013-03-21  0:45     ` Juri Linkov
2013-03-21  2:24       ` Michael Heerdegen
2013-03-21 23:03         ` Juri Linkov
2013-03-22  0:30           ` Michael Heerdegen
2013-03-22  0:45             ` Juri Linkov
2013-03-22  1:28               ` Michael Heerdegen
2013-03-23  0:49                 ` Juri Linkov
2013-03-22  1:59           ` Stefan Monnier
2013-03-23  0:44             ` Juri Linkov
2013-04-19 21:06               ` Michael Heerdegen
2013-04-20  1:49                 ` Stefan Monnier
2013-05-27 20:50                 ` Juri Linkov
2013-05-27 23:00                   ` Michael Heerdegen
2013-05-27 23:45                     ` Juri Linkov
2022-02-13 18:59             ` Juri Linkov
2022-02-14  1:13               ` Michael Heerdegen
2022-02-14  7:41                 ` Juri Linkov
2022-02-14 12:59                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-16  1:11                     ` Michael Heerdegen
2022-02-16  3:57                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-15  3:12                   ` Michael Heerdegen
2022-02-15 19:25                     ` Juri Linkov
2022-02-16  1:23                       ` Michael Heerdegen
2022-02-16  3:36                         ` bug#14013: [External] : " Drew Adams
2022-02-16 18:11                         ` Juri Linkov
2022-02-21  1:16                           ` Michael Heerdegen
2022-02-16  0:56                   ` Michael Heerdegen
2022-02-22 17:02                     ` Juri Linkov
2022-02-22 20:21                       ` Michael Heerdegen
2022-02-22 22:27                         ` Michael Heerdegen
2022-02-23  8:13                           ` Juri Linkov
2022-02-23 18:53                     ` Juri Linkov
2022-02-24  0:30                       ` Michael Heerdegen
2022-02-26  4:45                         ` Michael Heerdegen
2022-03-10 19:28                           ` Juri Linkov
2022-03-28 18:01                           ` Juri Linkov
2022-04-01  2:18                             ` Michael Heerdegen
2022-04-01 16:39                               ` Juri Linkov
2022-04-03 18:05                                 ` Juri Linkov
2022-04-04 19:40                                   ` Juri Linkov
2022-05-31  9:40                                   ` Michael Heerdegen
2022-06-08 16:28                                     ` Juri Linkov
2022-06-10 17:17                                     ` Juri Linkov
2022-06-12 16:46                                       ` Juri Linkov
2022-05-31  8:33                                 ` Michael Heerdegen
2022-06-09 17:30                                   ` Juri Linkov
2022-06-15 16:34                                     ` Juri Linkov [this message]
2022-06-30 17:45                                     ` Juri Linkov
2022-07-03 17:34                                       ` Michael Heerdegen
2022-07-03 18:23                                         ` Juri Linkov
2022-07-03 18:43                                       ` Michael Heerdegen
2022-07-03 19:49                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-08 17:59                                         ` Juri Linkov
2022-06-10 16:44                                   ` Juri Linkov
2022-06-14 16:31                                     ` Juri Linkov
2023-06-02  1:34                       ` Michael Heerdegen
2023-06-02  6:28                         ` Juri Linkov
2023-06-02 22:29                           ` Michael Heerdegen
2023-06-04  7:36                             ` Juri Linkov
2023-06-06  0:27                               ` Michael Heerdegen
2021-04-20  0:33         ` Michael Heerdegen
2021-04-20 19:22           ` Juri Linkov
2021-04-22  0:21             ` Michael Heerdegen
2021-04-22 21:51               ` Juri Linkov
2021-04-22 22:17                 ` bug#14013: [External] : " Drew Adams
2021-04-22 23:04                 ` Michael Heerdegen
2021-04-22 23:16                   ` Michael Heerdegen
2021-04-23 16:52                     ` Juri Linkov
2022-02-08 19:32           ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86a6ad6i2c.fsf@mail.linkov.net \
    --to=juri@jurta.org \
    --cc=14013@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).