branch: elpa/scala-mode commit be8985583dbd8a6b2a7ab690de681246e08e2c0d Author: Evan Meagher <e...@twitter.com> Commit: Heikki Vesalainen <heikkivesalai...@yahoo.com>
Multi-line comment indentation and asterisk-insertion on mid-line return. Also: - Rm unnecessary `looking-at` predicate from `scala-indent:indent-on-scaladoc-asterisk`. - Only insert asterisk when: 1. Inside scaladoc comment and 2. Previous line had leading asterisk margin or was the starting line of the comment. Closes #41 --- scala-mode-indent.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/scala-mode-indent.el b/scala-mode-indent.el index bb8457e..8f05e3a 100644 --- a/scala-mode-indent.el +++ b/scala-mode-indent.el @@ -873,18 +873,29 @@ the line." (let ((state (syntax-ppss))) (when (and (integerp (nth 4 state)) (looking-back "^\\s *\\*" (line-beginning-position))) - (when (and scala-indent:add-space-for-scaladoc-asterisk - (looking-at "\\s *$")) + (when scala-indent:add-space-for-scaladoc-asterisk (insert " ")) (scala-indent:indent-line-to (scala-indent:scaladoc-indent (nth 8 state)))))) (defun scala-indent:insert-asterisk-on-multiline-comment () "Insert an asterisk at the end of the current line when at the beginning of a line inside a multi-line comment " - (let ((state (syntax-ppss))) + (let ((state (syntax-ppss)) + (comment-start-pos (nth 8 (syntax-ppss)))) (when (and (integerp (nth 4 state)) - (string-match-p "^\\s-*$" (thing-at-point 'line))) - (end-of-line) + ; Ensure that we're inside a scaladoc comment + (string-match-p "^/\\*\\*[^\\*]" + (buffer-substring-no-properties + comment-start-pos + (+ comment-start-pos 4))) + ; Ensure that the previous line had a leading asterisk or was the comment start. + (let ((prev-line (buffer-substring-no-properties + (line-beginning-position 0) + (line-end-position 0)))) + (or + (string-match-p "^\\s-*\\*" prev-line) + (string-match-p "\\s-*/\\*\\*" prev-line)))) + (skip-syntax-forward " ") (insert "*") (scala-indent:indent-on-scaladoc-asterisk))))