On Wed, Nov 11, 2020 at 02:22:44PM +0100, Christopher Dimech wrote: > > > Sent: Wednesday, November 11, 2020 at 12:16 PM > > From: "Michael Heerdegen" > > To: help-gnu-emacs@gnu.org > > Subject: Re: Adding String to Beginning of Lines > > > > writes: > > > > > But watch out: the replacement string (confusingly called `regex' here, > > > others have already pointed that out) might contain special sequences > > > (e.g. "\\&") which have a meaning in this context. > > > > Indeed, an important objection. > > > > I would suggest to avoid using any query-replace at all and rather use > > something like > > > > #+begin_src emacs-lisp > > (save-excursion > > (while (and (<= (point) end) > > (not (eobp))) > > (insert my-string) > > (forward-line +1)) > > (deactivate-mark)) > > #+end_src > > That's what I started doing at the beginning. Should we revert to this > or continue with replace-regexp. Have now removed the confusingly called > `regex' and it is currently called nwltok. If it's always the beginning of line you're inserting at, your first approach seems to make more sense. Something like (beginning-of-line) ; if you aren't already there, see below (insert "foo") should do what you're after. The beginning-of-line isn't necessary if your advance function puts you already there. Note that (beginning-of-line 2) will put you at the beginning of the /next/ line. Cheers - t