Beatlevic
Beatlevic

Reputation: 605

Emacs php-mode and paredit

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.

Upvotes: 4

Views: 743

Answers (3)

Vicky Chijwani
Vicky Chijwani

Reputation: 10479

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)

Upvotes: 1

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56595

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.

Upvotes: 2

phimuemue
phimuemue

Reputation: 35983

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)

Upvotes: 2

Related Questions