[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode 26cd0b7 040/217: merged from align-parameters
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode 26cd0b7 040/217: merged from align-parameters |
Date: |
Sun, 29 Aug 2021 11:30:39 -0400 (EDT) |
branch: elpa/scala-mode
commit 26cd0b7647a5b250bfdec908c1a5646f4ab16bb9
Merge: 78fff40 d357a77
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
merged from align-parameters
---
Examples.md | 7 +--
README.md | 31 ++++++++++++--
scala-mode-indent.el | 118 +++++++++++++++++++++++++++++++++++----------------
3 files changed, 114 insertions(+), 42 deletions(-)
diff --git a/Examples.md b/Examples.md
index cc03df1..b4f801f 100644
--- a/Examples.md
+++ b/Examples.md
@@ -124,8 +124,8 @@ val someLongName = aFunctionCall(aCollection map ( name =>
value
))
-trait Foo extends Map[Option[x] forSome {
- type x <: String
+trait Foo extends Map[Option[x] forSome {
+ type x <: String
}, Boolean]
val someLongName = aFunctionCall(
@@ -160,7 +160,8 @@ val someLongName = aFunctionCall(aCollection map ( name =>
))
val someLongName = aFunctionCall("foo".
- length)
+ length
+ )
trait Foo extends Map[Option[x] forSome {
type x <: String
diff --git a/README.md b/README.md
index 81986d9..6b8e5b8 100644
--- a/README.md
+++ b/README.md
@@ -80,8 +80,9 @@ will toggle between the modes.
### Value expressions (scala-indent:indent-value-expression)
-When set to t (default), blocks in value expressions will be indented
-one extra step to make the 'val', 'var' or 'def' stand out. For example:
+When this variable is set to t (default), blocks in value expressions
+will be indented one extra step to make the 'val', 'var' or 'def'
+stand out. For example:
```
val x = try {
@@ -105,6 +106,30 @@ val x = try {
}
```
+### Parameter lists (scala-indent:align-parameters)
+
+When this variable is set to 't' (default), parameters and run-on
+lines in parameter lists will always align under and acording to the
+first parameter.
+
+```
+val x = equals(List(1,2,3) map (x =>
+ x + 1))
+
+val y = List( "Alpha", "Bravo",
+ "Charlie" )
+```
+
+When the variable is set to nil, the same will be as:
+
+```
+val x = equals(List(1,2,3) map (x =>
+ x + 1))
+
+val y = List( "Alpha", "Bravo",
+ "Charlie" )
+```
+
## Motion
Basic emacs motion will work as expected. The forward-sexp and
@@ -141,4 +166,4 @@ Mode development: Heikki Vesalainen
Contributors and valuable feedback:
- Ray Racine
- Eiríkr Åsheim (aka Erik Osheim)
-- Seth Tisue
\ No newline at end of file
+- Seth Tisue
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index 2466277..7255582 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -58,6 +58,32 @@ val x = try {
:type 'boolean
:group 'scala)
+(defcustom scala-indent:align-parameters t
+ "Whether or not to indent parameter lists so that next
+ parameter lines always align under the first parameter. When
+ non-nil, indentation will be
+
+def foo(x: Int, y: List[Int]
+ z: Int)
+
+val x = foo(1, List(1, 2, 3) map (i =>
+ i + 1
+ ), 2)
+
+When nil, the same will indent as
+
+def foo(x: Int, y: List[Int]
+ z: Int)
+
+val x = foo(1, List(1, 2, 3) map (i =>
+ i + 1
+ ), 2)
+"
+ :type 'boolean
+ :group 'scala)
+
+
+
(defconst scala-indent:eager-strategy 0
"See 'scala-indent:run-on-strategy'")
(defconst scala-indent:operator-strategy 1
@@ -137,7 +163,7 @@ it is nilled."
"Skip sexps backwards until reaches beginning of line (i.e. the
point is at the first non whitespace or comment character). It
does not move outside enclosin list. Returns the current point or
-nil if the beginnig of line could not be reached because of
+nil if the beginning of line could not be reached because of
enclosing list."
(let ((code-beg (scala-lib:point-after
(scala-syntax:beginning-of-code-line))))
@@ -151,6 +177,26 @@ enclosing list."
(unless (> (point) code-beg)
(point))))
+(defun scala-indent:align-anchor ()
+ "Go to beginning of line, if a) scala-indent:align-parameters
+is nil or backward-sexp-to-beginning-of-line is non-nil. This has
+the effect of staying within lists if
+scala-indent:align-parameters is non-nil."
+ (when (or (scala-indent:backward-sexp-to-beginning-of-line)
+ (not scala-indent:align-parameters))
+ (back-to-indentation)))
+
+(defun scala-indent:value-expression-lead (start anchor)
+ ;; calculate an indent lead. The lead is one indent step if there is
+ ;; a '=' between anchor and start, otherwise 0.
+ (if (and scala-indent:indent-value-expression
+ (ignore-errors
+ (save-excursion
+ (let ((block-beg (nth 1 (syntax-ppss start))))
+ (goto-char anchor)
+ (scala-syntax:has-char-before ?= block-beg)))))
+ scala-indent:step 0))
+
;;;
;;; Run-on
;;;
@@ -287,8 +333,7 @@ is not on a run-on line."
(while (and (scala-indent:run-on-line-p nil strategy)
(scala-syntax:skip-backward-ignorable)
(scala-indent:backward-sexp-to-beginning-of-line)))
- (when (scala-indent:backward-sexp-to-beginning-of-line)
- (back-to-indentation))
+ (scala-indent:align-anchor)
(point)))
(defconst scala-indent:double-indent-re
@@ -321,8 +366,9 @@ is not on a run-on line."
;; (= (point) end)))
;; 0)
;; else normal indent
- (t
- scala-indent:step)))))
+ (t (+ (if scala-indent:align-parameters 0
+ (scala-indent:value-expression-lead start anchor))
+ scala-indent:step))))))
(defconst scala-indent:forms-align-re
(regexp-opt '("yield" "else" "catch" "finally") 'words))
@@ -401,15 +447,17 @@ special word found. Special words include 'yield', 'else',
(defun scala-indent:goto-list-anchor-impl (point)
(goto-char point)
;; find the first element of the list
- (forward-comment (buffer-size))
- (if (= (line-number-at-pos point)
- (line-number-at-pos))
- (goto-char point)
- (beginning-of-line))
-
- ;; align list with first non-whitespace character
- (skip-syntax-forward " ")
- (point))
+ (if (not scala-indent:align-parameters)
+ (progn (back-to-indentation) (point))
+ (forward-comment (buffer-size))
+ (if (= (line-number-at-pos point)
+ (line-number-at-pos))
+ (goto-char point)
+ (beginning-of-line))
+
+ ;; align list with first non-whitespace character
+ (skip-syntax-forward " ")
+ (point)))
(defun scala-indent:goto-list-anchor (&optional point)
"Moves back to the point whose column will be used to indent
@@ -419,6 +467,11 @@ point or nil if the point is not in a list element > 1."
(when list-beg
(scala-indent:goto-list-anchor-impl list-beg))))
+(defun scala-indent:resolve-list-step (start anchor)
+ (if scala-indent:align-parameters
+ 0
+ (scala-indent:resolve-block-step start anchor)))
+
(defun scala-indent:for-enumerators-p (&optional point)
"Returns the point after opening parentheses if the current
point (or point 'point') is in a block of enumerators. Return nil
@@ -453,14 +506,15 @@ point or nil if the point is not in a enumerator element
> 1."
(regexp-opt '("if" "else" "yield" "for" "try" "finally" "catch") 'words))
(defun scala-indent:body-p (&optional point)
- "Returns the position of '=' or '=>' (TODO: not ATM) symbol if
-current point (or point 'point) is on a line that follows said
-symbol, or nil if not."
+ "Returns the position of '=', 'if or 'else if' (TODO: or '=>')
+symbol if current point (or point 'point) is on a line that
+follows said symbol, or nil if not."
(save-excursion
(when point (goto-char point))
(scala-syntax:beginning-of-code-line)
(or (scala-syntax:looking-back-token scala-syntax:body-start-re 3)
(progn
+ ;; if, else if
(when (scala-syntax:looking-back-token ")" 1)
(goto-char (match-end 0))
(backward-list))
@@ -482,10 +536,10 @@ symbol, or nil if not."
(if (looking-at scala-indent:value-keyword-re)
(point)
(when (scala-indent:backward-sexp-to-beginning-of-line)
- (scala-indent:goto-run-on-anchor nil
-
scala-indent:keywords-only-strategy))
- (when (scala-indent:backward-sexp-to-beginning-of-line)
- (back-to-indentation))
+ (scala-indent:goto-run-on-anchor
+ nil
+ scala-indent:keywords-only-strategy))
+ (scala-indent:align-anchor)
(point)))))
(defun scala-indent:resolve-body-step (start &optional anchor)
@@ -518,23 +572,14 @@ anchor for calculating block indent for current point (or
point
(when (scala-indent:backward-sexp-to-beginning-of-line)
(scala-indent:goto-run-on-anchor nil
scala-indent:keywords-only-strategy))
- (when (scala-indent:backward-sexp-to-beginning-of-line)
- (back-to-indentation))
+ (scala-indent:align-anchor)
(point)))))
(defun scala-indent:resolve-block-step (start anchor)
"Resolves the appropriate indent step for block line at position
'start' relative to the block anchor 'anchor'."
(let
- ;;; calculate a lead that is used for all steps. The lead is one
- ;;; indent step if there is a '=' between anchor and start,
- ;;; otherwise 0.
- ((lead (if (and scala-indent:indent-value-expression (ignore-errors
- (save-excursion
- (let ((block-beg (nth 1 (syntax-ppss start))))
- (goto-char anchor)
- (scala-syntax:has-char-before ?= block-beg)))))
- scala-indent:step 0)))
+ ((lead (scala-indent:value-expression-lead start anchor)))
(cond
;; at end of buffer
((= start (point-max)) (+ scala-indent:step lead))
@@ -582,7 +627,8 @@ start with opening parenthesis."
(goto-char parentheses-beg)
(cond
;; case 1
- ((and (= (char-after) ?\()
+ ((and scala-indent:align-parameters
+ (= (char-after) ?\()
(scala-indent:run-on-p)
(scala-syntax:looking-back-token ")" 1))
(scala-syntax:backward-parameter-groups)
@@ -643,7 +689,7 @@ nothing was applied."
(anchor (funcall rule-statement point)))
(if anchor
(progn
-; (message "indenting acording to %s at %d" rule-statement anchor)
+ (message "indenting acording to %s at %d" rule-statement anchor)
(when (/= anchor (point))
(error (format "Assertion error: anchor=%d, point=%d" anchor
(point))))
(+ (current-column)
@@ -659,9 +705,9 @@ point 'point'. Returns the new column, or nil if the indent
cannot be determined."
(or (scala-indent:apply-indent-rules
`((scala-indent:goto-open-parentheses-anchor
scala-indent:resolve-open-parentheses-step)
- (scala-indent:goto-for-enumerators-anchor 0)
+ (scala-indent:goto-for-enumerators-anchor
scala-indent:resolve-list-step)
(scala-indent:goto-forms-align-anchor
scala-indent:resolve-forms-align-step)
- (scala-indent:goto-list-anchor 0)
+ (scala-indent:goto-list-anchor scala-indent:resolve-list-step)
(scala-indent:goto-body-anchor scala-indent:resolve-body-step)
(scala-indent:goto-run-on-anchor scala-indent:resolve-run-on-step)
(scala-indent:goto-block-anchor scala-indent:resolve-block-step)
- [nongnu] elpa/scala-mode 5209142 189/217: Support for identifiers consisting from operator characters (#138), (continued)
- [nongnu] elpa/scala-mode 5209142 189/217: Support for identifiers consisting from operator characters (#138), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6f49104 193/217: scala-syntax:propertize-dollar, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 2a7b0fd 195/217: Moved ensime/emacs-scala-mode back to hvesalai/emacs-scala-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5d28cb3 210/217: feat: support trailing commas (>= Scala 2.12.2), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode b21befd 211/217: Fix README.md indenting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d837c96 203/217: doc: supports both Scala 2 and 3 (to some extent), not just 2.9, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 2bf5621 207/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 402d6df 209/217: Merge pull request #165 from fommil/sbtn, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ac8106f 025/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d81bc28 028/217: indenting code lines also removes trailing whitespace, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 26cd0b7 040/217: merged from align-parameters,
ELPA Syncer <=
- [nongnu] elpa/scala-mode 884795f 052/217: more fixes to strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 7113976 059/217: Indenting for multi-line strings with margin, fixed row comment indent, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 8d4f34f 058/217: Use font-lock-doc-face for scaladoc comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 689bd7d 089/217: (require 'package), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode cb3f278 086/217: Update for marmalade / melpa package., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 1a241eb 076/217: Add `scala-indent:insert-asterisk-on-multiline-comment`., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5cd1b20 068/217: Properly align constructor val and var params., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ad73d10 096/217: Merge pull request #49 from zbskii/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode defa2af 098/217: pkg.el cleanup, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 13b30a6 093/217: Added Hugh Giddens to contributors, ELPA Syncer, 2021/08/29