Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

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 ()
  (interactive)
  (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
add comment

Your Answer

 
discard

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.