[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode 5ba0a78 005/217: run-on and list indent primiti
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode 5ba0a78 005/217: run-on and list indent primitives |
Date: |
Sun, 29 Aug 2021 11:30:33 -0400 (EDT) |
branch: elpa/scala-mode
commit 5ba0a7875948663cc8fae9814ead3f233b3cda73
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
run-on and list indent primitives
---
Example.scala | 2 +-
scala-mode-indent.el | 69 +++++++++++++++++++++++++++++++++++++++++++++++-----
scala-mode-map.el | 2 +-
scala-mode-syntax.el | 39 +++++++++--------------------
4 files changed, 76 insertions(+), 36 deletions(-)
diff --git a/Example.scala b/Example.scala
index d46ea96..fb315c0 100644
--- a/Example.scala
+++ b/Example.scala
@@ -110,7 +110,7 @@ parentheses.
- Rule does not apply, if the first parameter was a lambda expression
*/
-class Foo(
+class Foo( /* */
i: String, // one step from indent anchor column
k: String
) // at indent anchor column
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index b10356e..64492c0 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -4,10 +4,67 @@
(provide 'scala-mode-indent)
-(defun scala-goto-indent-anhor ()
- "moves back to the point whose column will be used as
-the anchor relative to which indenting is calculated."
+(defun scala-indent:run-on-p (&optional point)
(interactive)
-
-)
-
+ "Returns t if the current point (or point at 'point) is on a
+line that is a run-on from a previous line."
+ (save-excursion
+ (when point (goto-char point))
+ (scala-syntax:beginning-of-code-line)
+ (not (or (looking-at scala-syntax:mustNotContinue-re)
+ (scala-syntax:looking-back-empty-line-p)
+ (scala-syntax:looking-back-token
+ scala-syntax:mustTerminate-re)))))
+
+; (defconst scala-syntax:mustNotTerminate-re
+; scala-syntax:reserved-symbols-unsafe-re
+
+(defun scala-indent:goto-run-on-beginning ()
+ "Moves back to the point whose column will be used as the
+anchor relative to which indenting is calculated. If this row is
+not a run on, does nothing."
+ (when (scala-indent:run-on-p)
+ (scala-syntax:beginning-of-code-line)
+ (let ((block-beg (or (nth 1 (syntax-ppss)) (point-min))))
+ (while (and (scala-indent:run-on-p)
+ (> (point) block-beg))
+ (if (scala-syntax:looking-back-token "\\s)" 1)
+ (backward-list)
+ (skip-syntax-backward "^)" (max block-beg (line-beginning-position
0))))))
+ (unless (= (char-syntax (char-before)) ?\()
+ (scala-syntax:beginning-of-code-line))))
+
+(defun scala-indent:list-element-line-p (&optional point)
+ "Returns t if the current point is in a list. A list is
+something that begins with '(' or '[', or 'for {'. A list element
+is preceded by ,"
+ (save-excursion
+ ;; first check that the previous line ended with ','
+ (beginning-of-line)
+ (let ((list-beg (nth 1 (syntax-ppss))))
+ (if (not (and (scala-syntax:looking-back-token "," 1)
+ list-beg))
+ ;; not at list element 2..n (list element 1 is not considered)
+ nil
+ (goto-char list-beg)
+ (or (= (char-after list-beg) ?\()
+ (= (char-after list-beg) ?\[)
+ (and (= (char-after list-beg) ?\{)
+ (scala-syntax:looking-back-token "for")))))))
+
+(defun scala-indent:goto-list-beginning ()
+ "Moves back to the point whose column will be used to indent
+lists rows. If this row is not a list element, does nothing"
+ (interactive)
+ (when (scala-indent:list-element-line-p)
+ (goto-char (1+ (nth 1 (syntax-ppss))))
+ (let ((block-beg (point)))
+ (forward-comment (buffer-size))
+ (if (= (line-number-at-pos (point))
+ (line-number-at-pos block-beg))
+ ;; on same line as block start
+ (progn (goto-char block-beg)
+ (skip-syntax-forward " "))
+ ;; on different line
+ (back-to-indentation)))))
+
diff --git a/scala-mode-map.el b/scala-mode-map.el
index b88f2ea..1c620af 100644
--- a/scala-mode-map.el
+++ b/scala-mode-map.el
@@ -18,7 +18,7 @@
(scala-mode-map:define-keys
keymap
(([backspace] 'backward-delete-char-untabify)
- ([(control c)(control r)] 'scala-syntax:runonp) ; TODO remove
+ ([(control c)(control r)] 'scala-indent:goto-list-beginning) ; TODO
remove
;; ("\r" 'scala-newline)
([(control c)(control c)] 'comment-region)
;; ("}" 'scala-electric-brace)
diff --git a/scala-mode-syntax.el b/scala-mode-syntax.el
index 3b5ad43..6c77a7e 100644
--- a/scala-mode-syntax.el
+++ b/scala-mode-syntax.el
@@ -193,9 +193,10 @@
and are infact a sign of run-on. Reserved-symbols not included.")
(defconst scala-syntax:mustTerminate-re
- (concat "\\([({\\[,;]\\|=>?\\|" scala-syntax:empty-line-re "\\)")
- "Symbols that must terminate an expression, i.e the following expression
-cannot be a run-on. This includes only parenthesis, '=', '=>', ',' and ';'
+ (concat "\\([,;]\\|=>?\\|\\s(\\|" scala-syntax:empty-line-re "\\)")
+ "Symbols that must terminate an expression or start a
+sub-expression, i.e the following expression cannot be a
+run-on. This includes only parenthesis, '=', '=>', ',' and ';'
and the empty line")
(defconst scala-syntax:mustNotContinue-re
@@ -210,7 +211,7 @@ and the empty line")
"protected" "return" "sealed" "throw"
"trait" "try" "type" "val" "var" "case")
'words)
- "\\|[)}]\\|]\\)")
+ "\\|\\s)\\)")
"Keywords that begin an expression and parenthesis that end an
expression, i.e they cannot be run-on to the previous line even
if there is no semi in between.")
@@ -433,7 +434,7 @@ over. Returns the number of points moved (will be
negative)."
(forward-comment -1)))
(skip-syntax-backward " " (line-beginning-position)))
-(defun scala-syntax:looking-back-token (re)
+(defun scala-syntax:looking-back-token (re &optional limit)
"Return the start position of the token matched by re, if the
current position is preceeded by it, or nil if not. All ignorable
comments and whitespace are ignored, i.e. does not search past an
@@ -443,30 +444,12 @@ empty line. Expects to be outside of comment."
(scala-syntax:skip-backward-ignorable)
(let ((end (point)))
;; skip back punctuation or ids (words and related symbols and
delimiters)
- (or (/= 0 (skip-chars-backward scala-syntax:delimiter-group))
- (/= 0 (skip-syntax-backward "."))
- (/= 0 (skip-syntax-backward "("))
- (/= 0 (skip-syntax-backward "w_'$")))
+ (or (/= 0 (skip-chars-backward scala-syntax:delimiter-group limit))
+ (/= 0 (skip-syntax-backward "." limit))
+ (/= 0 (skip-syntax-backward "(" limit))
+ (/= 0 (skip-syntax-backward ")" limit))
+ (/= 0 (skip-syntax-backward "w_'$" limit)))
;; if we didn't move, then we didn't find anything
(if (= (point) end)
nil
(if (looking-at re) (point) nil)))))
-
-(defun scala-syntax:runonp (&optional point)
- (interactive)
- "Returns t if the current point (or point at 'point) is on a
-line that is a run-on to previous line."
- (save-excursion
- (when point (goto-char point))
- (scala-syntax:beginning-of-code-line)
- (let ((p (not (or (looking-at scala-syntax:mustNotContinue-re)
- (scala-syntax:looking-back-empty-line-p)
- (scala-syntax:looking-back-token
- scala-syntax:mustTerminate-re)))))
- (when p (message "runon @ %d" (point)))
- p )))
-
-; (defconst scala-syntax:mustNotTerminate-re
-; scala-syntax:reserved-symbols-unsafe-re
-;(defconst scala-syntax:mustTerminate-re
-;(defconst scala-syntax:mustNotContinue-re
- [nongnu] branch elpa/scala-mode created (now 598cb68), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5ba0a78 005/217: run-on and list indent primitives,
ELPA Syncer <=
- [nongnu] elpa/scala-mode ca7308a 002/217: Initial commit with README and Example.scala outlining how it will work, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a8b0936 003/217: Working on syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6f1b748 001/217: Example.scala to show how we intend to indent, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3413883 004/217: run-on-p, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode f0cc3d4 006/217: working on indent rules, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode f17fa95 007/217: approaching a functioning indent engine, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 4dbaa5f 010/217: picked some of Erik's fontlock magic for an interim solution, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 84e5c8a 013/217: regression fix, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode aebc5b0 017/217: Fixes #7: indenting of block lines when at last char of buffer, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c3ea76f 009/217: fixed indenting of if body (and probably other things), ELPA Syncer, 2021/08/29