[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 1650ae5 434/495: Fix multiline case statement inde
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 1650ae5 434/495: Fix multiline case statement indent. |
Date: |
Sat, 7 Aug 2021 09:06:03 -0400 (EDT) |
branch: elpa/go-mode
commit 1650ae5f2343feb313703c4949079ae601fe1bd5
Author: Muir Manders <muir@retailnext.net>
Commit: Peter Sanford <psanford@sanford.io>
Fix multiline case statement indent.
Now that we support commas as dangling operators, expand the
"case foo:" regex to match across lines.
Also handle the case where there is a newline directly after the
"case" keyword. We now don't treat commas as dangling operators in
"case" clause lists.
Fixes #280
---
go-mode.el | 36 ++++++++++++++++++++++++++++++-
test/testdata/indentation_tests/switch.go | 19 ++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/go-mode.el b/go-mode.el
index b5575d2..ca9bd0a 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -643,8 +643,35 @@ current line will be returned."
(not (or
(go--open-paren-position)
(go--in-composite-literal-p)
+ (go--in-case-clause-list-p)
(go--in-struct-definition-p))))
+(defun go--in-case-clause-list-p ()
+ "Return non-nil if inside a multi-line case cause list.
+
+This function is only concerned with list items on lines after the
+case keyword. It returns nil for the case line itself."
+ (save-excursion
+ (beginning-of-line)
+ (when (not (looking-at go--case-or-default-regexp))
+ (let (saw-colon)
+ ;; optionally skip line with the colon
+ (when (looking-at ".*:[[:space:]]*$")
+ (setq saw-colon t)
+ (forward-line -1))
+
+ ;; go backwards while at a comment or a line ending in comma
+ (while (and
+ (or (go-in-comment-p)
+ (looking-at
"[[:space:]]*\\(//\\|/\\*\\)\\|.*,[[:space:]]*$"))
+ (zerop (forward-line -1))))
+
+ (and
+ (looking-at go--case-regexp)
+ ;; we weren't in case list if first line ended in colon
+ ;; and the "case" line ended in colon
+ (not (and saw-colon (looking-at ".*:[[:space:]]*$"))))))))
+
(defun go--in-struct-definition-p ()
"Return non-nil if inside a struct definition."
(save-excursion
@@ -734,6 +761,9 @@ The return value is the position of the opening paren."
(forward-line -1))
(current-indentation)))
+(defconst go--case-regexp "\\([[:space:]]*case\\([[:space:]]\\|$\\)\\)")
+(defconst go--case-or-default-regexp (concat "\\(" go--case-regexp "\\|"
"[[:space:]]*default:\\)"))
+
(defun go-mode-indent-line ()
(interactive)
(let (indent
@@ -745,7 +775,11 @@ The return value is the position of the opening paren."
(if (go-in-string-or-comment-p)
(goto-char point)
(setq indent (go-indentation-at-point))
- (if (looking-at (concat go-label-regexp ":\\([[:space:]]*/.+\\)?$\\|case
.+:\\|default:"))
+ (if (and
+ (looking-at (concat go-label-regexp ":\\([[:space:]]*/.+\\)?$\\|"
go--case-or-default-regexp))
+ ;; don't think last part of multiline case statement is a label
+ (not (go-previous-line-has-dangling-op-p))
+ (not (go--in-case-clause-list-p)))
(cl-decf indent tab-width))
(setq shift-amt (- indent (current-column)))
(if (zerop shift-amt)
diff --git a/test/testdata/indentation_tests/switch.go
b/test/testdata/indentation_tests/switch.go
index 259b293..7d0f972 100644
--- a/test/testdata/indentation_tests/switch.go
+++ b/test/testdata/indentation_tests/switch.go
@@ -3,6 +3,7 @@ package _switch
func main() {
switch "" {
case "foo":
+ label:
code()
case "bar":
case "baz":
@@ -10,4 +11,22 @@ func main() {
default:
code()
}
+
+ switch 123 {
+ case 1, 2,
+ 3:
+ case
+ 1,
+ 3:
+ case
+ // hi
+ "hi",
+ "there":
+ code()
+ case
+ /* hi
+ there */
+ "hi",
+ "there":
+ }
}
- [nongnu] elpa/go-mode d964767 399/495: Use forward-word-strictly when available, (continued)
- [nongnu] elpa/go-mode d964767 399/495: Use forward-word-strictly when available, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7c38d6a 477/495: Improve commenting partial lines., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 24990df 400/495: Some simple style fixes for issues found by checkdoc, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 10d6ab4 486/495: Allow leading spaces for compilation error message, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e79970d 224/495: fix beginning-of-defun for abs(count) > 1, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode cec546c 306/495: Clarify some points in NEWS, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 5c1c546 307/495: Don't fontify parenthesis of multi-line type declaration, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 99b06da 408/495: Describe gofmt-args in the readme and the gofmt docstring (also gofmt-command), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7c50c80 410/495: Always move back to same column after applying rcs patch, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e20a54a 426/495: Speed up go-previous-line-has-dangling-op-p, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1650ae5 434/495: Fix multiline case statement indent.,
ELPA Syncer <=
- [nongnu] elpa/go-mode 1fcf76d 435/495: Fix indentation regexes to be case insensitive, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8796ec6 446/495: indent: fix floating point literal with trailing point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1bbe1d0 451/495: update default go-packages-function to use go list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 50e15c7 457/495: Add major mode for go.mod files: go-dot-mod-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a414da8 465/495: Fontify "font-lock-negation-char-face", ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 1ef3e95 476/495: Fix fontification of single line composite literal., ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode db8284d 485/495: Handle godef "no object" error, ELPA Syncer, 2021/08/07