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: Emacs: adding 1 to every number made of 2 digits inside a marked region. Date: Wed, 22 Sep 2021 22:28:28 +0800 Message-ID: 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="3633"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 22 16:32:03 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 1mT3I1-0000eU-SR for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 22 Sep 2021 16:32:01 +0200 Original-Received: from localhost ([::1]:43104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mT3Hz-0001Yj-N1 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 22 Sep 2021 10:31:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mT3Gp-0001XU-G6 for help-gnu-emacs@gnu.org; Wed, 22 Sep 2021 10:30:47 -0400 Original-Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:42508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mT3Gl-0008VZ-Fg for help-gnu-emacs@gnu.org; Wed, 22 Sep 2021 10:30:44 -0400 Original-Received: by mail-lf1-x136.google.com with SMTP id u8so12348003lff.9 for ; Wed, 22 Sep 2021 07:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=BG2ofBtAwyKawozaCJka9nPo0yDf1NoIJBKPg4ybthc=; b=BksFqPWgmz5PNy55stkP4Qr17vW4drcneEiBEFkjdJYwYTTuSWXewEsVSUmnSnqLXs y0+ToicEmnSYcks0iSSV3f26uKFOlp0vmG+gLBftvJbNf8Wj3qGWXeMTuu9KhOA9THkx kdthCoAFOuHXwjhvt5QN7XSD1Uz0RJDKDI/2rezz2lMJBB16iIytMKnPZY722+S9M4Ix LQgN0jEgwZJXEpC9GuenUJfZpU5wk3reV2mFx6QLvHxad3lH+1aqqL54SDW8tQ5+OTQH 7AwJi0xQLi9ZHSwbUS4BlKh32EW2zxXF5SvTjepNCcvRP2UaMwYy65iQLEMPoTf+3Ubc slSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=BG2ofBtAwyKawozaCJka9nPo0yDf1NoIJBKPg4ybthc=; b=2SgzuqmqH/mqlhIIP2onzK8H02a/BlOLYKRRU9bE+pBkqhM28pAhssCW3YBbW+UjLw mrDR50EZhRQY9Cz7Nj0GRpy7Altv0RlIhEZlYpy9RwYwIRg7IndbR3Y3zxQuosZpV4PZ K0ccHWWEUS9OgSsRGLQdQTf2ieqYtDHS1PR9azY4asMqqpz8u+9uNGWvFDWEKaEPBjpc QQ+bK6x0r6xpxpl3hpUHXQW8C1rIySFJZPWzg4KmImTaiqF6id4nn3nefZpR7pZ+chyY kAavgk1FgWDj+VKKuHprob9E0lH9t7qSgc1mh2m/YRockUGKliNVvLgn/fbICuPbyaYP jGdg== X-Gm-Message-State: AOAM5335ALCnAAXc9kU9lQzBtOxcM5oHMm3X4GW74oVd96CoM7M/gI5g lTCjCtaJLc0ZbgX4+DtTtgMBL+BsTr1dPJC4novM6Az+8UPbKeEr X-Google-Smtp-Source: ABdhPJwi/jwhgjWC79vNEjbT3pyBRZ4waUd8XCka/e4mGJY3NVNnxrs9rZSgHX3oKFueG0kqvucipPeV7npkUAD7UD0= X-Received: by 2002:ac2:59c6:: with SMTP id x6mr29157098lfn.298.1632320919481; Wed, 22 Sep 2021 07:28:39 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=hongyi.zhao@gmail.com; helo=mail-lf1-x136.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:133148 Archived-At: 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 -- Assoc. Prof. Hongyi Zhao Theory and Simulation of Materials Hebei Vocational University of Technology and Engineering No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province