Skip to content

Commit

Permalink
Keep multiline array literals at same indent.
Browse files Browse the repository at this point in the history
If the current line and the line above both begin with an array literal, align
the current line with the above line.
Resolves JesseKPhillips#26.

Keeps multiline 2D array definitions aligned like so:
auto a = [
  [1, 2, 3],
  [1, 2, 3],
  [1, 2, 3],
];

Previously they were aligned like so:
auto a = [
  [1, 2, 3],
  [1, 2, 3],
    [1, 2, 3],
];
  • Loading branch information
rcorre committed Oct 11, 2015
1 parent f42c43a commit b192ba5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions indent/d.vim
Expand Up @@ -65,5 +65,13 @@ function GetDIndent()
return cindent(lnum - 1)
endif

" Align multiline array literals. e.g.:
" auto a = [
" [ 1, 2, 3 ],
" [ 4, 5, 6 ],
if line =~ '^\s*\[' && getline(lnum - 1) =~ '^\s*\['
return indent(lnum - 1)
endif

return cind
endfunction
10 changes: 10 additions & 0 deletions tests/array.d
@@ -0,0 +1,10 @@
// Nothing should change when you reindent (press =G from the top)

unittest {
auto a = [
[ 1, 2, 3, 4 ],
[ 1, 2, 3, 4 ],
[ 1, 2, 3, 4 ],
[ 1, 2, 3, 4 ],
];
}

0 comments on commit b192ba5

Please sign in to comment.