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

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

Re: replace-regexp


From: Tassilo Horn
Subject: Re: replace-regexp
Date: Sun, 09 May 2021 00:03:19 +0200
User-agent: mu4e 1.5.13; emacs 28.0.50

Emanuel Berg via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> writes:

> Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>
>>> (defun md-latex (beg end)
>>>   (interactive "r")
>>>   (save-excursion
>>>     (goto-char beg)
>>>     (while (re-search-forward "_\\(.*\\)_" end t)
>>>       (setq end (copy-marker end t))
>>>       (replace-match "\\\\textit{\\1}") )))
>>
>> Almost: move the (setq end (copy-marker end t)) outside
>> the loop.
>
> What does it do to end that makes it work?

The t in (copy-marker end t) says that the marked should stay after
inserted text, i.e., it automatically moves backwards if text is
inserted before it.  With your original example, end was just a position
(integer) which did not change and the last replacement made point move
beyond it.

Bye,
Tassilo



reply via email to

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