Skip to content

Commit c9f5e92

Browse files
muirdmpsanford
authored andcommitted
Fix indentation of chained dangling selectors.
foo. bar. baz Now indents properly as foo. bar. baz Fix by treating period as an operator so it is taken into account by go--continuation-line-indents-p. Period isn't technically a Go operator, but it can be a dangling operator as far as go-mode is concerned. Fixes #346. Closes: #347 [via git-merge-pr]
1 parent 85a20da commit c9f5e92

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

go-mode.el

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,23 +994,26 @@ is done."
994994
indent
995995
(+ indent (current-indentation))))))
996996

997-
(defconst go--operator-chars "*/%<>&\\^+\\-|=!,"
997+
(defconst go--operator-chars "*/%<>&\\^+\\-|=!,."
998998
"Individual characters that appear in operators.
999-
Comma is included because it is sometimes a dangling operator, so
1000-
needs to be considered by `go--continuation-line-indents-p'")
999+
Comma and period are included because they can be dangling operators, so
1000+
they need to be considered by `go--continuation-line-indents-p'")
10011001

10021002
(defun go--operator-precedence (op)
10031003
"Go operator precedence (higher binds tighter).
10041004
1005-
Comma gets the default 0 precedence which is appropriate because commas
1006-
are loose binding expression separators."
1005+
Comma and period are present because they can be dangling
1006+
operators that affect indentation, although they aren't
1007+
technically operators."
10071008
(cl-case (intern op)
1009+
(\. 7) ; "." in "foo.bar", binds tightest
10081010
(! 6)
10091011
((* / % << >> & &^) 5)
10101012
((+ - | ^) 4)
10111013
((== != < <= > >=) 3)
10121014
(&& 2)
10131015
(|| 1)
1016+
(, 0) ; loose binding expression separator
10141017
(t 0)))
10151018

10161019
(defun go--flow-block-p ()

test/testdata/indentation_tests/dangling_operator.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ lol` +
284284
},
285285
}
286286

287+
foo.
288+
bar.
289+
baz.
290+
qux
291+
287292
return 123,
288293
456
289294
}

0 commit comments

Comments
 (0)