简体   繁体   中英

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.

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)

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.

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM