branch: elpa/scala-mode commit 1a3d958f28d46c999ccde122e8cfece0a5997a09 Author: Heikki Vesalainen <heikkivesalai...@yahoo.com> Commit: Heikki Vesalainen <heikkivesalai...@yahoo.com>
forward/backward-sexp --- README.md | 6 ++++-- scala-mode-map.el | 2 -- scala-mode-syntax.el | 23 ++++++++--------------- scala-mode.el | 10 +++++++++- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index bc0d1c5..38692bc 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,9 @@ will toggle between the modes. ## Motion -Basic emacs motion will work, including movement over expressions (M-C-f, M-C-b). +Basic emacs motion will work as expected. The forward-sexp and +backward-sexp (M-C-f, M-C-b) motion commands will move over reserved +words, literals, ids and lists. ## Code highlighting @@ -87,11 +89,11 @@ should work is welcomed as issues to this github project. - supports multi-line strings - highlights only properly formatted string and character constants - fills scaladoc comments properly (TODO row comments) +- indenting a code line removes trailing whitespace ## Future work - indent scaladoc left margin correctly -- indenting a row should remove trailing whitespace and converts tabs to spaces - indent and fill multi-line strings with margin correctly - movement commands to move to previous or next definition (val, var, def, class, trait, object) diff --git a/scala-mode-map.el b/scala-mode-map.el index bb4dabc..2108e11 100644 --- a/scala-mode-map.el +++ b/scala-mode-map.el @@ -28,8 +28,6 @@ keymap ( ([backtab] 'scala-indent:indent-with-reluctant-strategy) - ;; TODO: remove, use forward-sexp-function insetead - ((kbd "C-M-b") 'scala-syntax:backward-sexp) ([(control c)(control r)] 'scala-indent:rotate-run-on-strategy) ([(control c)(control c)] 'comment-region) ;; ("}" 'scala-electric-brace) diff --git a/scala-mode-syntax.el b/scala-mode-syntax.el index 1e83cd6..d42f21a 100644 --- a/scala-mode-syntax.el +++ b/scala-mode-syntax.el @@ -663,7 +663,7 @@ one." (while (scala-syntax:looking-at scala-syntax:modifiers-re) (scala-syntax:forward-sexp) (when (scala-syntax:looking-at "[") - (forward-sexp))))) + (forward-list))))) (defun scala-syntax:looking-back-else-if-p () ;; TODO: rewrite using (scala-syntax:if-skipped (scala:syntax:skip-backward-else-if)) @@ -733,16 +733,10 @@ beginning of the skipped expression." (forward-comment (buffer-size)) (while (< 0 (+ (skip-syntax-forward " ") (skip-chars-forward scala-syntax:delimiter-group)))) - - (if (not (= (char-syntax (char-after)) ?\.)) - ;; emacs can handle everything but opchars - (forward-sexp) - ;; just because some char has punctuation syntax, doesn't mean the - ;; position has it (since the propertize function can change - ;; things. So... let's first try to handle it as punctuation and - ;; if we got no success, then we let emacs try - (when (= (skip-syntax-forward ".") 0) - (forward-sexp)))) + + ;; emacs can handle everything but opchars + (when (= (skip-syntax-forward ".") 0) + (goto-char (or (scan-sexps (point) 1) (buffer-end 1))))) (defun scala-syntax:backward-sexp () "Move backward one scala expression. It can be: parameter @@ -756,10 +750,9 @@ beginning of the skipped expression." (while (> 0 (+ (skip-syntax-backward " ") (skip-chars-backward scala-syntax:delimiter-group)))) - (if (not (or (bobp) (= (char-syntax (char-before)) ?\.))) - (backward-sexp) - (when (= (skip-syntax-backward ".") 0) - (backward-sexp)))) + (when (= (skip-syntax-backward ".") 0) + (goto-char (or (scan-sexps (point) -1) (buffer-end -1))) + (backward-prefix-chars))) (defun scala-syntax:has-char-before (char end) (save-excursion diff --git a/scala-mode.el b/scala-mode.el index 28012e6..6c1a663 100644 --- a/scala-mode.el +++ b/scala-mode.el @@ -49,6 +49,13 @@ (defconst scala-mode:paragraph-separate (concat scala-mode:comment-line-start "$")) +(defun scala-mode:forward-sexp-function (&optional count) + (unless count (setq count 1)) + (if (< count 0) + (dotimes (n (abs count)) + (scala-syntax:backward-sexp)) + (dotimes (n count) + (scala-syntax:forward-sexp)))) ;; (defun scala-mode () ;; "Major mode for editing scala code. @@ -90,6 +97,7 @@ When started, runs `scala-mode-hook'. 'comment-start-skip 'comment-column 'comment-multi-line + 'forward-sexp-function 'indent-line-function 'indent-tabs-mode) @@ -118,7 +126,7 @@ When started, runs `scala-mode-hook'. ;; TODO: comment-indent-function ;; TODO: forward-sexp-function - + forward-sexp-function 'scala-mode:forward-sexp-function indent-line-function 'scala-indent:indent-line indent-tabs-mode nil )