[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Emacs: adding 1 to every number made of 2 digits inside a marked reg
From: |
Hongyi Zhao |
Subject: |
Re: Emacs: adding 1 to every number made of 2 digits inside a marked region. |
Date: |
Thu, 23 Sep 2021 20:58:49 +0800 |
On Thu, Sep 23, 2021 at 6:23 PM Stephen Berman <stephen.berman@gmx.net> wrote:
[...]
> > Tried but it does nothing.
>
> Since you're now searching backwards, are you sure you had point *after*
> the numbers? I.e., if this is the *scratch* buffer:
>
> -------------------------------------------------------
> ;; some 35
> ;; word 31
> ;; another 39
> ;; thing 60
> ;; to 40
> ;; say 11
> ;; here 48
>
> (while (re-search-backward "[[:digit:]]\\{2\\}" nil t)
> (let ((x (match-string 0))
> (pt (point)))
> (delete-char 2)
> (insert (format "%d" (1+ (string-to-number x))))
> (goto-char pt)))
> -------------------------------------------------------
>
> then put the cursor at the end of the sexp and type `C-x C-e'.
This way works. But the invalid method I tried before is as follows:
Select the data block and put the point at the end of it in scratch,
then `M-:' the above code in minibuffer. With this method, I only the
following message generated in minibuffer:
Mark set
nil
Best, HZ
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., (continued)
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region.,
Hongyi Zhao <=
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Stephen Berman, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/23
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Emanuel Berg, 2021/09/22
- Re: Emacs: adding 1 to every number made of 2 digits inside a marked region., Hongyi Zhao, 2021/09/23