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: Stephen Berman
Subject: Re: Emacs: adding 1 to every number made of 2 digits inside a marked region.
Date: Thu, 23 Sep 2021 15:29:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

On Thu, 23 Sep 2021 20:58:49 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:

> 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

If by selecting the data block you mean: (with emacs -Q) putting point
before the start of the block, typing `C-SPC', then moving point to the
end of the block: that works for me, so I don't know why it doesn't work
you.

Steve Berman



reply via email to

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