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

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

[nongnu] elpa/go-mode 6d58e9d 442/495: indent: fix case statement in fun


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 6d58e9d 442/495: indent: fix case statement in func in composite literal
Date: Sat, 7 Aug 2021 09:06:05 -0400 (EDT)

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

    indent: fix case statement in func in composite literal
    
    Our composite literal detection wasn't working in cases like:
    
    Foo{
      Bar: func() {
        switch {
          case qux: // indents too far here
    
    We thought the "func" open curly was a composite literal curly with
    implicit type. Fix by tweaking the logic to instead check that the
    open curly is preceded by nothing, a comma, or a colon.
    
    Closes: #293 [via git-merge-pr]
---
 go-mode.el                                           | 13 +++++++++----
 test/testdata/indentation_tests/composite_literal.go | 13 +++++++++++++
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 3bbe162..089b220 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -616,15 +616,20 @@ case keyword. It returns nil for the case line itself."
     (and
      (go-goto-opening-parenthesis)
 
-     ;; opening paren-like character is curly
+     ;; Opening paren-like character is a curly.
      (eq (char-after) ?{)
 
      (or
-      ;; preceded by non space (e.g. "Foo|{")
+      ;; Curly is preceded by non space (e.g. "Foo|{").
       (not (looking-back "[[:space:]]" (1- (point))))
 
-      ;; or curly itself is in a composite literal (e.g. "Foo{|{")
-      (go--in-composite-literal-p)))))
+      (and
+       (progn (skip-syntax-backward " ") t)
+
+       ;; Curly looks like a composite literal with implicit type
+       ;; name. In particular, the curly is the first character on the
+       ;; line or the previous character is a comma or colon.
+       (or (bolp) (looking-back "[,:]" (1- (point)))))))))
 
 (defun go--open-paren-position ()
   "Return non-nil if point is between '(' and ')'.
diff --git a/test/testdata/indentation_tests/composite_literal.go 
b/test/testdata/indentation_tests/composite_literal.go
index b20d832..d1b1edf 100644
--- a/test/testdata/indentation_tests/composite_literal.go
+++ b/test/testdata/indentation_tests/composite_literal.go
@@ -18,4 +18,17 @@ func _() {
                        println("there")
                },
        }
+
+       Foo{
+               Bar: func() {
+                       switch {
+                       case baz:
+                       }
+               },
+
+               "bar": {
+                       "foo",
+                       "bar",
+               },
+       }
 }



reply via email to

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