Dimitar Panayotov shares experience

Everything which eases programmer’s life and satisfies the clients

GNU Emacs: Transient mark mode (active selection)

Posted by Dimitar Panayotov on 24 November 2006, 10:16

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.

4 Responses to “GNU Emacs: Transient mark mode (active selection)”

  1. Roman Lagunov Says:

    Hi!

    Just found your blog. Subscribe to feed.

    Looks like another emacser here. Well, it’s a good news for me today.

    I start my own blog about Emacs and linux few months ago, and search for another linux, and especially Emacs, bloggers.

    Welcome :)

  2. Dimitar Panayotov Says:

    Thank you very much, Roman.

    It is so nice to see that somebody actually cares what he/she will find here.

    It may sound as a classic cliche, but such feedback motivates me to continue to write articles which I believe could benefit somebody.

    You could easily mail me personally with your blog address, so that we could comment each other (criticizing, too, why not?) and to develop some knowledge about GNU Emacs and Linux.

    Thank you for being so kind on my “first time” :)

  3. Patricia J. Hawkins Says:

    Yes, the biggest annoyance when I screw up my .emacs file is the absence of transient-mark-mode. And worse than that is the absence of the following little code snippet, which I’ve had in my .emacs file for donkey’s years:

    (defun copy-region-as-kill-clear-mark (beg end)
    "Save the region as if killed, but don't kill it.
    If `interprogram-cut-function' is non-nil, also save the text on the global system clipboard
    If `transient-mark-mode' is set, deactivate the mark."

    (interactive "r")
    (copy-region-as-kill beg end)
    (deactivate-mark)
    )
    (define-key ctl-x-map "=" 'copy-region-as-kill-clear-mark)

    I think C-x = is bound by default to something which I never use — check and see with “C-h k C-x =”

  4. Dimitar Panayotov Says:

    Patricia,

    I have tried something like your suggestion some time ago, only to discover that it does not work on Debian 4.0 + KDE 3.5.5. See this post for details: http://pdimitar.wordpress.com/2006/11/29/gnu-emacs-universal-way-to-put-text-in-clipboard/

    I have no idea by now whether this will be fixed or not, because I am not sure whether it was the right function I called. However, as you can see in the referenced post, using clipboard-kill-ring-save solved my problems.

    Of course, I appreciate every useful piece of info anyone wants to post here, and I thank you very much. In this case, I never knew how to define keyboard shortcuts in Emacs in more descriptive way rather to type “C-X-something”, which actually does not work for some combinations, as far as I tried it.

    Thanks and take care.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>