help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding String to Beginning of Lines


From: tomas
Subject: Re: Adding String to Beginning of Lines
Date: Wed, 11 Nov 2020 15:07:32 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

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" <michael_heerdegen@web.de>
> > To: help-gnu-emacs@gnu.org
> > Subject: Re: Adding String to Beginning of Lines
> >
> > <tomas@tuxteam.de> 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

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]