emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 35a5ddc 445/495: indent: fix decl statements with


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 35a5ddc 445/495: indent: fix decl statements with dangling "="
Date: Sat, 7 Aug 2021 09:06:06 -0400 (EDT)

branch: elpa/go-mode
commit 35a5ddc1299371ea0f8f050800944e1c35806cfc
Author: Muir Manders <muir@mnd.rs>
Commit: Peter Sanford <psanford@sanford.io>

    indent: fix decl statements with dangling "="
    
    In "var", "const" and "type" statements, a dangling "=" does not
    indent the following lines. We now test for this case and don't treat
    the "=" as a dangling operator.
    
    var foo =
    // don't indent me
    123
    
    Note that the above is a syntax error without the comment.
---
 go-mode.el                                        |  6 ++-
 test/testdata/indentation_tests/dangling_decls.go | 47 +++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/go-mode.el b/go-mode.el
index 90897b5..18d048c 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -556,7 +556,11 @@ The return value is cached based on the current 
`line-beginning-position'."
   "Return non-nil if current line ends in a dangling operator.
 The return value is not cached."
   (or
-   (go--line-suffix-p go-dangling-operators-regexp)
+   (and
+    (go--line-suffix-p go-dangling-operators-regexp)
+    ;; "=" does not behave like a dangling operator in decl statements.
+    (not (go--line-suffix-p "\\(?:var\\|type\\|const\\)[[:space:]].*=")))
+
    ;; treat comma as dangling operator in certain cases
    (and
     (go--line-suffix-p ",")
diff --git a/test/testdata/indentation_tests/dangling_decls.go 
b/test/testdata/indentation_tests/dangling_decls.go
new file mode 100644
index 0000000..cd4f4d1
--- /dev/null
+++ b/test/testdata/indentation_tests/dangling_decls.go
@@ -0,0 +1,47 @@
+package main
+
+var foo =
+// hello
+123
+
+var foo = 123 +
+       // hello
+       123
+
+const foo =
+// hello
+123
+
+const foo = 123 +
+       // hello
+       123
+
+type foo =
+// hello
+int
+
+func main() {
+       var foo =
+       // hello
+       123
+
+       var foo = 123 +
+               // hello
+               123
+
+       const foo =
+       // hello
+       123
+
+       const foo = 123 +
+               // hello
+               123
+
+       type foo =
+       // hello
+       int
+
+       foo :=
+               // hello
+               123
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]