From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help 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 Message-ID: References: <87pmt0bdao.fsf@rub.de> <87r1dfsqj4.fsf@gmx.net> <87ee9fsojd.fsf@rub.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40491"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Stephen Berman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 23 11:02:12 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTKcO-000AIX-Az for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 11:02:12 +0200 Original-Received: from localhost ([::1]:41596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTKcM-00065g-CK for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 05:02:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKaW-0005Ul-UQ for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 05:00:16 -0400 Original-Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:34319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTKaV-0004Gl-49 for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 05:00:16 -0400 Original-Received: by mail-lf1-x131.google.com with SMTP id g41so23696096lfv.1 for ; Thu, 23 Sep 2021 02:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wM6IO0tqaROV6NbPVQt33pyxLQHo8s5MJWSlFSplWLw=; b=BZpugf7Vodhu/qhf8ue3CGYJRl2BEJ5ExWV7zDoLDr474MZPPXkUI7gGXi1AmeXo8r YjiUwYwdE1Stwr7cbzFKaIwVZIzgG/OIQvs9BYzAX02Tw1KJfSLeCFt/f00S8dH8kUbI 5CiIOHOzzaysakOtlJLRfo2SB1qdhxT3dKpdveMy7WjjYsSAXknSbolBae3koC+sKm1F zQXY6edjPqSf6XLCr4dCr28y/+ehqF34So1CMHz7bR2oJaGSSMjfu9MA7sHtZ2L279Gz 8xBGxOBEhP6i3e8pc+78fiVfFWiC54HgGWhj6Xefyl2Hz1mARixqvo+FQRO2FRFoyYz2 5nXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wM6IO0tqaROV6NbPVQt33pyxLQHo8s5MJWSlFSplWLw=; b=yJjIbwRIMazyHcw7iU3q0MuKBlY0iTtjGlhPHKJ9i4Pns9jTF4RoMp8ZL4F8IzEkl3 5vdB6RqlaUzzrYqizpO8nXcE/KCybS2MM5wYOlAbN+5C1DSWsLelgYyXYlQUHaM0Uy9f 2vCZnN5MTfHuwNMLFIF6iDC88C+lsT1KF86CNKKgyZ/hCT+BTIU/Fa7DV3eKDvxn8F3Z UBmJbdN+/sG3+yfsmG9Njg0XItlOO/FDiRHDafWw0L+jUjmfwZfoOFT2lzt4oi19XJZz sJ0K7dECEwlK8aiqxKjR4liLOCIIrEl/WkHeVaqrrs1fa8JCdvQko12cOVopVQyvOLGp 13Tg== X-Gm-Message-State: AOAM530vZyJaCT5M6W+uxSsh4Gz/oysz9Ets2tP/lgoU4gsvtV9Yhluf EMP+DSAb3b4CjmXLE3EHiXlMfaPvlaYAltZwBewnUeX2BO9nEggY X-Google-Smtp-Source: ABdhPJyaBq2LN2Dfc0/1xUp4BOgTxNWXrKH+PnI8QQbav8gsTmC64Bd+66SgWRVT2VUzg4vOr/idufwy89VeGzL1bZs= X-Received: by 2002:a05:651c:1250:: with SMTP id h16mr4108161ljh.68.1632387613458; Thu, 23 Sep 2021 02:00:13 -0700 (PDT) In-Reply-To: <87ee9fsojd.fsf@rub.de> Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=hongyi.zhao@gmail.com; helo=mail-lf1-x131.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133169 Archived-At: On Thu, Sep 23, 2021 at 4:07 PM Stephen Berman wrote: > > On Thu, 23 Sep 2021 15:54:19 +0800 Hongyi Zhao wrote: > > > On Thu, Sep 23, 2021 at 3:24 PM Stephen Berman wrote: > >> > >> On Thu, 23 Sep 2021 08:23:26 +0800 Hongyi Zhao wrote: > >> > >> > On Thu, Sep 23, 2021 at 3:50 AM Stephen Berman wrote: > >> >> > >> >> On Wed, 22 Sep 2021 22:28:28 +0800 Hongyi Zhao 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