Fix C-style doc comment pair expansion

Some major modes rely on external parsers for correct indentation, like
js2-mode or enh-ruby-mode. They don't properly indent the closing
comment pair (*/), so we do it manually.
This commit is contained in:
Henrik Lissner 2019-01-08 00:38:46 -05:00
parent d3fd9f3754
commit ceb06e1948
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -64,12 +64,20 @@
(sp-local-pair (append sp--html-modes '(markdown-mode gfm-mode))
"<!--" "-->" :actions '(insert) :post-handlers '(("| " "SPC")))
;; Expand C-style doc comment blocks
(defun +default-expand-doc-comment-block (&rest _ignored)
(let ((indent (current-indentation)))
(newline-and-indent)
(save-excursion
(newline)
(insert (make-string indent 32) " */")
(delete-char 2))))
(sp-local-pair
'(js2-mode typescript-mode rjsx-mode rust-mode c-mode c++-mode objc-mode
java-mode php-mode css-mode scss-mode less-css-mode stylus-mode)
java-mode php-mode css-mode scss-mode less-css-mode stylus-mode)
"/*" "*/"
:actions '(insert)
:post-handlers '(("| " "SPC") ("|\n*/[i][d-2]" "RET") ("\n* ||\n*/[i][d-2]" "*")))
:post-handlers '(("| " "SPC") ("|\n*/[i][d-2]" "RET") (+default-expand-doc-comment-block "*")))
;; Highjacks backspace to:
;; a) balance spaces inside brackets/parentheses ( | ) -> (|)