[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode 78fff40 039/217: scala-indent:align-forms custo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode 78fff40 039/217: scala-indent:align-forms customization variable |
Date: |
Sun, 29 Aug 2021 11:30:39 -0400 (EDT) |
branch: elpa/scala-mode
commit 78fff40e4f3555787c21964b9c8a7efefebc90d1
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
scala-indent:align-forms customization variable
---
scala-mode-indent.el | 109 ++++++++++++++++++++++++++++++++++-----------------
1 file changed, 73 insertions(+), 36 deletions(-)
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index c1fba0b..2466277 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -13,6 +13,26 @@ 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
@@ -304,10 +324,10 @@ is not on a run-on line."
(t
scala-indent:step)))))
-(defconst scala-indent:special-align-re
+(defconst scala-indent:forms-align-re
(regexp-opt '("yield" "else" "catch" "finally") 'words))
-(defun scala-indent:special-align-p (&optional point)
+(defun scala-indent:forms-align-p (&optional point)
"Returns scala-syntax:beginning-of-code-line for the line on
which current point (or point 'point') is, if the line starts
with one of 'yield', 'else', 'catch' and 'finally', otherwise
@@ -315,18 +335,18 @@ nil. Also, the previous line must not be with '}'"
(save-excursion
(when point (goto-char point))
(scala-syntax:beginning-of-code-line)
- (when (looking-at scala-indent:special-align-re)
+ (when (looking-at scala-indent:forms-align-re)
(goto-char (match-beginning 0))
(point))))
-(defun scala-indent:goto-special-align-anchor (&optional point)
+(defun scala-indent:goto-forms-align-anchor (&optional point)
"Moves back to the point whose column will be used as the
anchor relative to which indenting of special words on beginning
of the line on which point (or point 'point') is, or nul if not
special word found. Special words include 'yield', 'else',
'catch' and 'finally'"
- (let ((special-beg (scala-indent:special-align-p point)))
+ (let ((special-beg (scala-indent:forms-align-p point)))
(when special-beg
(goto-char special-beg)
(if (and (scala-syntax:looking-back-token "}")
@@ -334,31 +354,45 @@ special word found. Special words include 'yield', 'else',
(goto-char (match-beginning 0))
(= (match-beginning 0) (scala-lib:point-after
(scala-syntax:beginning-of-code-line)))))
(goto-char (match-beginning 0))
- (cond ((looking-at "\\<yield\\>")
- ;; align with 'for'
- (if (scala-syntax:search-backward-sexp "\\<for\\>")
- (point)
- (message "matching 'for' not found")
- nil))
- ((looking-at "\\<else\\>")
- ;; align with 'if' or 'else if'
- (if (scala-syntax:search-backward-sexp "\\<if\\>")
- (if (scala-syntax:looking-back-token "\\<else\\>")
- (goto-char (match-beginning 0))
- (point))
- nil))
- ((looking-at "\\<catch\\>")
- ;; align with 'try'
- (if (scala-syntax:search-backward-sexp "\\<try\\>")
- (point)
- (message "matching 'try' not found")
- nil))
- ((looking-at "\\<finally\\>")
- ;; align with 'try'
- (if (scala-syntax:search-backward-sexp "\\<try\\>")
- (point)
- (message "matching 'try' not found")
- nil)))))))
+ (let ((anchor
+ (cond ((looking-at "\\<yield\\>")
+ ;; align with 'for'
+ (if (scala-syntax:search-backward-sexp "\\<for\\>")
+ (point)
+ (message "matching 'for' not found")
+ nil))
+ ((looking-at "\\<else\\>")
+ ;; align with 'if' or 'else if'
+ (if (scala-syntax:search-backward-sexp "\\<if\\>")
+ (if (scala-syntax:looking-back-token "\\<else\\>")
+ (goto-char (match-beginning 0))
+ (point))
+ nil))
+ ((looking-at "\\<catch\\>")
+ ;; align with 'try'
+ (if (scala-syntax:search-backward-sexp "\\<try\\>")
+ (point)
+ (message "matching 'try' not found")
+ nil))
+ ((looking-at "\\<finally\\>")
+ ;; align with 'try'
+ (if (scala-syntax:search-backward-sexp "\\<try\\>")
+ (point)
+ (message "matching 'try' not found")
+ nil)))))
+ (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))
+ (point))))))))
+
+(defun scala-indent:resolve-forms-align-step (start anchor)
+ (if scala-indent:align-forms
+ 0
+ ;; TODO: merge to use step calculation
+ 0))
;;;
;;; Lists and enumerators
@@ -432,11 +466,14 @@ symbol, or nil if not."
(backward-list))
(when (scala-syntax:looking-back-token scala-indent:value-keyword-re)
(goto-char (match-beginning 0))
- (if (looking-at "\\<if\\>")
- (if (scala-syntax:looking-back-token "\\<else\\>")
- (match-beginning 0)
- (point))
- (point)))))))
+ (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))
+ (point))))))
(defun scala-indent:goto-body-anchor (&optional point)
(let ((declaration-end (scala-indent:body-p point)))
@@ -623,7 +660,7 @@ 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-special-align-anchor 0)
+ (scala-indent:goto-forms-align-anchor
scala-indent:resolve-forms-align-step)
(scala-indent:goto-list-anchor 0)
(scala-indent:goto-body-anchor scala-indent:resolve-body-step)
(scala-indent:goto-run-on-anchor scala-indent:resolve-run-on-step)
- [nongnu] elpa/scala-mode 347faeb 075/217: Add Evan Meagher to contributors list., (continued)
- [nongnu] elpa/scala-mode 347faeb 075/217: Add Evan Meagher to contributors list., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 081a92b 081/217: scala-indent:remove-indent-from-previous-empty-line, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 0fac9ae 014/217: removed debug messages, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 9476d4c 018/217: Fixes #3: alignment of else inside parens, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3f724ed 030/217: Add the scala-indent:pad-equals setting., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6257e3b 033/217: Renamed bad-equals to indent-value-expression. Added info to README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 4e3a24f 043/217: Updated Examples.md to reflect issues already solved, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 338ff73 060/217: Changed the indent defaults, closes #19, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6c257f6 057/217: Enhanced support for comments and multi-line strings, including, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 68ca175 056/217: Fixes #20, the cons bug (a :: b :: Nil) as well as improving some of, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 78fff40 039/217: scala-indent:align-forms customization variable,
ELPA Syncer <=
- [nongnu] elpa/scala-mode f61e32d 047/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 0991658 051/217: Fixes #17: string syntax, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3174f4c 048/217: Update README.md clone to be a valid command., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a78716d 046/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode ac13b94 061/217: post-self-insert-hooks, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 2201b1c 092/217: Interact nicely with global-font-lock-mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 98d22a5 099/217: Added programming languages to README.md code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 453c012 106/217: fixed bug in string escapes marking, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6116127 042/217: Updated README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 11a710d 044/217: Correct annotation highlighting., ELPA Syncer, 2021/08/29