Search code examples
emacsmacrosregion

Emacs stop marking region without using keyboard quit


I find myself often recording a macro, marking a region, and then realising I didn't want to mark a region. I then hit C-g, my way to stop it, but then as a result it stops the macro.

While executing the macro, I wouldn't care if there is an unnecessary marking and demarking, as long as I can just quickly do the macro.

Is there a way to silently stop marking a region?


Solution

  • If you didn't mean to set the mark, just use a prefix argument to the set-mark-command binding to pop that mark (jumping to it, and deactivating the region):

    C-uC-SPC

    If you don't want to jump to that position, then you'll be stuck with having the extra mark(s) in the mark ring, but you can deactivate the region by using the command (with no prefix) twice:

    C-SPCC-SPC

    That sets and then deactivates the mark.

    For clarity, note that buffers you are editing will tend to have a "marked region" most of the time -- there is always a point value, and there is generally a current mark value if you have been editing. I am assuming you are actually referring to the "active region" (i.e. a highlighted region, assuming that transient mark mode is enabled).