1

Using CPlusPlusMode in Emacs v24.5.1, I want to auto-create matching parenthesis and curly brace when typing expressions.

More specifically, when typing, e.g., '{', CPlusPlusMode should create a matching parenthesis and move the cursor in between, like in the example below:

if (a < b) { 
   // cursor here: default behavior

if (a < b) {
  // cursor here: anticipated behavior
}
Shuzheng
  • 11,288
  • 20
  • 88
  • 186

1 Answers1

1

ElectricPair should do what you are looking for:

Electric Pair mode, a global minor mode, provides a way to easily insert matching delimiters. Whenever you insert an opening delimiter, the matching closing delimiter is automatically inserted as well, leaving point between the two.

Use the snippet below in your Emacs config file to activate it by default for C++:

(add-hook 'c++-mode-hook #'electric-pair-mode)