[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode b55ca83 066/217: Merge pull request #23 from hv
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode b55ca83 066/217: Merge pull request #23 from hvesalai/issue22 |
Date: |
Sun, 29 Aug 2021 11:30:44 -0400 (EDT) |
branch: elpa/scala-mode
commit b55ca8334014202c452c17af232bbcc96ed96ce1
Merge: 95e3742 2f7b335
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Merge pull request #23 from hvesalai/issue22
indent `while` like `if`, `for` et al (fixes #22)
Also fixes indenting of bar in the following example
if (foo)
(1, 2)
else
(2, 3)
bar
---
README.md | 15 +++++++++++++++
scala-mode-indent.el | 27 ++++++++++++++++++++-------
2 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
index d6ae63a..863a7e8 100644
--- a/README.md
+++ b/README.md
@@ -318,6 +318,21 @@ customization variable *frame-background-mode* to *dark*
(use **M-x**
- highlights only properly formatted string and character constants
- indenting a code line removes trailing whitespace
+## Known issues
+
+*do/while* is not always handled correctly. For example:
+
+```scala
+do
+ foo
+while (bar)
+ foo
+```
+
+The indenter thinks the second occurrence of `foo` is the body of the while.
+To work around this, terminate the while with a semicolon,
+or put a blank line after it.
+
## Future work
- syntax-begin-function for reliably fontifying elements which span
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index cb5d6e4..0c95410 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -505,23 +505,36 @@ point or nil if the point is not in a enumerator element
> 1."
;;; Body
;;;
-(defconst scala-indent:value-keyword-re
- (regexp-opt '("if" "else" "yield" "for" "try" "finally" "catch") 'words))
+(defconst scala-indent:control-keywords-cond-re
+ (regexp-opt '("if" "while" "for") 'words)
+ "All the flow control keywords that are followed by a
+condition (or generators in the case of 'for') in parentheses.")
+
+(defconst scala-indent:control-keywords-other-re
+ (regexp-opt '("else" "do" "yield" "try" "finally" "catch") 'words)
+ "Other flow control keywords (not followed by parentheses)")
+
+(defconst scala-indent:control-keywords-re
+ (concat scala-indent:control-keywords-cond-re
+ scala-indent:control-keywords-other-re))
(defun scala-indent:body-p (&optional point)
- "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."
+ "Returns the position of '=' symbol, or one of the
+scala-indent:control-keywords-re or
+scala-indent:control-keywords-cond-re keywords if current
+point (or point 'point) is on a line that follows said symbol or
+keyword, 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)
+ (scala-syntax:looking-back-token
scala-indent:control-keywords-other-re)
(progn
;; if, else if
(when (scala-syntax:looking-back-token ")" 1)
(goto-char (match-end 0))
(backward-list))
- (when (scala-syntax:looking-back-token scala-indent:value-keyword-re)
+ (when (scala-syntax:looking-back-token
scala-indent:control-keywords-cond-re)
(goto-char (match-beginning 0))
(when (and (looking-at "\\<if\\>")
(scala-syntax:looking-back-token "\\<else\\>"))
@@ -534,7 +547,7 @@ follows said symbol, or nil if not."
(let ((declaration-end (scala-indent:body-p point)))
(when declaration-end
(goto-char declaration-end)
- (if (looking-at scala-indent:value-keyword-re)
+ (if (looking-at scala-indent:control-keywords-re)
(point)
(when (scala-indent:backward-sexp-to-beginning-of-line)
(scala-indent:goto-run-on-anchor
- [nongnu] elpa/scala-mode e6967f7 154/217: Add Ivan Malison as a contributor., (continued)
- [nongnu] elpa/scala-mode e6967f7 154/217: Add Ivan Malison as a contributor., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3953269 127/217: Tweaked syntax rules to make highlighting more customizeable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c0842f6 157/217: Use cl functions to avoid mapcan missing error., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d1fbe2d 171/217: Implemented prettify/conceal with a base set of rules. (#108), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 2e8fd35 180/217: Fix for fill-paragraph with prefix arg. Fixes #125. (#126), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 7e63002 182/217: Add "inline" keyword from scalameta (#128), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 1357eba 183/217: Fix for #94, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 730e16d 186/217: Merge pull request #130 from ensime/fix/120, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 1dd5825 085/217: Added comment syntax for bash preambles (#!...!#) in scala script files, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 16d6f36 067/217: Added a not to README about font-lock-doc-face, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode b55ca83 066/217: Merge pull request #23 from hvesalai/issue22,
ELPA Syncer <=
- [nongnu] elpa/scala-mode aa38dae 083/217: Fixes #38: 100% CPU usage for multi-line strings in some cases., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 0af3b07 069/217: Added Makefile and fixed compilation warnings, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode be89855 084/217: Multi-line comment indentation and asterisk-insertion on mid-line return., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 711091a 087/217: moved provides to end of files, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6312b36 082/217: Make the code agreeable to Emacs-Lisp mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 18a52f0 094/217: Update installation instructions, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode a1ea0b7 097/217: Proper instructions and autoload settings for package-based install, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 763c93c 107/217: scala-indent:join-line, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c62ecf9 109/217: Update README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode aea047a 104/217: Create .gitignore with *.elc, ELPA Syncer, 2021/08/29