Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In emacs, I prefer the electric-pair-mode behavior for parentheses and brackets as opposed to what seems like the "jumpy" default behavior.

However, I currently use auto-newline and like the automatic newlines inserted with the curly brackets (I use BSD style indentation).

What I would like to figure out is how to best combine these behaviors, so that when I type an opening curly bracket, an indented line and closing bracket will follow.

I tried looking on Google for potential solutions, but I had trouble trying to phrase what exactly I'm looking for.

share|improve this question

I could not find an easy way to do what you want, though eventually electric-layout-mode might help. So I offer the following hack:

(defun c-open-brace ()
  (let ((electric-pair-mode nil))
    (c-electric-brace nil)
    (save-excursion (newline) (insert ?}) (indent-according-to-mode))))

(define-key c-mode-map (kbd "{") 'c-open-brace)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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