Skip to content

Fixing the mark commands in transient mark mode

by mickey on December 22nd, 2010

Most people, myself included, use transient-mark-mode (or just tmm), a great piece of kit that makes Emacs behave sanely by using visible regions like other editors. But tmm can get in the way of Emacs’s point and mark system, as the mark also serves as a handy beacon that you can set with C-SPC and jump to with C-u C-SPC.

Sadly, most of the point and mark commands generally go unnoticed by people who never used Emacs without tmm. That’s a shame, because mastering the mark commands will greatly speed up movement and editing.

In tmm the command C-SPC activates the region and lets you select text as you see fit. That means if you want to set the mark (and nothing else) you have to follow up the preceding command with another C-SPC (or C-g) to abort the active region “selection.” That’s too much typing for something that should be second nature.

I use the following snippet below to explicitly set the mark. I bind it to C-, an unused key.

The C-u C-SPC command is trickier, as the functionality in tmm can be very useful for precision work not served by specialist commands like mark-defun or kill-sexp. To jump to the mark I replace the binding on M- — an altogether useless command that opens up a terminal-friendly menu bar in the minibuffer — with a dedicated “jump to mark” command.

The exchange-point-and-mark, bound to C-x C-x, will by default activate the region when it is invoked. You must use the prefix argument to suppress the activation, but I find that to be too cumbersome for day-to-day use so I disable it outright. The snippet below will do this, so if you don’t want that to happen don’t use the snippet below!

And there you have it. Mark commands without the interloping tmm to spoil the fun.

  1. Boyd Adamson permalink

    It’s not in the doc string but when tmm is on, calling set-mark-command twice (C-SPC C-SPC) will set the mark but disable the region. Easier than C-SPC C-g

    (When tmm is off, it’s the opposite – a double press will turn it on temporarily)

  2. What a good aritcle.
    This do save time.
    But C-SPC conflict with ime.
    I have to change C-SPC to f2.

  3. Chris permalink

    On the mark commands, I find mark-sexp to be one of the most useful, in or out of a lisp-style mode. It grabs identifiers, balanced groups of parens and braces, etc. and on repeat it just expands. I bind it to M-SPC and use it hundreds of times each day.

    I’m enjoying the blog; thanks.

    • mickey permalink

      Hi Chris,

      Glad you like the blog. That command is one of my favourites, too. I use the default C-M-SPC keybind as it matches kill-sexp bound to C-M-k.

  4. rory permalink

    Thank you for these nice tweaks.

  5. Great article! After just two days of using Emacs, this was probably the most desired feature I wanted to implement.

Trackbacks & Pingbacks

  1. Effective Editing I: Movement | Mastering Emacs
  2. There and back again in Emacs (and Visual Studio) « Peter Reavy
  3. My Emacs keybindings | Mastering Emacs
  4. There and back again in Emacs (and Visual Studio) | Peter Reavy

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS