" indent/go.vim: Vim indent file for Go.
+" - function invocations split across lines
+" - general line splits (line ends in an operator)
-" C indentation is mostly correct
+" C indentation is too far off useful, mainly due to Go's := operator.
+" Let's just define our own.
-" +0 -- Don't indent continuation lines (because Go doesn't use semicolons
-" L0 -- Don't move jump labels (NOTE: this isn't correct when working with
-" gofmt, but it does keep struct literals properly indented.)
-" :0 -- Align case labels with switch statement
-" l1 -- Always align case body relative to case labels
-" J1 -- Indent JSON-style objects (properly indents struct-literals)
-" (0, Ws -- Indent lines inside of unclosed parentheses by one shiftwidth
-" m1 -- Align closing parenthesis line with first non-blank of matching
-" Known issue: Trying to do a multi-line struct literal in a short variable
-" declaration will not indent properly.
+ let prevlnum = prevnonblank(a:lnum-1)
+ " grab the previous and current line, stripping comments.
+ let prevl = substitute(getline(prevlnum), '//.*$', '', '')
+ let thisl = substitute(getline(a:lnum), '//.*$', '', '')
+ let previ = indent(prevlnum)
+ " previous line opened a block
+ if prevl =~# '^\s*\(case .*\|default\):$'
+ " previous line is part of a switch statement
+ " TODO: handle if the previous line is a label.
+ " this line closed a block
+ " We want to outdent if it's part of a switch ("case foo:" or "default:").
+ " We ignore trying to deal with jump labels because (a) they're rare, and
+ " (b) they're hard to disambiguate from a composite literal key.
+ if thisl =~# '^\s*\(case .*\|default\):$'