branch: elpa/scala-mode commit 081a92b0b6431f235658d99027f7cb510fe68f11 Author: Heikki Vesalainen <heikkivesalai...@yahoo.com> Commit: Heikki Vesalainen <heikkivesalai...@yahoo.com>
scala-indent:remove-indent-from-previous-empty-line New functionality that removes previously added indent when the cursors moves away from the line and the line was left otherwise empty. --- scala-mode-indent.el | 24 +++++++++++++++++++++++- scala-mode-map.el | 4 ++++ scala-mode.el | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scala-mode-indent.el b/scala-mode-indent.el index 27a3b88..48d5628 100644 --- a/scala-mode-indent.el +++ b/scala-mode-indent.el @@ -761,6 +761,25 @@ column, if it was at the left margin." (indent-line-to column) (save-excursion (indent-line-to column))))) +(make-variable-buffer-local 'scala-indent:previous-indent-pos) + +(defun scala-indent:remove-indent-from-previous-empty-line () + "Handles removing of whitespace from a previosly indented code +line that was left empty (i.e. whitespaces only). Also clears the +scala-indent:previous-indent-pos variable that controls the process." + (when (and scala-indent:previous-indent-pos + (/= scala-indent:previous-indent-pos (point))) + (save-excursion + (beginning-of-line) + (if (= scala-indent:previous-indent-pos + (point)) + (setq scala-indent:previous-indent-pos + (when (looking-at "^\\s +$") (point))) + (goto-char scala-indent:previous-indent-pos) + (when (looking-at "^\\s +$") + (delete-region (match-beginning 0) (match-end 0))) + (setq scala-indent:previous-indent-pos nil))))) + (defun scala-indent:indent-code-line (&optional strategy) "Indent a line of code. Expect to be outside of any comments or strings" @@ -772,7 +791,10 @@ strings" ; (message "run-on-strategy is %s" (scala-indent:run-on-strategy)) (scala-indent:indent-line-to (scala-indent:calculate-indent-for-line)) (scala-lib:delete-trailing-whitespace) - ) + (setq scala-indent:previous-indent-pos + (save-excursion + (beginning-of-line) + (when (looking-at "^\\s +$") (point))))) (defun scala-indent:indent-line (&optional strategy) "Indents the current line." diff --git a/scala-mode-map.el b/scala-mode-map.el index d827e41..15e46a5 100644 --- a/scala-mode-map.el +++ b/scala-mode-map.el @@ -23,6 +23,10 @@ (add-hook 'post-self-insert-hook 'scala-indent:indent-on-scaladoc-asterisk)) +(defun scala-mode-map:add-remove-indent-hook () + (add-hook 'post-command-hook + 'scala-indent:remove-indent-from-previous-empty-line)) + (when (not scala-mode-map) (let ((keymap (make-sparse-keymap))) (scala-mode-map:define-keys diff --git a/scala-mode.el b/scala-mode.el index bfb3f6f..81ff902 100644 --- a/scala-mode.el +++ b/scala-mode.el @@ -99,6 +99,7 @@ When started, runs `scala-mode-hook'. (turn-on-font-lock) ;; add indent functionality to some characters (scala-mode-map:add-self-insert-hooks) + (scala-mode-map:add-remove-indent-hook) ) ;; Attach .scala files to the scala-mode