Index | Thread | Search

From:
mark.willson@hydrus.org.uk
Subject:
mg: replace-regexp won't if dot is on empty line [PATCH]
To:
tech@openbsd.org
Date:
Sun, 01 Mar 2026 15:40:45 +0000

Download raw body.

Thread
  • mark.willson@hydrus.org.uk:

    mg: replace-regexp won't if dot is on empty line [PATCH]

Hi,

If replace-regexp is invoked when the dot is on an empty line, that line
is not subject to replacement, even when it should be, e.g.
(replace-regexp "^" "#").

The following patch fixes the issue, by abusing the value in curwp->w_doto.
It's the least intrusive modification I could come up with.

Best Regards,
Mark

--- re_search.c.orig	Sun Mar  1 10:34:56 2026
+++ re_search.c	Sun Mar  1 11:43:45 2026
@@ -145,6 +145,10 @@
 	    EFNUL | EFNEW | EFCR, re_pat) == NULL)
 		return (ABORT);
 	ewprintf("Query replacing %s with %s:", re_pat, news);
+	
+	/* If dot on empty line, suppress line forward in re_forwsrch */
+	if (curwp->w_doto == 0 && curwp->w_dotp->l_used == 0)
+		curwp->w_doto = -1;
 
 	/*
 	 * Search forward repeatedly, checking each time whether to insert
@@ -222,6 +226,9 @@
 	    EFNUL | EFNEW | EFCR, re_pat) == NULL)
                 return (ABORT);
 
+	/* If dot on empty line, suppress line forward in re_forwsrch */
+	if (curwp->w_doto == 0 && curwp->w_dotp->l_used == 0)
+		curwp->w_doto = -1;
 	while (re_forwsrch() == TRUE) {
 		plen = regex_match[0].rm_eo - regex_match[0].rm_so;
 		if (re_doreplace((RSIZE)plen, news) == FALSE)
@@ -353,6 +360,9 @@
 			tdotline++;
 			tbo = 0;
 		}
+	if (tbo < 0) 
+		/* line forward was suppressed */
+		tbo = 0;
 	/*
 	 * Note this loop does not process the last line, but this editor
 	 * always makes the last line empty so this is good.