From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#14013: 24.3.50; dired-isearch-filenames-regexp is matching text outside filenames Date: Sun, 03 Apr 2022 21:05:07 +0300 Organization: LINKOV.NET Message-ID: <86pmlyqbfh.fsf@mail.linkov.net> References: <87li9hk5e5.fsf@web.de> <87wqt1vd0o.fsf@mail.jurta.org> <87d2ut4mji.fsf@web.de> <87620lvavl.fsf@mail.jurta.org> <87zjxxsd6c.fsf@web.de> <87vc8ke4os.fsf@mail.jurta.org> <86zgmutwx9.fsf@mail.linkov.net> <87o83ab67d.fsf@web.de> <86r185520f.fsf@mail.linkov.net> <87czjn39yf.fsf@web.de> <86y2215rbn.fsf@mail.linkov.net> <87ee3tjecw.fsf@web.de> <87pmnap75m.fsf@web.de> <86mtha7y8w.fsf@mail.linkov.net> <877d8935sf.fsf@web.de> <861qygal8h.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14981"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Stefan Monnier , 14013@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Apr 03 20:20:27 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nb4pt-0003jZ-RO for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Apr 2022 20:20:25 +0200 Original-Received: from localhost ([::1]:40776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nb4ps-0002Ss-BJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 03 Apr 2022 14:20:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nb4pX-0002Sh-83 for bug-gnu-emacs@gnu.org; Sun, 03 Apr 2022 14:20:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nb4pW-0003RC-I7 for bug-gnu-emacs@gnu.org; Sun, 03 Apr 2022 14:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nb4pW-0001kF-BG for bug-gnu-emacs@gnu.org; Sun, 03 Apr 2022 14:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Apr 2022 18:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14013 X-GNU-PR-Package: emacs Original-Received: via spool by 14013-submit@debbugs.gnu.org id=B14013.16490099976691 (code B ref 14013); Sun, 03 Apr 2022 18:20:02 +0000 Original-Received: (at 14013) by debbugs.gnu.org; 3 Apr 2022 18:19:57 +0000 Original-Received: from localhost ([127.0.0.1]:49493 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nb4pR-0001jq-9u for submit@debbugs.gnu.org; Sun, 03 Apr 2022 14:19:57 -0400 Original-Received: from relay11.mail.gandi.net ([217.70.178.231]:46637) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nb4pO-0001jb-DP for 14013@debbugs.gnu.org; Sun, 03 Apr 2022 14:19:55 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 71E8A100002; Sun, 3 Apr 2022 18:19:46 +0000 (UTC) In-Reply-To: <861qygal8h.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 01 Apr 2022 19:39:10 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:229380 Archived-At: --=-=-= Content-Type: text/plain >> I wonder if it is realistic to use a temporary helper buffer to >> implement ^. > > Good idea. Maybe even not a buffer, but just a string. > Are there any differences between buffer matching and string matching? > > Then first we could remove ^ from the search regexp, and when it finds > something, then get the found buffer-substring using text properties > and match it with the original regexp that contains ^. This works surprisingly well. Maybe there are more corner cases, but something already works with quick tests: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-isearch-search-filenames.patch diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index c49e4e91d8..0832ea1ddb 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -3202,7 +3202,16 @@ dired-isearch-search-filenames (if isearch-forward old (max (1- old) (point-min))) property) old)) - end found) + end found regexp (i 0)) + (when isearch-regexp + (setq regexp string) + (while (string-match "\\^\\|\\$\\|\\\\`\\|\\\\'" string i) + (setq i (- (match-end 0) (length (match-string 0 string)))) + (if (save-match-data (not (subregexp-context-p + string (match-beginning 0)))) + ;; The ^/$ is inside a char-range or escaped or something. + nil + (setq string (replace-match "" t t string))))) ;; Otherwise, try to search for the next property. (unless beg (setq beg (if isearch-forward @@ -3221,6 +3230,9 @@ dired-isearch-search-filenames (max bound end)) end) noerror count)) + (when (and regexp (not (string-match-p + regexp (buffer-substring beg end)))) + (setq found nil)) (unless found (setq beg (if isearch-forward (next-single-property-change end property) --=-=-=--