branch: elpa/scala-mode commit ac13b94f38e2752d2c7b99b909aeb4c35c2b943d Author: Heikki Vesalainen <heikkivesalai...@yahoo.com> Commit: Heikki Vesalainen <heikkivesalai...@yahoo.com>
post-self-insert-hooks scala-indent:indent-on-special-words scala-indent:indent-on-scaladoc-asterisk --- README.md | 1 - scala-mode-indent.el | 25 ++++++++++++++++++++++++- scala-mode-map.el | 4 +++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f44a388..55e9ada 100644 --- a/README.md +++ b/README.md @@ -325,7 +325,6 @@ customization variable *frame-background-mode* to *dark* (use **M-x** - syntax-begin-function for reliably fontifying elements which span multiple lines - beginning-of-defun, end-of-defun -- indent case, etc after they are typed (use first space as self-insert-hook) - movement commands to move to previous or next definition (val, var, def, class, trait, object) - highlight headings and annotations inside scaladoc specially (use diff --git a/scala-mode-indent.el b/scala-mode-indent.el index cf953c0..8ceb7d1 100644 --- a/scala-mode-indent.el +++ b/scala-mode-indent.el @@ -789,7 +789,25 @@ comment is outside the comment region. " (+ (match-beginning 0) 1))) (current-column)))) -(defun scala-mode:indent-scaladoc-asterisk (&optional insert-space-p) +(defconst scala-indent:indent-on-words-re + (concat "^\\s *" + (regexp-opt '("catch" "case" "else" "finally" "yield") 'words))) + +(defun scala-mode:indent-on-special-words () + "This function is meant to be used with post-self-insert-hook. + +Indents the line if position is right after a space that is after +a word that needs to be indented specially." + ;; magic numbers used 4 = length of "case" + (when (and (> (current-column) 4) + (= (char-before) ?\s) + (= (char-syntax (char-before (- (point) 1))) ?w) + (save-excursion (backward-char) + (looking-back scala-indent:indent-on-words-re)) + (not (nth 8 (syntax-ppss)))) + (scala-indent:indent-line-to (scala-indent:calculate-indent-for-line)))) + +(defun scala-mode:indent-on-scaladoc-asterisk (&optional insert-space-p) "This function is meant to be used with post-self-insert-hook. Indents the line if position is right after an asterisk in a @@ -804,3 +822,8 @@ the asterisk is the last character on the line." (looking-at "\\s *$")) (insert " ")) (scala-indent:indent-line-to (scala-indent:scaladoc-indent (nth 8 state)))))) + +(defun scala-mode:indent-scaladoc-asterisk (&optional insert-space-p) + (message "scala-mode:indent-scaladoc-asterisk has been deprecated, use +scala-mode:indent-on-scaladoc-asterisk") + (scala-mode:indent-on-scaladoc-asterisk insert-space-p)) diff --git a/scala-mode-map.el b/scala-mode-map.el index efba50b..f6d99ca 100644 --- a/scala-mode-map.el +++ b/scala-mode-map.el @@ -22,7 +22,9 @@ (defun scala-mode-map:add-self-insert-hooks () (add-hook 'post-self-insert-hook - #'scala-mode-map:indent-parentheses)) + 'scala-mode-map:indent-parentheses) + (add-hook 'post-self-insert-hook + 'scala-mode:indent-on-special-words)) (when (not scala-mode-map) (let ((keymap (make-sparse-keymap)))