2

Imagine one wants to apply two functions (A and B, where A could be commenting the code with M-; and B convert the text to all-caps with C-x C-u) to the same active region. I would proceed as follows:

  1. set the mark with C-<SPC>
  2. move the cursor until the end of the region I want to modify
  3. run function A
  4. repeat 1. and 2.
  5. run function B

How should I proceed to run both A and B (and potentially others) without repeating the selection step? It seems this behavior arises since most functions which work on an active region implicitly call deactivate-mark on completion.


The question above highlights one of the use cases described in this other post.

unvarnished
  • 129
  • 5
  • 1
    While the answer to the other question duplicate the answer here, the questions are very different. If I was searching for the answer to 'how to apply multiple actions to the region', how would I know to search for 'what is the use of exchange mark and point'? – Tyler Aug 25 '21 at 16:36
  • @Tyler: Completely agree, but cannot reopen the question by myself. I myself only found the other question after reading the accepted answer. – unvarnished Aug 26 '21 at 07:59

1 Answers1

3

At step 4, do C-x C-x (exchange-point-and-mark) which will reactivate the mark as it swaps point and mark (and so takes point back to where you started in Step 1).

Fran Burstall
  • 3,665
  • 10
  • 18
  • Thank you. I had dismissed this option because it seemed not to work, but upon further inspection I realized it was being overridden by ```cua-mode```. One either deactivates ```cua-mode```, or else uses the following: ```(require 'cua-base) (progn (define-key cua-global-keymap (kbd "C-x C-x") 'exchange-dot-and-mark) ) ``` where ```exchange-dot-and-mark``` is an alias for ```exchange-point-and-mark```, but has no predefined keybind. – unvarnished Aug 25 '21 at 16:11