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 18:13:08 +0800 Message-ID: References: <87pmt0bdao.fsf@rub.de> <87r1dfsqj4.fsf@gmx.net> <87ee9fsojd.fsf@rub.de> <87a6k3siyp.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="40334"; 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 12:14:15 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 1mTLk5-000ALs-To for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 12:14:13 +0200 Original-Received: from localhost ([::1]:37804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTLk4-0006vN-FY for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 06:14:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTLjI-0006v0-Jt for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:13:27 -0400 Original-Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]:42764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTLjF-00073y-O2 for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:13:24 -0400 Original-Received: by mail-qk1-x729.google.com with SMTP id t4so20023451qkb.9 for ; Thu, 23 Sep 2021 03:13:20 -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=vL2C+kZOqhR8v+HWNOBqQh4U69vC4KjM01Un5gvPyV4=; b=K07m8CQCJHiNYC2PmDIM1YgBjtFbkZwV9S22FCfrDnTjaEkYMoyWUDmCtakuLrPWqz 1uQir155PxUe9yCVE39EZSqAHW+8ExVFeysPQgs2pqRuBT+++AgJmHqb5BqDv4NSTtvU nl6g1e9B/3meXtzCDoFttA+x0oi+7hRYFljfSjgN2IdjyL1qXspPUEt+4T21jH0hH7qJ hVaER56B8QakXnJFRQNjmouX8d7zNd+8nlr83riEAvstx1murL+v6bpScg7592A7KwTq SpQ8p6tXNE1wuydA1gBjrKMfCot8GT5r2DHa5PSBg7gsw7WwCmYesF11yXXGp4goPEs1 v9EA== 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=vL2C+kZOqhR8v+HWNOBqQh4U69vC4KjM01Un5gvPyV4=; b=zphLCGg8QDsha/PwXWKCiba1YWBJvk9phaSLitJ3mRXe55NK4DCHY67MDL+yQV7F9V rVWhKYzidlwzje5WzRSmZwsI/z4Tn8NaSe4ff1NaICBSbNGT70NengPQGx+gz5KcMbKH rLR+ldUTroUfBZyMWZj2xnYcrolIqJKa9LamZJgLWeXXzXer3bSoU83ayUMvpqOtaaP7 +VS4cN5M4jXhmL4d2GH3KkcxLaB3NC3oflZ9WZih5IQzCeIB7MObDnw68wLiV9MXYARs +7BOuq2NTz1pC8ChGqai1D4c/c+ZI7cnCXdk0aHrMqV0OmcXkiBSZBzD+bql8QmxS0yP MbEA== X-Gm-Message-State: AOAM5321g4p/fid8PXZdjM3uGp2aOBZNLSFLezj2RmIvze7aecBHjz+1 x0PS1KG3IghVMSD2or9pz6DGEoGjjaPSM+wsa/M= X-Google-Smtp-Source: ABdhPJwyPnvjt89CXz8xxLQvQ8BCUfsnHa0o1f5tfSNRzBaWeQanDQqdqhP/RgnjhkSAbO19MXGqS0B6M76C+Vt6/XA= X-Received: by 2002:a25:1584:: with SMTP id 126mr4788692ybv.126.1632391999682; Thu, 23 Sep 2021 03:13:19 -0700 (PDT) In-Reply-To: <87a6k3siyp.fsf@rub.de> Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=hongyi.zhao@gmail.com; helo=mail-qk1-x729.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:133177 Archived-At: On Thu, Sep 23, 2021 at 6:08 PM Stephen Berman wrote: > > On Thu, 23 Sep 2021 17:00:01 +0800 Hongyi Zhao wrote: > > > On Thu, Sep 23, 2021 at 4:07 PM Stephen Berman wrote: > [...] > >> 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? > > Since you're now searching backwards, you need to delete forwards to > retain the position of the numbers and you need to make sure point is in > front of the number that was just incremented before continuing the loop: > > (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))) Tried but it does nothing. HZ