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: Christopher Dimech
Subject: Re: Adding String to Beginning of Lines
Date: Wed, 11 Nov 2020 18:20:01 +0100

Have put the following, bet the insert is not progressing to the
last line of the selected region.  I started my selected region
on the first character of 'RFrec-field-nwltok' and ended my
selected region on the last character of 'insert'.

>
> (defun RFrec-field-nwltok (beg end nwltok)
>    "rec-field-nwltok adds a newline token for a recutils field."
>    (interactive
>       (list (region-beginning)
>             (region-end)
>             (read-string "rec-field-nwltok: " nil nil ";; + ") ))
>    (save-excursion
>       (let (rz lpos)
>          (setq rz (region-end))
>          (goto-char (region-beginning))
>          (beginning-of-line)
>
>          (while (and (< (point) rz)
>                      (not (eobp)))
>             (insert nwltok)
>             (forward-line 1)) )
>       (deactivate-mark) ))
>

> 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
>
> > Cheers
>
> Ebenso!
>
>
> Regards,
>
> Michael.
>
>
>



reply via email to

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