4

I would like to use paredit in combination with php-mode, but it doesn't add a closing curly bracket "}". Might this have something todo with the fact that an electric brace is bound to "{"? And how could I overwrite this?

Thanks.

Beatlevic
  • 605
  • 1
  • 6
  • 13

3 Answers3

2

Some time ago, I wrote such a thing for C, but you can easily use it for PHP as well:

(define-minor-mode c-helpers-minor-mode
  "This mode contains little helpers for C developement"
  nil
  ""
  '(((kbd "{") . insert-c-block-parentheses))
)

(defun insert-c-block-parentheses ()
  (interactive)
  (insert "{")
  (newline)
  (newline)
  (insert "}")
  (indent-for-tab-command)
  (previous-line)
  (indent-for-tab-command)
  )

(add-hook 'php-mode-hook 'c-helpers-minor-mode)
phimuemue
  • 34,669
  • 9
  • 84
  • 115
2

Using paredit is php-mode is a bad idea - it's mostly suited for Lisp code editing. There is a very nice alternative for general purpose development though - autopair-mode. It's very easy to use and inserts braces, brackets and quotes in a manner similar to the one present in most IDEs.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
  • I found `autopair-mode` horrendously slow when I had a large number of open buffers. `paredit-mode`, on the other hand, always feels snappy, which is why I use it everywhere. – Vicky Chijwani Apr 12 '12 at 18:48
  • Emacs 24 contains a new global `electric-pair-mode`, which might be faster? – phils Apr 13 '12 at 07:08
  • 1
    Yep, it is. I've moved on from `autopair-mode` to the new `electric-pair-mode`. It's slightly less capable, but a lot faster indeed. – Bozhidar Batsov Apr 13 '12 at 07:15
1

In my experience, autopair-mode felt extremely sluggish when a large number of buffers were open (plus, paredit-mode ensures that delimiters are never unbalanced, unlike autopair-mode). So if, like me, you absolutely want to use paredit-mode and nothing else will do, have a look at this answer. In the elisp snippet given there, just replace slime-repl-mode-map and slime-repl-mode-hook with the corresponding variables for php (most likely php-mode-map and php-mode-hook)

Community
  • 1
  • 1
Vicky Chijwani
  • 10,191
  • 6
  • 56
  • 79