Select region selected after emacs operation

My question is based on this answer from Trey Jackson to this question from SyntaxT3rr0r .

Trey offers the following function to increase each two-digit number in a selected area of ​​the Emacs buffer.

(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)))))))

I would like to use this feature for my own purposes. However, I would like to increase numbers many times in a row. The problem with the function in its current form is that before each call I have to select the area again with the mouse.

My question is: how can I change the Trey function so that it leaves the area selected after the call? (My ultimate goal is to assign this function a shortcut on the keyboard (something like ctrl+ ), so if I hold the keys down ctrland pressed, all the double-digit numbers in my selected area will constantly increase.)

By the way, I know this answer of Brian Campbell , which suggests using it exchange-point-and-markfor re-selecting a previously selected region. However, I tried this and it doesn't seem to help in this case.

+5
source share
2 answers

, let (deactivate-mark), save-excursion, user_jr, :

fooobar.com/questions/1153043/...

(defun add-1-to-2-digits (b e)
  "add 1 to every 2 digit number in the region"
  (interactive "r")
  (save-excursion
    (let (deactivate-mark) 
      (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)))))))))
+5

All Articles