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, 15 Jun 2022 19:34:39 +0300 Organization: LINKOV.NET Message-ID: <86a6ad6i2c.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> <87ilpm2jan.fsf@web.de> <86mtelbua2.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="4281"; 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 15 18:55:13 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 1o1WIT-0000wf-IV for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Jun 2022 18:55:13 +0200 Original-Received: from localhost ([::1]:56892 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o1WIQ-0001m5-On for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Jun 2022 12:55:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o1W0s-00011e-23 for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2022 12:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45798) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o1W0r-00053D-OB for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2022 12:37:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o1W0r-0006zE-MI for bug-gnu-emacs@gnu.org; Wed, 15 Jun 2022 12:37:01 -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, 15 Jun 2022 16:37:01 +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.165531098226806 (code B ref 14013); Wed, 15 Jun 2022 16:37:01 +0000 Original-Received: (at 14013) by debbugs.gnu.org; 15 Jun 2022 16:36:22 +0000 Original-Received: from localhost ([127.0.0.1]:39695 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o1W0D-0006yH-Pg for submit@debbugs.gnu.org; Wed, 15 Jun 2022 12:36:22 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:41121) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o1W0B-0006xz-KZ for 14013@debbugs.gnu.org; Wed, 15 Jun 2022 12:36:20 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8FEC0200005; Wed, 15 Jun 2022 16:36:11 +0000 (UTC) In-Reply-To: <86mtelbua2.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 09 Jun 2022 20:30:45 +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:234598 Archived-At: --=-=-= Content-Type: text/plain > 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: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=isearch-search-fun-in-noncontiguous-region.patch Content-Transfer-Encoding: 8bit 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))))) +(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)) (defun isearch-resume (string regexp word forward message case-fold) --=-=-=--