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

[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: Mon, 27 Sep 2021 13:57:41 +0800

On Mon, Sep 27, 2021 at 9:22 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Arthur Miller wrote:
>
> > | some    | 34 |  |
> > | word    | 30 |  |
> > | another | 38 |  |
> > | thing   | 59 |  |
> > | to      | 39 |  |
> > | say     | 10 |  |
> > | here    | 47 |  |

I'm still not so clear about the above method, especially, must I add
all the vertical bars to my original data for doing this operation and
then remove them again?

>
> Her you go:
>
> (defun inc-all (&optional beg end)
>   (interactive (when (use-region-p)
>                  (list (region-beginning) (region-end)) ))
>   (let ((bg (or beg (point-min)))
>         (ed (or end (point-max))) )
>     (save-mark-and-excursion
>       (goto-char bg)
>       (while (re-search-forward "[[:digit:]]\\{2\\}" ed t)
>         (replace-match
>          (format "%d" (1+ (string-to-number (match-string 0)))) )))))

Again, must the above code depend on vertical bars/lines in the data?

HZ



reply via email to

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