From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Andreas_R=c3=b6hler?= 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:37:50 +0200 Message-ID: <0e97aad3-ca78-8a5a-2ecf-2e4f5205477d@easy-emacs.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4037"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux i686; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 23 10:38: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 1mTKFL-0000mI-7J for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 10:38:23 +0200 Original-Received: from localhost ([::1]:56532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTKFI-0004aG-Nm for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 23 Sep 2021 04:38:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKEv-0004Zs-Cu for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 04:37:57 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.10]:55153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTKEt-000269-H7 for help-gnu-emacs@gnu.org; Thu, 23 Sep 2021 04:37:57 -0400 Original-Received: from [192.168.178.63] ([94.134.177.121]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mr9Jw-1nFFub3Tcc-00oFmg for ; Thu, 23 Sep 2021 10:37:51 +0200 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:D+csp/fobMMOtkDV0Jenh6dVXZOe+mFjNIPsfPm0ykxs3ktKilh 98oc2+wbnm5OXrCtaG2YEYCER/lQP1zpGoafPEm9xT6FpuOl+3VwgqL3WpH31U0v1x7qyp+ RbXcl63nC5Inu3zc1IpCYr7cl5K938j8bOLokh7Q7UJiV0q4NbyG+yX1HB++RP7vSEA6ojL QupRlEmp3FEb57oHf3+cw== X-UI-Out-Filterresults: notjunk:1;V03:K0:iLqB2H/zKFA=:eAIzlRsRFK2uD+mJx9jfDK UT2mwD3SSwNflMtu2iJd1tJ3L/Rureo55ia57h9yTxCtcAz456GHKXcUQNp2kCUQ7KuuRrtoz fZ76XrxZLu/JTweuaWdOnV9YYlMFjCJKh7uVm/+vj9DSS6hjD07QXkrk+I2TVCtsieBcUg9q+ vaaUQa0VJNAcOau07POYKd/EKYkLU2oY7VGgH5ruX2cqKs3EC52Qbx6fjzYd6DNv12KwY/zKt +zIGZ5CYnKgIl3c+UGaCNbKxqNosoEtugPkpKyBSrA7jKTb1+zTj36vNk+OUtCdyins3faexz X9KK/fA5GRfSXnIqMPyf1ngUr8Ex5Pc6uVjKhtGvFuINX0jInTi7PPKNA68FcfmEzgRpV7y5J z03vYXrk7crPbf1uxh1+nGROVLwGn9ROkdO8/5+oOMsnW2G/GiOoGhs6RCibYU+xoeuaU0QqE /BlnpDzbZW4/L7dt9ahtqwIEJTs2EkRC53B6bZVJyagzooFo/1V76V1iSd7HhmDLtyYEvww/H rMtLWFjCvGAwvhHj4B18dmjqaqYi3K5kt5TFRXJfY1smAHgSQeA+5F29Vdh1650UxKjMjK4Kr FyMUSLbZW5dzF9sMjszcgovX4+VdzPwt7CuVX6Zt3Dr87Ae9gmGl7h7I8FOHaf7l8TGuY802H q8H0zBLDkeV7Ykz/uA2Sfgc0FheJRffLAB7oar9aMpyk9XXHJp1PzU2G4bcdSRxdQgYXYC1ev vT77tNlqqS4wzwMt1g8N8Rpi/QzKaVHqCB4PB5yLE4DNLIkjUIIWg7q1aQs= Received-SPF: none client-ip=212.227.17.10; envelope-from=andreas.roehler@easy-emacs.de; helo=mout.kundenserver.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=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:133168 Archived-At: https://github.com/andreas-roehler/numbers-at-point comes with ar-raise-in-region-maybe which should do the trick. Cheers, Andreas On 22.09.21 16:28, 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 > -------------------- > > I tried all the ELISP codes suggested there, and only found that the > following one is valid: > > C-M-% \b[0-9][0-9]\b return \,(1+ \#&) > > The other two can't do the trick: > > First one: > > (defun add-1-to-2-digits (b e) > "add 1 to every 2 digit number in the region" > (interactive "r") > (goto-char b) > (while (re-search-forward "\\b[0-9][0-9]\\b" e t) > (replace-match (number-to-string (+ 1 (string-to-int (match-string 0))))))) > > Validating method: > > `M-:' input-the-above-code-here, RET, `M-x add-1-to-2-digits'. > > And the second: > > (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-int x)))))) > > Validating method: > > `M-:' input-the-above-code-here, RET > > [1] https://stackoverflow.com/questions/2686593/emacs-adding-1-to-every-number-made-of-2-digits-inside-a-marked-region > > Any hints/comments/enhancements for these methods will be greatly appreciated? > > Regards