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 t开发者_C百科hat an electric brace is bound to "{"? And how could I overwrite this?
Thanks.
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.
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)
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
)
精彩评论