all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#49842: re-builder restriction to region (lisp/emacs-lisp/re-builder)
@ 2021-08-03  4:03 Karthik Chikmagalur
  2021-08-04  1:28 ` bug#49842: re-builder restriction to region Karthik Chikmagalur
  0 siblings, 1 reply; 7+ messages in thread
From: Karthik Chikmagalur @ 2021-08-03  4:03 UTC (permalink / raw)
  To: 49842

[-- Attachment #1: Type: text/plain, Size: 1312 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: re-builder.patch --]
[-- Type: text/x-patch, Size: 1094 bytes --]

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-19 19:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03  4:03 bug#49842: re-builder restriction to region (lisp/emacs-lisp/re-builder) Karthik Chikmagalur
2021-08-04  1:28 ` bug#49842: re-builder restriction to region Karthik Chikmagalur
2021-08-04  7:29   ` bug#49842: re-builder restriction to region (lisp/emacs-lisp/re-builder) Lars Ingebrigtsen
2021-08-04 20:59     ` Karthik Chikmagalur
2021-08-05 10:57       ` Lars Ingebrigtsen
2022-08-22 11:01       ` Lars Ingebrigtsen
2022-09-19 19:22         ` Lars Ingebrigtsen

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.