Hi Folks,
The patch below fixes the following issues with the mg(1) editor:
The first two parts fix:
* an infinite loop with (replace-regexp "^" ""). replace-regexp does
not advance to the next line.
* the replacement of all occurances of ^pat on a line by replace-regexp. For
example, (replace-regexp "^#" "") will delete every occurance of
"#" in the line "#############################". This is unexpected
(at least to me) and is not the behaviour of emacs.
The third part prevents an infinite loop when (replace-regexp "^.*$" "")
operates on an empty line.
I'd be very grateful if someone could apply this patch (or a more
acceptable version) to the source tree.
--- re_search.c.orig Wed Aug 27 14:42:51 2025
+++ re_search.c Wed Oct 29 10:48:22 2025
@@ -191,6 +191,8 @@
ewprintf("<SP> replace, [.] rep-end, <DEL> don't, [!]
repl rest <ESC> quit");
goto retry;
}
+ if (re_pat[0] == '^' && news[0] == '\0')
+ curwp->w_doto = curwp->w_dotp->l_used;
}
stopsearch:
@@ -224,6 +226,8 @@
plen = regex_match[0].rm_eo - regex_match[0].rm_so;
if (re_doreplace((RSIZE)plen, news) == FALSE)
return (FALSE);
+ if (re_pat[0] == '^' && news[0] == '\0')
+ curwp->w_doto = curwp->w_dotp->l_used;
rcnt++;
}
@@ -342,10 +346,9 @@
if (tbo == clp->l_used)
/*
* Don't start matching past end of line -- must move to
- * beginning of next line, unless line is empty or at
- * end of file.
+ * beginning of next line, unless at end of file.
*/
- if (clp != curbp->b_headp && llength(clp) != 0) {
+ if (clp != curbp->b_headp) {
clp = lforw(clp);
tdotline++;
tbo = 0;
Best Regards,
Mark
--
Mark Willson
[email protected]