TransientMarkMode

Transient Mark mode gives you much of the standard selection-highlighting behavior of other editors. In GNU Emacs 23 and onwards, it is enabled by default. Otherwise, to enable it, put the following in your init file: (transient-mark-mode 1)

In Transient Mark mode, the region is active only temporarily, and it is highlighted while it is active. You activate the region for each command that uses it: place the mark, then move the cursor (and point).

Some features in Emacs support extra behaviors or require it to be on.

Highlighting the region would not be appropriate without Transient Mark mode. Because the region always exists (as soon as the mark exists), without a notion of active region, some text would always be highlighted (except when mark = point), which would prove to be a nuisance.

In Emacs 22 and later, ‘C-SPC C-SPC’ activates Transient Mark mode only temporarily. This means that even if you do not use Transient Mark mode, you can get the effect of it for the space of one command by doing ‘C-SPC C-SPC’.

See also:

Commands that do not work well with Transient Mark Mode

indent-rigidly (prior to Emacs 23 only)

  1. Set mark (C-SPC)
  2. Move the cursor a couple of lines down
  3. C-x TAB

In GnuEmacs prior to Emacs 23, if ‘transient-mark-mode’ is on, the above works only one time. Consecutive presses of ‘C-x TAB’ beep at you (“The mark is not active now”).

In order to keep the region highlighted after ‘C-x TAB’ finishes, you can use this advice:

   (defadvice indent-rigidly (after deactivate-mark-nil activate)
     (if (called-interactively-p)
         (setq deactivate-mark nil)))

Comments

Trouble activating the region at the end of a command

I wrote a small function called ‘duplicate-region’ (see DuplicateStartOfLineOrRegion), and I’d like the mark to be active after calling it.

Transient mark mode is on, I use ‘push-mark’ and ‘exchange-point-and-mark’, (I tried a few other options too) but I can’t make it work. Any idea ?

Cheers! – SebastienRoccaSerra

  (setq deactivate-mark nil)

DrewAdams

Thanks, done! – SebastienRoccaSerra

How to make C-x C-x turn on highlighting?

How do you make C-x C-x turn on highlighting, without changing anything else?

What do you mean by *“without changing anything else”*? Doesn’t ‘C-x C-x C-x C-x’ do what you are requesting?


CategoryRegion