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:23:12 +0200 Message-ID: <875yursi9b.fsf@rub.de> 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 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7164"; 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:23:48 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 1mTLtK-0001eK-Ui for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 12:23:46 +0200 Original-Received: from localhost ([::1]:41022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTLtI-0001QQ-Ad for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 06:23:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTLst-0001Pv-Dg for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:23:20 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:44283) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTLsq-0007Dn-6r for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 06:23:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=badeba3b8450; t=1632392593; bh=eT6RKtoevtpewHQJzXnom3yt1ipO7hP6gh5kyqcwDro=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=AbrDRpQcEnwnMpD/HxiyouM1F/4cpeUA0psS3X+ihLJgVaZFx0qN7PmQYY43CA7vT meKKgSz+fwbeK5BwawSN6rY2ezpqGjVlXc62EEIQUcJApazzGNGjJae9qeZkXKREAN F3y85FDARlk0r2j7eJ893OBcS3yDad7zCx8SAGb4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobelfs ([188.109.192.197]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M42nY-1mTLsn2sDI-0007YV; Thu, 23 Sep 2021 12:23:13 +0200 In-Reply-To: (Hongyi Zhao's message of "Thu, 23 Sep 2021 18:13:08 +0800") X-Provags-ID: V03:K1:JYesIRYBMkM44j5CTbRXMu4TtyChMPFh/nOQXgBlwGH3nXEAvSY 1wQtP2GwSPE7Mi098KoNz7lPGYY+p3uHdGi/LekCfPSJYaanCAoaY5RVjP3KYDMtJKIIhLF twK3WIKz/mfZxji1GbnsSftDiP4LKJEo9Ne738My0bb/1Ww+F50kYE29w62+nA9dhqPfPhv x18+c4BMkcZJ5T/sbxpMA== X-UI-Out-Filterresults: notjunk:1;V03:K0:FSA8mehE/2c=:6cARiM5Dxv1QXkF+5wFuxd 7GuJa4qB1BFKSpmnCzRq1oHrZ8xth9xHpYBE2q0bqokghbUdzO2lI4UUZ2R4kQFE8uAYSXMAu qmgeQlD/w0p4wAU89hd2PvTtpg3GxbVu7M/86YycHHFBdYF9Q9YJ5Tc2H7RDi2s6YyNiNM333 T11OM+wlSx0a422rQLIypaN/ZkZw1YX+67fGr+ZtlLb1HSQZib8MKizlBD8b4Omkl4YuWtqo+ rRpigq7uveixg73Db2X8MEy+wcPl5GSGJlgE/2MRPfGX1xa8lUD1oqJxkYpIUNLXf9iUG8i+1 EqvfSzNCBsWWp5beF0lBi2PtU/FWqhF9MTVnAlcbFFYflkLh1PEDuL2bp0syrXlwA5Zvgj9KR mNWCyoJXAaVEdhMsAd4dFRzzUkQbcFved2/4aq/ruxr7Dp7MQ39muCBY/zuoLrHP7nG2l+u5O E8C7iyp6kXzy268Ich05+i0STFzpPRW1WYnjVn6Dp8tS4BBCZEox7/yNLVH0Rko1FuWimwaDs TuTUsgwTpAyKeBgmDrsf0yB6E6Go4PVBhNsJq90UAzaDvj/09t04zioyUo/y34EB50bad5DjY V0/gYunuj++PViVuzbmXyGa+W7FIpeZ+HDW8/ZK2ZVpalMqk9xlWTRLh2RtHPxdcubrPykqWB /kgjA2FJLMQk1UPIOwKPGg8hKShWbUaOB7+RtNb6UzQVpDjrCnkU+6C4yAARJguJ7ZO1pcnk7 Uc0pYHfufn0NwWJBi5uSsP0KT3o/oi6xhPLLfrVC8SGw4ntX5xTQb/+4N+gOc/esxN+GtlmE Received-SPF: pass client-ip=212.227.17.20; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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:133179 Archived-At: On Thu, 23 Sep 2021 18:13:08 +0800 Hongyi Zhao wrote: > 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. 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'. Steve Berman