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 10:07:34 +0200 Message-ID: <87ee9fsojd.fsf@rub.de> References: <87pmt0bdao.fsf@rub.de> <87r1dfsqj4.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15525"; 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 10:08:23 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 1mTJmJ-0003re-0o for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 10:08:23 +0200 Original-Received: from localhost ([::1]:34838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTJmH-00064f-Ae for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 04:08:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTJlg-00064N-0P for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 04:07:44 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:45023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTJla-00019y-Fi for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 04:07:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=badeba3b8450; t=1632384455; bh=swcc7xRI4xPh8dqRxvk8MYJdA6R99JoM0/gCdYUwm9E=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=CiVqqxFEjlIeZ9rE01yeoNuG7tiiYli9Kk5FsrSLZODb7uxtj3BIJbYPep7XtE8S5 xen1gsVECVsE3AGGqoEJy0gcWS2CEpuHy3CodduaoineAmNMbGY1W42YAflXTcuIT3 iM6/hJsecAcacgfSys8gkbtnaTjL76gc0Mwda2/0= 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 1Mw9UK-1mk1AZ0vBs-00s5DF; Thu, 23 Sep 2021 10:07:35 +0200 In-Reply-To: (Hongyi Zhao's message of "Thu, 23 Sep 2021 15:54:19 +0800") X-Provags-ID: V03:K1:JvgVcKOcF7VI0UUoq7YWbMyBOg/MNd/7AdX+Ne5Iu0cfCkfanWB BtXkqpBXVHzPJRJmxH3osFZDNA6MvTymfseQX8xbZiI8PiZgYPCXnFOFSTTX8U+YvFV/RJn c7PQ2r2HnB/aUT1Z/CHOo7elw5B3Woc+rf+fOyaKfebc1jsoNed9de2U9z0LWJqavPvcRNL AD+aYCZWqUZ2Doh2/+kzQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:CmNXkXmUqIs=:gM5/0VEWJ6kIo+T2pEBe9l xhXdehXmYuPYDf51mprfZbTaqVbWH8ug5FAcowOax7edWUwLwqif+KwtfGWhmWPoWUZi7maOz 6cc+KBjW8zTwDEy39HXxqucJvLZhx/hHDlkjDXkAFOottG3sY0pEXqCK/jJ6AUunOIwwYC9+H vKccdpDjlrhv6TVj4GcKAmjtRlcf522wWoDahs2YjjcuwMnGsNYi4roLN2NaMQHP7+AZbHTdK FWGXagIFM4JLBoplfeoZrWISTHD59t4AZLPxRGX+XBGzbymuJjYY1gMpTAvdC3u2+GUYeB2eQ zdYZ3ka+TBNfwziTOvfaIUk2Jw3dZV7wEPY2XMxTgKgZARDM+pPmrEcpXAf1KKPyKis5OsvKD +RDxDzhskIxCvmd8klHIGTl+1+8IJ+7JtfqAeBVJ1scDcvGHUJe8rJZvvu3+q0eiUwK2rFz4O TLzVU0DfhmZekkxrW3aqGM84ZFxIfxeLLFKAWwaa/u1DOFaKzmfvaiNKj/5yQTsz0mcgamsCF 8fMtvV0OkuGzBBNwS6Wcl57Hcfn8UKilwVWE5cOpKXexJzmP89P5oFiIJ+l8o8OM4YJ8BCtEh 78tVdZYjmmRrIGmnqRcBULXHGpkAO9nsDslqpc5t2GOB1VLDzrtpqgY5lZr22p866pXnThAS7 hNxY5sSbgPxcot2ar2vDHf4Pc9o0O8NK18E/0sVEHpAGdwVd8qA+ATb6qW+xJi5DXv9Wgz3NE UQt1cPBm5VhpaYNb9PEPx5qAViHC7TdGAYsOUp3kPvdC16lS849D2lvsmzVsLKX2xQSBr+i2 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:133167 Archived-At: 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. Steve Berman