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, 08 Jun 2022 19:28:42 +0300 [thread overview]
Message-ID: <86v8tbi0th.fsf@mail.linkov.net> (raw)
In-Reply-To: <87pmjudoqz.fsf@web.de> (Michael Heerdegen's message of "Tue, 31 May 2022 11:40:04 +0200")
[-- Attachment #1: Type: text/plain, Size: 919 bytes --]
>> This works surprisingly well. Maybe there are more corner cases,
>> but something already works with quick tests:
>
> Yes, not bad indeed. Did you find any corner cases?
Below is the patch that works quite well for the most use cases.
But unfortunately, there are still some unsolvable corner cases:
when a file name is e.g. "aaxbbx" and the search regexp is "x$",
then after removing "$", searching for "x" will find the first
occurrence of "x", and will set match-data to it. Later code
that uses string-match can adjust the found position to the
last occurrence of "x". But it can't change match-data
used by isearch. And using a temporary buffer won't help either
to set the real buffer positions in match-data to the last "x".
IOW, no post-processing can help the main search function
to set match-data to the correct place that matches "x$"
in the dired buffer (and file name doesn't always end at eol).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-isearch-search-filenames.patch --]
[-- Type: text/x-diff, Size: 2627 bytes --]
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 4faf9431aa..bb17760598 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3217,7 +3217,17 @@ dired-isearch-search-filenames
(if isearch-forward old (max (1- old) (point-min)))
property)
old))
- end found)
+ end found regexp regexp-^ regexp-$ (i 0))
+ (when isearch-regexp
+ (setq regexp string)
+ (while (string-match "\\(\\^\\|\\\\`\\)\\|\\$\\|\\\\'" string i)
+ (setq i (match-beginning 0))
+ (if (save-match-data (not (subregexp-context-p
+ string (match-beginning 0))))
+ ;; The ^/$ is inside a char-range or escaped or something.
+ (setq i (1+ i))
+ (setq string (replace-match "" t t string))
+ (if (match-beginning 1) (setq regexp-^ t) (setq regexp-$ t)))))
;; Otherwise, try to search for the next property.
(unless beg
(setq beg (if isearch-forward
@@ -3236,6 +3246,29 @@ dired-isearch-search-filenames
(max bound end))
end)
noerror count))
+ ;; Handle ^/$ specially
+ (when (and regexp found)
+ ;; Apply ^/$ regexp on the whole filename field
+ (save-match-data
+ (if (string-match regexp (buffer-substring beg end))
+ ;; FIXME: better to modify previous match-data
+ (setq found (if isearch-forward
+ (+ beg (match-end 0))
+ (- beg (match-end 0))))
+ (setq found nil)))
+ ;; Check ^/$ matches at filename field boundaries
+ (when found
+ (goto-char found)
+ (unless (and (or (not regexp-^)
+ (eq (if isearch-forward beg end) (point-min))
+ (null (get-text-property
+ (1- (if isearch-forward beg end)) property)))
+ (or (not regexp-$)
+ (eq (point) (point-max))
+ (null (get-text-property
+ (point) property))))
+ (setq found nil))))
+ ;; Get the next filename field
(unless found
(setq beg (if isearch-forward
(next-single-property-change end property)
next prev parent reply other threads:[~2022-06-08 16:28 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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86v8tbi0th.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.