[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
- replace-regexp, Emanuel Berg, 2021/05/06
- Re: replace-regexp, Tassilo Horn, 2021/05/07
- Re: replace-regexp, Emanuel Berg, 2021/05/07
- Re: replace-regexp, Emanuel Berg, 2021/05/07
- Re: replace-regexp, Emanuel Berg, 2021/05/07
- Re: replace-regexp, Yuri Khan, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp,
Tassilo Horn <=
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- RE: [External] : Re: replace-regexp, Drew Adams, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08