unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Michael Heerdegen <michael_heerdegen@web.de>, 14013@debbugs.gnu.org
Subject: bug#14013: 24.3.50; dired-isearch-filenames-regexp is matching text outside filenames
Date: Sun, 13 Feb 2022 20:59:30 +0200	[thread overview]
Message-ID: <86zgmutwx9.fsf@mail.linkov.net> (raw)
In-Reply-To: <jwvvc8kurq1.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 21 Mar 2013 21:59:52 -0400")

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

> Why not (add-function :around (local isearch-search-fun-function)
>                       #'dired--isearch-filenames)
> and then
>
>    (defun dired--isearch-filenames (iiff &rest args)
>      (let ((fun (apply iiff args)))
>        (lambda (&rest args)
>          (unless (get-text-property (point) 'dired-filename)
>            (if isearch-forward
>    	       (goto-char (or (next-single-property-change
>                                (point) 'dired-filename)
>                               (point-max)))
>              (goto-char (or (previous-single-property-change
>                             (point) 'dired-filename)
>                         (point-min)))))
>          (apply fun args))))

After a short delay, this has been implemented now:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-isearch-search-filenames.patch --]
[-- Type: text/x-diff, Size: 4282 bytes --]

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 41c45b4e51..f1d0f9e225 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3140,11 +3140,11 @@ dired-isearch-filenames-mode
 When off, it uses the original predicate."
   :lighter nil
   (if dired-isearch-filenames-mode
-      (add-function :before-while (local 'isearch-filter-predicate)
-                    #'dired-isearch-filter-filenames
+      (add-function :around (local 'isearch-search-fun-function)
+                    #'dired-isearch-search-filenames
                     '((isearch-message-prefix . "filename ")))
-    (remove-function (local 'isearch-filter-predicate)
-                     #'dired-isearch-filter-filenames))
+    (remove-function (local 'isearch-search-fun-function)
+                     #'dired-isearch-search-filenames))
   (when isearch-mode
     (setq isearch-success t isearch-adjusted t)
     (isearch-update)))
@@ -3168,12 +3168,34 @@ dired-isearch-filenames-end
   (unless isearch-suspended
     (kill-local-variable 'dired-isearch-filenames)))
 
-(defun dired-isearch-filter-filenames (beg end)
+(defun dired-isearch-search-filenames (orig-fun)
   "Test whether some part of the current search match is inside a file name.
 This function returns non-nil if some part of the text between BEG and END
 is part of a file name (i.e., has the text property `dired-filename')."
-  (text-property-not-all (min beg end) (max beg end)
-			 'dired-filename nil))
+  (let ((search-fun (funcall orig-fun)))
+    (lambda (string &optional bound noerror count)
+      (let ((beg (and (get-text-property (point) 'dired-filename) (point)))
+            end found)
+        (unless beg
+          (setq beg (if isearch-forward
+                        (next-single-property-change (point) 'dired-filename)
+                      (previous-single-property-change (point) 'dired-filename)))
+          (when beg (goto-char beg)))
+        (while (and beg (not found))
+          (setq end (if isearch-forward
+                        (next-single-property-change beg 'dired-filename)
+                      (previous-single-property-change beg 'dired-filename)))
+          (setq found (funcall search-fun string
+                               (if isearch-forward
+                                   (min (or bound (point-max)) end)
+                                 (max (or bound (point-max)) end))
+                               noerror count))
+          (unless found
+            (setq beg (if isearch-forward
+                          (next-single-property-change end 'dired-filename)
+                        (previous-single-property-change end 'dired-filename)))
+            (when beg (goto-char beg))))
+        found))))
 
 ;;;###autoload
 (defun dired-isearch-filenames ()
diff --git a/lisp/wdired.el b/lisp/wdired.el
index ab3b91bbe5..573e125bc8 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -217,6 +217,7 @@ wdired-mode
   (error "This mode can be enabled only by `wdired-change-to-wdired-mode'"))
 (put 'wdired-mode 'mode-class 'special)
 
+(autoload 'dired-isearch-search-filenames "dired-aux")
 
 ;;;###autoload
 (defun wdired-change-to-wdired-mode ()
@@ -238,8 +239,9 @@ wdired-change-to-wdired-mode
   (setq-local wdired--old-point (point))
   (wdired--set-permission-bounds)
   (setq-local query-replace-skip-read-only t)
-  (add-function :after-while (local 'isearch-filter-predicate)
-                #'wdired-isearch-filter-read-only)
+  (add-function :around (local 'isearch-search-fun-function)
+                #'dired-isearch-search-filenames)
+  (setq-local replace-re-search-function #'dired-isearch-search-filenames)
   (use-local-map wdired-mode-map)
   (force-mode-line-update)
   (setq buffer-read-only nil)
@@ -438,8 +440,9 @@ wdired-change-to-dired-mode
     (remove-text-properties
      (point-min) (point-max)
      '(front-sticky nil rear-nonsticky nil read-only nil keymap nil)))
-  (remove-function (local 'isearch-filter-predicate)
-                   #'wdired-isearch-filter-read-only)
+  (remove-function (local 'isearch-search-fun-function)
+                   #'dired-isearch-search-filenames)
+  (kill-local-variable 'replace-re-search-function)
   (use-local-map dired-mode-map)
   (force-mode-line-update)
   (setq buffer-read-only t)

  parent reply	other threads:[~2022-02-13 18:59 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 [this message]
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
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=86zgmutwx9.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).