GNU bug report logs - #49842
re-builder restriction to region (lisp/emacs-lisp/re-builder)

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Karthik Chikmagalur <karthikchikmagalur@HIDDEN>; dated Tue, 3 Aug 2021 04:04:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 49842 <at> debbugs.gnu.org:


Received: (at 49842) by debbugs.gnu.org; 4 Aug 2021 07:29:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Aug 04 03:29:54 2021
Received: from localhost ([127.0.0.1]:42525 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mBBLe-0003EM-Bw
	for submit <at> debbugs.gnu.org; Wed, 04 Aug 2021 03:29:54 -0400
Received: from quimby.gnus.org ([95.216.78.240]:37222)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1mBBLd-0003E9-0J
 for 49842 <at> debbugs.gnu.org; Wed, 04 Aug 2021 03:29:53 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org;
 s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:
 References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:
 Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
 Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:
 List-Subscribe:List-Post:List-Owner:List-Archive;
 bh=4bVFKC0NaIZj+Vipub3RCfh1G1p6K0KqiJ8Utu7qThk=; b=fqLmP8Eo0Mv/uJ+ztYB9B9QiTe
 nz5iqRu0CYJMSdaRR/c+b1HVeqotV78caJpgatnK9GukEUxdjjwGrER4TpvyNbUijA6T6LW9ZDHrQ
 2kCiAhrpq7HalaxYJwpREfXcGWqUQSGwZ6EyMSLpbUkFtdqN+hNcyxgRR9ad7RsvZFdo=;
Received: from [84.212.220.105] (helo=elva)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1mBBLU-00057t-MD; Wed, 04 Aug 2021 09:29:46 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Karthik Chikmagalur <karthikchikmagalur@HIDDEN>
Subject: Re: bug#49842: re-builder restriction to region
 (lisp/emacs-lisp/re-builder)
References: <87lf5jqing.fsf@HIDDEN> <877dh23smo.fsf@HIDDEN>
Date: Wed, 04 Aug 2021 09:29:44 +0200
In-Reply-To: <877dh23smo.fsf@HIDDEN> (Karthik Chikmagalur's message of
 "Tue, 03 Aug 2021 18:28:47 -0700")
Message-ID: <874kc5fz13.fsf_-_@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 Content preview:  Karthik Chikmagalur <karthikchikmagalur@HIDDEN> writes:
 > IIRC, the right way to restrict this to the region would be to define >
 a variable to hold the bounds of the region as specified by the user > before
 starting re-builder and re-search-forward inside [...] 
 Content analysis details:   (-2.9 points, 5.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
 [score: 0.0000]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 49842
Cc: 49842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Karthik Chikmagalur <karthikchikmagalur@HIDDEN> writes:

> IIRC, the right way to restrict this to the region would be to define
> a variable to hold the bounds of the region as specified by the user
> before starting re-builder and re-search-forward inside those
> bounds. Perhaps a closure that's tied to the specific re-builder
> session can be used to avoid issues with the value of this variable
> when running multiple simultaneous re-builder sessions.

I'm not very familiar with re-builder.el myself, but I think that sounds
like a promising approach.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#49842; Package emacs. Full text available.

Message received at 49842 <at> debbugs.gnu.org:


Received: (at 49842) by debbugs.gnu.org; 4 Aug 2021 01:29:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 03 21:29:04 2021
Received: from localhost ([127.0.0.1]:41974 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mB5iS-00026l-Iy
	for submit <at> debbugs.gnu.org; Tue, 03 Aug 2021 21:29:04 -0400
Received: from mail-pj1-f50.google.com ([209.85.216.50]:53894)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <karthikchikmagalur@HIDDEN>) id 1mB5iQ-00026A-KF
 for 49842 <at> debbugs.gnu.org; Tue, 03 Aug 2021 21:29:03 -0400
Received: by mail-pj1-f50.google.com with SMTP id j1so722086pjv.3
 for <49842 <at> debbugs.gnu.org>; Tue, 03 Aug 2021 18:29:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version;
 bh=xIKsHFeJJhePn33iqE+ldi93lhVjQb5dZCr1eturFdU=;
 b=qlIDdjvxDcXwUFg0+B51K0OYljg7fHsBHtAJDlVtx7B0twz3uCA7a9blDAIsDPR8w0
 0E1vWvFzTIaGvCcYwSQNEOF0EbETLWu9bzNzdbJBKWTLNAeJeq2DoGRGJEPU8F9i3ETC
 8fCpHANT279BlABI2tesv52PqG9jETmmHgFz5S6ilLJvqFnQDNK1ji06zlXij7mXTzfi
 FKUvvWopnEpkerbzWBBgX0yHU2OWKNg4r74LPIKRntVZEdkcTJv6+ELseoLSmT6iUUKE
 8gKFLdOURJrHTvA/UdqErsbQkzBE0xK5qHhTWdCiWH83WZJVVZljCqGnJX+CDO4TuOeq
 CYXg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version;
 bh=xIKsHFeJJhePn33iqE+ldi93lhVjQb5dZCr1eturFdU=;
 b=Ufv6lOEQTAhvbHu7VQb0CenzoFnio8XEVIQ15Yntien8FCDFGxnnoZPSNJ7NkVIBzy
 Iv6c9Sb5gGzQJZ90GWD93ze+bPApWGrve6TyEVJnv7yNeTZ840yLO2F0s4lbjnukfzFt
 eTTXZlAjnKRfvnq7v0WY8PZeG56zBe65F8EA3DYxAcxYSFqJq00Ph3gB3onPLjFJLp38
 b7trBMcKxgUvYyCp/ElWJTqZ59nXogUz2zIFqUOD2wItsNneL53jJco4dSaj24cnEg80
 AFhz75/wiMcAmKGpUU27SSk3h9DvzK1e03amF/+C34TR/4pz3N4JKaqWXAAi2bZfELqT
 lXjw==
X-Gm-Message-State: AOAM533uvyJ2LkamnCaqstyWwA9Bbzv4TGAmCVvPqGXSO1Zi54hUJr6D
 OtcLkbdJDKzXqtSQU0TzweuyRA8LoM1ksA==
X-Google-Smtp-Source: ABdhPJwnTppth5+h0Tdl/cXjSGZJnuW7u4XVoUsip/QlRRAgijj2fYsUcRMszX5Tx6II4UiFEteL/w==
X-Received: by 2002:a17:90b:2284:: with SMTP id
 kx4mr24987176pjb.202.1628040536306; 
 Tue, 03 Aug 2021 18:28:56 -0700 (PDT)
Received: from localhost (ip72-205-127-227.sb.sd.cox.net. [72.205.127.227])
 by smtp.gmail.com with ESMTPSA id kr6sm4172612pjb.23.2021.08.03.18.28.55
 for <49842 <at> debbugs.gnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 03 Aug 2021 18:28:55 -0700 (PDT)
From: Karthik Chikmagalur <karthikchikmagalur@HIDDEN>
To: 49842 <at> debbugs.gnu.org
Subject: re-builder restriction to region
Date: Tue, 03 Aug 2021 18:28:47 -0700
Message-ID: <877dh23smo.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 49842
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello,

Please disregard this patch. With further testing this does not behave as expected.

re-builder moves the point around in reb-target-buffer with each search, so (region-beginning) has a different meaning every time reb-update-overlays is called. As a result, this fails when, for example, we type in a regexp (in the re-builder buffer), then delete it and type in a new regexp. The new regexp is matched from the location of the first match of the old regexp instead of from the beginning of the region as originally specified by the user.

IIRC, the right way to restrict this to the region would be to define a variable to hold the bounds of the region as specified by the user before starting re-builder and re-search-forward inside those bounds. Perhaps a closure that's tied to the specific re-builder session can be used to avoid issues with the value of this variable when running multiple simultaneous re-builder sessions.

Karthik




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#49842; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 Aug 2021 04:03:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 03 00:03:42 2021
Received: from localhost ([127.0.0.1]:39600 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mAleY-0001n5-3i
	for submit <at> debbugs.gnu.org; Tue, 03 Aug 2021 00:03:42 -0400
Received: from lists.gnu.org ([209.51.188.17]:58656)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <karthikchikmagalur@HIDDEN>) id 1mAleW-0001my-VW
 for submit <at> debbugs.gnu.org; Tue, 03 Aug 2021 00:03:41 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:55108)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <karthikchikmagalur@HIDDEN>)
 id 1mAleW-00018Q-NQ
 for bug-gnu-emacs@HIDDEN; Tue, 03 Aug 2021 00:03:40 -0400
Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:54786)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <karthikchikmagalur@HIDDEN>)
 id 1mAleV-0000w4-2x
 for bug-gnu-emacs@HIDDEN; Tue, 03 Aug 2021 00:03:40 -0400
Received: by mail-pj1-x1030.google.com with SMTP id a8so5000550pjk.4
 for <bug-gnu-emacs@HIDDEN>; Mon, 02 Aug 2021 21:03:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version;
 bh=mwq0tA6JoDe+3JxInZbJDEczSNXRCRb4mjcWR/eYPI8=;
 b=ZNzOOmSDkVbzvwE3kuTWTslUtoIn+PS72dHxnTAN8jPLc3ZSmSwMA5jw9GgeoGCurh
 GIR+m+FadN0Z5Rg+gL6ts9FB2GY0Vogx5fTW+Y4IQJCBteBsM6J+yqN72YdsEk8tovvn
 O2bcNw7sXtDLc/HxwnOx60SlCQteb+WZHz45FaaBKJ27R7YlXUwEx/EAlglrN97aTxtb
 EX7M/pgoJq77N07AZej3HgwZq3z/rL2ScuFDuXa/pOysjX0TpcHshvATt1xYv03khoKz
 Ea46HaD+KW63E2Vg9faw356LkW7M5QgLlr9zHxZ7q8JfSwZ07wgx/HIkHqJgJcw805qJ
 NUhA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version;
 bh=mwq0tA6JoDe+3JxInZbJDEczSNXRCRb4mjcWR/eYPI8=;
 b=um8BRSbdsn5/dJIrQC/fPLuBBZHvr5IUtSTKvQ9EMeWO9fEW2sM6L2v8eQ278s3Cun
 Bqo2YLIlrRPktyRtmncjzSndvimQVCIWBbunZKiEfy3TAgTtfdi+3cAhHYQ/EaeEl841
 CW1MRBrnMlIswGMmQZHciab6L3gpAbk0qjK4dHJTevFZBdb4zshPvBMEkDAuz0M3K2Vd
 vbjwJhsZMYx6ShL1K0hrCYijUUjVXcMPxQjSMKcVXA4YNfmhr+IQ2XLcHChSeD2SC6M4
 rZQCg/dNmSJ99LkY+5BqxYxhpciNmHbXs0Xp+HCoSFqvKCWwI0fDiSBa3y+nWUZooyN9
 BkWQ==
X-Gm-Message-State: AOAM5319HRvk77X6M/Z2pseEPmrzni7+cCI48eWqVAJJw8AA+KRiOOJq
 PJLidBilft5b1VltL9G4wmEUWT5mwDerWw==
X-Google-Smtp-Source: ABdhPJyTAkmz0QTSKQpXutiCzTI8gm8lZOSYqS+UEFQND520h/cmTqAmWhM3RGsCC8VRhA5J+CNFVw==
X-Received: by 2002:a63:e807:: with SMTP id s7mr805787pgh.200.1627963417138;
 Mon, 02 Aug 2021 21:03:37 -0700 (PDT)
Received: from localhost (169-231-132-213.wireless.ucsb.edu. [169.231.132.213])
 by smtp.gmail.com with ESMTPSA id y139sm13163843pfb.107.2021.08.02.21.03.36
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 02 Aug 2021 21:03:36 -0700 (PDT)
From: Karthik Chikmagalur <karthikchikmagalur@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: re-builder restriction to region (lisp/emacs-lisp/re-builder)
Date: Mon, 02 Aug 2021 21:03:31 -0700
Message-ID: <87lf5jqing.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=2607:f8b0:4864:20::1030;
 envelope-from=karthikchikmagalur@HIDDEN; helo=mail-pj1-x1030.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--=-=-=
Content-Type: text/plain

Hello,

The function "reb-update-overlays" (in lisp/emacs-lisp/re-builder.el)
displays matches in the whole of reb-target-buffer starting at
(point-min) even when the region is active. In keeping with the behavior
of commands like query-replace, replace-regexp and query-replace-regexp,
I modified it so that when the region is active re-builder only displays
matches in the active region. It's behavior is unchanged when the region is
inactive.

I think this change makes sense without disrupting the expectations of
re-builder users.

More generally, I think re-builder needs some work:

1. When the user quits re-builder, the point in reb-target-buffer is not
restored correctly.

2. Without an active region, there should be an option to match forward
or backward from reb-target-buffer's point instead of always matching
from (point-min), with the ability to customize the default behavior.

3. re-builder's overlay system (or some modification of it) can be used
by query-replace-regexp to show matches as the user types.

I am waiting to sign the copyright papers from FSF (which I have
applied for) before sending in these larger patches.

Commit log entry:

* lisp/emacs-lisp/re-builder.el (reb-update-overlays): Restrict
  re-builder matches to region when the region is active.
  
Karthik Chikmagalur

--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=re-builder.patch

diff -u emacs-src/lisp/emacs-lisp/re-builder.el emacs-src/lisp/emacs-lisp/re-builder-new.el
--- /lisp/emacs-lisp/re-builder.el	2021-08-02 20:47:39.226669281 -0700
+++ /lisp/emacs-lisp/re-builder-new.el	2021-08-02 20:37:27.442020958 -0700
@@ -642,16 +642,19 @@
 	 (submatches 0)
 	 firstmatch
          here
+         start end
          firstmatch-after-here)
     (with-current-buffer reb-target-buffer
         (setq here
               (if reb-target-window
                   (with-selected-window reb-target-window (window-point))
-                (point)))
+                (point))
+              start (if (region-active-p) (region-beginning) (point-min))
+              end   (if (region-active-p) (region-end) (point-max)))
       (reb-delete-overlays)
-      (goto-char (point-min))
+      (goto-char start)
       (while (and (not (eobp))
-		  (re-search-forward re (point-max) t)
+		  (re-search-forward re end t)
 		  (or (not reb-auto-match-limit)
 		      (< matches reb-auto-match-limit)))
 	(when (and (= 0 (length (match-string 0)))

Diff finished.  Mon Aug  2 20:48:01 2021

--=-=-=--




Acknowledgement sent to Karthik Chikmagalur <karthikchikmagalur@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#49842; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 4 Aug 2021 07:45:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.