Tuesday, September 21, 2010

GNU Emacs: Transient mark mode (active selection)

Posted by Dimitar Panayotov

Many developers use GNU Emacs, but they are often annoyed when they press C-SPC (Ctrl + Space) to start selecting a region and then when they go somewhere else in the file, they execute some command on the thing which should be the currently selected region. And also often it turns out the result is not as expected. To have some knowledge what you do wrong (or to keep yourself informed in a visual manner) you could enable “Transient Mark Mode” in GNU Emacs by clicking “Options” and then “Transient mark mode”; now, when you press C-SPC (Ctrl + Space) and you move the cursor, you will see a selection growing or shrinking as you move the cursor. Basically, if you press C-g (“Quit”) no region marking will be done until you press C-SPC again. Also, any change in the current file will discard the selection. If you want to be advanced on this, see here:

http://www.delorie.com/gnu/docs/emacs/emacs_54.html

As far as I know, this is pretty well supported option in many versions/variants of GNU Emacs.

You could also do it in the non-clickable way, if you like this (like me). Just put in your “.emacs” file (wherever it is, you should know) this:


(custom-set-variables
'(transient-mark-mode t))

And done.