From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman 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 12:07:58 +0200 Message-ID: <87a6k3siyp.fsf@rub.de> References: <87pmt0bdao.fsf@rub.de> <87r1dfsqj4.fsf@gmx.net> <87ee9fsojd.fsf@rub.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14640"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 23 12:08:52 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 1mTLet-0003gI-9U for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 12:08:51 +0200 Original-Received: from localhost ([::1]:59164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTLer-00028G-9e for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 06:08:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTLe8-00027v-Vg for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:08:05 -0400 Original-Received: from mout.gmx.net ([212.227.15.18]:42491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTLe6-0002ZB-AB for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:08:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=badeba3b8450; t=1632391679; bh=/i1W3K5rsXQ0ribVP2OkH5Ij1bNJcGK4UU39h6h/tGc=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=KtQ4FROERqc4UFQd64mYPveXm5VHvhk6DIXZ7VQfbkXJS/x+8vUTE/zAmJP5GEWcN Vz87gLrBxVhAnsVnCP7SfW3LvHsldwOOk/VsrteuAU1oDAhOH3bPi6dffgTZ0v5rtn DwLmaSEfEGVYFfglIWl/sPgTS8PPZMX/oB017Z6Y= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobelfs ([188.109.192.197]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N3siA-1mtqfv2MIy-00zmwt; Thu, 23 Sep 2021 12:07:59 +0200 In-Reply-To: (Hongyi Zhao's message of "Thu, 23 Sep 2021 17:00:01 +0800") X-Provags-ID: V03:K1:8DiJaaxqm8GZFWrmfVQuQcAVlK7fARs8yrpiScvEYijd3VILeRT lgoPfzj/JW3YVWsSKhEuzzV8xHmCDjDJmxHUqPFBfaPpjRa1hnnarKPfzd9bkWVV93qqm9b FP7S615e2vRIzfVMr+9Al4kpAgBHv8lAYRInWs26j1THne5aahct+CTjno+7Acqn5mXL/vn eFmeMLB9Dfn3oCgxcgurg== X-UI-Out-Filterresults: notjunk:1;V03:K0:o7Rd4CLi19I=:i6QgvfD87rOQEEHmOo40LL WTqvtRWFRK463FZ6Hikfwzltk+PEqQyyXdHgvNpw8sZMlf2bTGzB8qsK4HUD/pFTY6h70xTtQ +8ER3idj7RJaLOw2HuPKP27VubJEpKO/fDQhk9fc1l5zXPsE4sXLxJEVsWdZ1VqdnZOxFiFoN CC9DOnN5bmPWcae39TiZBi7MEyj1sbZvczpoAY/hSQkvVk+qApCoo0ewruJiUTq+FmwYOZSfj 3aF9aRIFeMUiWEKRyk5XGdZtw1Q8Df+9w9tqrsW2DECSi/mWcGVkiPTqZeFUl75PG4qCkB75f Cr/Afby/IKroT4BquUdxkUDwKolPgwjOBEqaR5WAuufzlyYW1VwLEivv2/cgE7RiZ/OJTtuCd fQ7sWV3PU8GL9vd818ojekKf1THbpkB/lnhj77UNYUzdxn/5blo+5vz4HWHjng8Qk0wGjSSdr sX7H0EApyJOMb008D3JYrYjtY4APCCIo4mGYvKyOc4POtPBqg5wew+2qdMOeoJ1oTsAZAXuak mNzY3Xu0qsOLoCsWQCty7Ux0ZRHj8uOcdNZT4d+5ATltRplHbIImw+2fPbr8RMP4F5kXOc71n QaYkHISYOtgumwl6uif9YRV3BQFINuEdWWaK+oBV2qTdZM0Ly7/yjNf4TxjmMTh5CCRTeR5xU Z+QwvNLcEGSb7D7ffXcfLCdxhB1pBRF7u5R9BixmMAozjnFh7Mje8flrkLNXTPKS9LMwLyrR1 AfxUHa6nD3O04Deue9Aw1AJUSsZ5OS6ThWp/lkEMcQ2ptn54JCTxqK7cGtgAIZ19vCc7Wo5M Received-SPF: pass client-ip=212.227.15.18; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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:133175 Archived-At: 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))) Steve Berman