all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Emacs: adding 1 to every number made of 2 digits inside a marked region.
Date: Thu, 23 Sep 2021 17:00:01 +0800	[thread overview]
Message-ID: <CAGP6POKmfMjmCrk89Eg-uXUnw_nW5w5Ovd+H+qmg2o_GRW9yDw@mail.gmail.com> (raw)
In-Reply-To: <87ee9fsojd.fsf@rub.de>

On Thu, Sep 23, 2021 at 4:07 PM Stephen Berman <stephen.berman@gmx.net> wrote:
>
> On Thu, 23 Sep 2021 15:54:19 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> > On Thu, Sep 23, 2021 at 3:24 PM Stephen Berman <stephen.berman@gmx.net> wrote:
> >>
> >> On Thu, 23 Sep 2021 08:23:26 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >>
> >> > On Thu, Sep 23, 2021 at 3:50 AM Stephen Berman <stephen.berman@gmx.net> wrote:
> >> >>
> >> >> On Wed, 22 Sep 2021 22:28:28 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> >> >>
> >> >> > Today, I stumbled on this interesting discussion here [1]:
> >> >> >
> >> >> > --------------------
> >> >> > Imagine I've got the following in a text file opened under Emacs:
> >> >> >
> >> >> > some    34
> >> >> > word    30
> >> >> > another 38
> >> >> > thing   59
> >> >> > to      39
> >> >> > say     10
> >> >> > here    47
> >> >> >
> >> >> > and I want to turn into this, adding 1 to every number made of 2 digits:
> >> >> >
> >> >> > some    35
> >> >> > word    31
> >> >> > another 39
> >> >> > thing   60
> >> >> > to      40
> >> >> > say     11
> >> >> > here    48
> >> >> > --------------------
> >> [...]
> >> > This one does nothing:
> >> >
> >> > (while (re-search-forward "\\<[0-9][0-9]\\>" nil t) (let ((x
> >> > (match-string 0))) (delete-backward-char 2) (insert (format "%d" (1+
> >> > (string-to-number x))))))
> >>
> >> It works for me.  How exactly did you use it?
> >
> > Mark set the following in scratch buffer:
> >
> > some    34
> > word    30
> >
> > M-: (while (re-search-forward "[[:digit:]]\\{2\\}" nil t) (let ((x
> >  (match-string 0))) (delete-backward-char 2) (insert (format "%d" (1+
> >  (string-to-number x)))))) RET
> >
> > Please see the screenshot of the running results on my machine in the
> > attachment.
>
> In your first screenshot it looks like point in *scratch* is after the
> number 30 when you evaluate the while-sexp.  Make sure point is before
> 34 and then it should work.

Exactly. Thank you for pointing this out. Then I do the following
testing in the scratch buffer:

some    30
word    31 *

*  This is the position of point.

M-:
(while (re-search-backward "[[:digit:]]\\{2\\}" nil t) (let ((x
 (match-string 0))) (delete-backward-char 2) (insert (format "%d" (1+
 (string-to-number x))))))

Then I obtained the following in scratch:

;; This buffer is for
tex100999897969594939291908988878685848382818079787776757473727170696867666564636261605958575655545352515049484746454443424140393837363534333231

Any hints for this strange result?

Best, HZ



  reply	other threads:[~2021-09-23  9:00 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 14:28 Emacs: adding 1 to every number made of 2 digits inside a marked region Hongyi Zhao
2021-09-22 19:50 ` Stephen Berman
2021-09-22 21:04   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  0:23   ` Hongyi Zhao
2021-09-23  7:24     ` Stephen Berman
2021-09-23  7:54       ` Hongyi Zhao
2021-09-23  8:07         ` Stephen Berman
2021-09-23  9:00           ` Hongyi Zhao [this message]
2021-09-23 10:07             ` Stephen Berman
2021-09-23 10:13               ` Hongyi Zhao
2021-09-23 10:23                 ` Stephen Berman
2021-09-23 12:58                   ` Hongyi Zhao
2021-09-23 13:29                     ` Stephen Berman
2021-09-23 14:25                       ` Hongyi Zhao
2021-09-22 20:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  0:42   ` Hongyi Zhao
2021-09-23  0:46     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  0:56       ` Hongyi Zhao
2021-09-23  2:06         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  2:12           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  0:57     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23  8:02   ` Hongyi Zhao
2021-09-23  8:37 ` Andreas Röhler
2021-09-23  9:05   ` Hongyi Zhao
2021-09-23  9:58   ` Hongyi Zhao
2021-09-23 10:10     ` Gregory Heytings
2021-09-23 10:17       ` Hongyi Zhao
2021-09-23 13:08         ` Gregory Heytings
2021-09-23 11:59     ` Andreas Röhler
2021-09-23 13:14       ` Hongyi Zhao
2021-09-23 13:51         ` Andreas Röhler
2021-09-23 14:23           ` Hongyi Zhao
2021-09-23  9:26 ` Gregory Heytings
2021-09-23  9:53   ` Hongyi Zhao
2021-09-23 10:02     ` Gregory Heytings
2021-09-23 14:13     ` [External] : " Drew Adams
2021-09-23 23:50       ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-24  0:23         ` Drew Adams
2021-09-24  2:34           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-24  3:01             ` Drew Adams
2021-09-24  7:25         ` Gregory Heytings
2021-09-24  7:32           ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-23 11:50 ` Andreas Röhler
2021-09-26 22:54 ` Michael Heerdegen
2021-09-26 23:50   ` Arthur Miller
2021-09-27  1:02   ` Arthur Miller
2021-09-27  1:22     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-27  5:57       ` Hongyi Zhao
2021-09-28  1:32         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-27 10:59       ` Arthur Miller
2021-09-28  1:34         ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-09-28  1:51           ` Arthur Miller
2021-09-27  1:03   ` Arthur Miller
2021-09-27 14:08     ` Arthur Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGP6POKmfMjmCrk89Eg-uXUnw_nW5w5Ovd+H+qmg2o_GRW9yDw@mail.gmail.com \
    --to=hongyi.zhao@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=stephen.berman@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.