I've the delete-selection-mode enabled. In programming modes like Python and Lua, or in general modes like Fundamental or Text, when there's an active region, pressing ( rightly wraps the region with the parenthesis pair like ( region ). I understand that this behaviour is not special and the key ( is just bound to self-insert-command.

However, when I'm in CC mode the region is deleted and I see this (|), which is not the desired behaviour as there was an active region; this seems appropriate when there's no active region. Upon investigation I understand that disabling delete-selection-mode fixes the situation.

In CC mode, giving M-( does the job, however, I don't want to special case in my brain saying, for CC mode do M-( and for every other mode do (. I want a simple solution where I can just do ( and instead of deleting the selection, the active region should get wrapped.

  • 1
    Cannot reproduce. Please try with emacs -Q and report whether behavior still exists.
    – nispio
    Commented Oct 9, 2015 at 17:21
  • @nispio Wow, thanks! Updated the question. I realize that having delete-selection-mode seems to be the issue. However, on other programming modes the issue isn't present even when it's enabled. cc-mode is the faulty one; when delete-selection-mode is enabled, it just deletes the selection instead of wrapping it.
    – legends2k
    Commented Oct 13, 2015 at 17:09

2 Answers 2


The answer by legends2k is correct. However, if you want to fix the issue without having to modify your local emacs installation, you can also work around the issue by adding the following lines to your personal .emacs:

(eval-after-load "cc-mode"
    (require 'cc-mode)
    (put 'c-electric-paren 'delete-selection nil)
    (put 'c-electric-brace 'delete-selection nil)))
  • Is it ok to move the require inside progn? Would it gain us anything?
    – legends2k
    Commented Mar 18, 2016 at 4:38
  • @legends2k I made that change. It doesn't hurt, but I'm not sure that we gain anything in terms of deferred loading either, if that's what you are asking. I'm really not sure that the eval-after-load even gains us anything, but I have never understood the ins-and-outs of autoloading very well.
    – nispio
    Commented Mar 18, 2016 at 5:24
  • Same here, even I don't understand the mechanism very well, but I think by the time require is run, the cc-mode is already ON so it wouldn't load anything not already present (which, I guess, would be the case with require had it been outside eval-after-load).
    – legends2k
    Commented Mar 18, 2016 at 6:00
  • (require 'cc-mode) inside (eval-after-load "cc-mode"...) is always a nop. Actually, you could probably just run the puts eagerly even without requireing or eval-after-loading.
    – npostavs
    Commented Mar 18, 2016 at 14:19
  • @npostavs The only thing I know for sure is that require is necessary. Also, I disagree that the require inside of eval-after-load is a nop, since I get different behavior (it doesn't work) when I comment that line out.
    – nispio
    Commented Mar 18, 2016 at 19:06

This is a bug in CC mode which is already fixed in the master branch. Since you have an older stable build, you can replace your copies of the files

from git and compile them within Emacs with M-x byte-compile-file or on terminal using

emacs -Q -batch -f batch-byte-compile delsel.el progmodes/cc-cmds.el

The respective .elc files will be updated. Reload the .elc files (M-x load file) or restart Emacs. The issue would be fixed now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.