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: Wed, 08 Jun 2022 19:28:42 +0300 Organization: LINKOV.NET Message-ID: <86v8tbi0th.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> <86pmlyqbfh.fsf@mail.linkov.net> <87pmjudoqz.fsf@web.de> 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="40575"; 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 Wed Jun 08 18:37:25 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 1nyygO-000APN-Rp for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Jun 2022 18:37:24 +0200 Original-Received: from localhost ([::1]:51770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyygN-0005pg-ME for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Jun 2022 12:37:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyyZI-0000hc-HS for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 12:30:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50159) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyyZH-0004yh-5y for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 12:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nyyZG-0008RS-Tm for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 12:30: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: Wed, 08 Jun 2022 16:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 14013 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 14013-submit@debbugs.gnu.org id=B14013.165470574832341 (code B ref 14013); Wed, 08 Jun 2022 16:30:02 +0000 Original-Received: (at 14013) by debbugs.gnu.org; 8 Jun 2022 16:29:08 +0000 Original-Received: from localhost ([127.0.0.1]:44052 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyyYO-0008PY-GJ for submit@debbugs.gnu.org; Wed, 08 Jun 2022 12:29:08 -0400 Original-Received: from relay1-d.mail.gandi.net ([217.70.183.193]:56703) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyyYM-0008Ol-Ry for 14013@debbugs.gnu.org; Wed, 08 Jun 2022 12:29:07 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 4E5EA24000A; Wed, 8 Jun 2022 16:28:58 +0000 (UTC) In-Reply-To: <87pmjudoqz.fsf@web.de> (Michael Heerdegen's message of "Tue, 31 May 2022 11:40:04 +0200") 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:233983 Archived-At: --=-=-= Content-Type: text/plain >> 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). --=-=-= 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 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) --=-=-=--