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.


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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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