[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode aad6559 041/217: scala-indent:align-forms: obey
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode aad6559 041/217: scala-indent:align-forms: obey scala-indent:indent-value-expression |
Date: |
Sun, 29 Aug 2021 11:30:40 -0400 (EDT) |
branch: elpa/scala-mode
commit aad65599902cf27b65cf45e15bdf1904df255a2b
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
scala-indent:align-forms: obey scala-indent:indent-value-expression
Fixes #13
---
README.md | 39 +++++++++++++++++++++++++++++++
scala-mode-indent.el | 65 +++++++++++++++++++++++++---------------------------
scala-mode.el | 4 +++-
3 files changed, 73 insertions(+), 35 deletions(-)
diff --git a/README.md b/README.md
index 6b8e5b8..b861afc 100644
--- a/README.md
+++ b/README.md
@@ -130,6 +130,45 @@ val y = List( "Alpha", "Bravo",
"Charlie" )
```
+### Forms (scala-indent:align-forms)
+
+When this variable is set to 't' (default), `if`, `for` and `try`
+forms are aligned.
+
+```
+val x = if (kala)
+ foo
+ else if (koira)
+ bar
+ else
+ zot
+
+val x = try "1".toInt
+ catch { case e => 0)
+ finally { println("hello") }
+
+val xs = for (i <- 1 to 10)
+ yield i
+```
+
+When the variable is set to nil, the same will be as:
+
+```
+val x = if (kala)
+ foo
+ else if (koira)
+ bar
+ else
+ zot
+
+val x = try "1".toInt
+ catch { case e => 0)
+ finally { println("hello") }
+
+val xs = for (i <- 1 to 10)
+ yield i
+```
+
## Motion
Basic emacs motion will work as expected. The forward-sexp and
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index 7255582..72f4a7b 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -13,26 +13,6 @@ indentation will be one or two steps depending on context."
:type 'integer
:group 'scala)
-(defcustom scala-indent:align-forms t
- "Whether or not to align 'else', 'yield', 'catch', 'finally'
-below their respective expression start. When non-nil, identing
-will be
-
-val x = if (foo)
- bar
- else
- zot
-
-when nil, the same will indent as
-
-val x = if (foo)
- bar
- else
- zot
-"
- :type 'boolean
- :group 'scala)
-
(defcustom scala-indent:indent-value-expression t
"Whether or not to indent multi-line value expressions, with
one extra step. When true, indenting will be
@@ -82,7 +62,25 @@ val x = foo(1, List(1, 2, 3) map (i =>
:type 'boolean
:group 'scala)
+(defcustom scala-indent:align-forms t
+ "Whether or not to align 'else', 'yield', 'catch', 'finally'
+below their respective expression start. When non-nil, identing
+will be
+
+val x = if (foo)
+ bar
+ else
+ zot
+when nil, the same will indent as
+
+val x = if (foo)
+ bar
+ else
+ zot
+"
+ :type 'boolean
+ :group 'scala)
(defconst scala-indent:eager-strategy 0
"See 'scala-indent:run-on-strategy'")
@@ -186,13 +184,15 @@ scala-indent:align-parameters is non-nil."
(not scala-indent:align-parameters))
(back-to-indentation)))
-(defun scala-indent:value-expression-lead (start anchor)
+(defun scala-indent:value-expression-lead (start anchor &optional not-block-p)
;; 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))))
+ (let ((block-beg (if not-block-p
+ start
+ (nth 1 (syntax-ppss start)))))
(goto-char anchor)
(scala-syntax:has-char-before ?= block-beg)))))
scala-indent:step 0))
@@ -429,16 +429,13 @@ special word found. Special words include 'yield', 'else',
(if scala-indent:align-forms
anchor
(when anchor
- ;; TODO: merge to use the new function for this
- (when (scala-indent:backward-sexp-to-beginning-of-line)
- (back-to-indentation))
+ (scala-indent:align-anchor)
(point))))))))
(defun scala-indent:resolve-forms-align-step (start anchor)
(if scala-indent:align-forms
0
- ;; TODO: merge to use step calculation
- 0))
+ (scala-indent:value-expression-lead start anchor t)))
;;;
;;; Lists and enumerators
@@ -522,11 +519,9 @@ follows said symbol, or nil if not."
(goto-char (match-beginning 0))
(when (and (looking-at "\\<if\\>")
(scala-syntax:looking-back-token "\\<else\\>"))
- (match-beginning 0))
- ;;TODO merge with teh function
- (when (and (not scala-indent:align-forms)
- (scala-indent:backward-sexp-to-beginning-of-line))
- (back-to-indentation))
+ (goto-char (match-beginning 0)))
+ (when (not scala-indent:align-forms)
+ (scala-indent:align-anchor))
(point))))))
(defun scala-indent:goto-body-anchor (&optional point)
@@ -545,7 +540,8 @@ follows said symbol, or nil if not."
(defun scala-indent:resolve-body-step (start &optional anchor)
(if (and (not (= start (point-max))) (= (char-after start) ?\{))
0
- scala-indent:step))
+ (+ (scala-indent:value-expression-lead start anchor t)
+ scala-indent:step)))
;;;
;;; Block
@@ -689,7 +685,8 @@ nothing was applied."
(anchor (funcall rule-statement point)))
(if anchor
(progn
- (message "indenting acording to %s at %d" rule-statement anchor)
+ (if scala-mode:debug-messages
+ (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)
diff --git a/scala-mode.el b/scala-mode.el
index 6c1a663..6de0246 100644
--- a/scala-mode.el
+++ b/scala-mode.el
@@ -87,6 +87,7 @@ When started, runs `scala-mode-hook'.
; :abbrev
(scala-mode:make-local-variables
+ 'scala-mode:debug-messages
'syntax-propertize-function
'font-lock-defaults
'paragraph-start
@@ -103,7 +104,8 @@ When started, runs `scala-mode-hook'.
(add-hook 'syntax-propertize-extend-region-functions
'scala-syntax:propertize-extend-region)
- (setq
+ (setq scala-mode:debug-messages nil
+
syntax-propertize-function 'scala-syntax:propertize
parse-sexp-lookup-properties t
- [nongnu] elpa/scala-mode 2527376 032/217: Merge pull request #12 from non/topic/optional-padding, (continued)
- [nongnu] elpa/scala-mode 2527376 032/217: Merge pull request #12 from non/topic/optional-padding, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6aeb341 034/217: Edited README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode bd0cd1a 035/217: Examples.md contains discussion on indenting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 35f3eef 036/217: Fixes #10, if body in parameter lists, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode da67179 050/217: Merge pull request #15 from non/bug/fix-annotations, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 95e3742 063/217: fix typo in readme, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ecb0d57 055/217: correct emacs version in check, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d65f062 064/217: indent `while` like `if`, `for` et al (fixes #22), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 280bff9 037/217: fix hex literal highlighting, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3149a3d 049/217: Merge pull request #16 from gpampara/readme-update, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode aad6559 041/217: scala-indent:align-forms: obey scala-indent:indent-value-expression,
ELPA Syncer <=
- [nongnu] elpa/scala-mode 94f34b2 077/217: Rm trailing whitespace from all project files., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 5d2416f 088/217: Reverted unintended removal of whitespace deletion hook, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 56280a2 062/217: Made scala-indent:indent-on-scaladoc-asterisk be an integral part of the mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode caaebbd 078/217: Rm unneccessary `integerp` invocation., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode b251627 079/217: Comment out example binding of `scala-indent:insert-asterisk-on-multiline-comment`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode f4b5a6b 095/217: Add .sbt to config, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 037d202 090/217: Merge pull request #44 from vn971/patch-1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode cc2db35 100/217: indent case body only if first case statement is on its own line, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode e3f91eb 101/217: octal escapes for chars and strings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 74e5194 108/217: sbt support for scala-mode2, ELPA Syncer, 2021/08/29