|
From: | Michael Heerdegen |
Subject: | Re: Emacs: adding 1 to every number made of 2 digits inside a marked region. |
Date: | Mon, 27 Sep 2021 00:54:11 +0200 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hongyi Zhao <hongyi.zhao@gmail.com> writes: > 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 You might want to give Calc a try for such things. It doesn't perfectly handle the editing part though since it doesn't know about rectangle commands (AFAICT - at least for insertion). So here is how I would do it: - mark the rectangular region spanning the numbers - `C-x * r': this will grab the number column as a matrix and pop up Calc - `1 RET +': will add 1 to all entries You now have the result as a matrix. What you have to do now manually using conventional rectangle commands is to kill the original numbers from the buffer (they are already marked, so `C-x r k'), and then kill and yank the numbers as rectangle from the Calc buffer. Calc also allows to add numbers in a row or column in any buffer in a similarly easy way. The Calc tutorial has some examples doing such things. Michael.
[Prev in Thread] | Current Thread | [Next in Thread] |