Skip to content

Commit

Permalink
indent symbols based on whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
LnL7 committed Feb 27, 2016
1 parent 85593b1 commit 5083b7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
18 changes: 13 additions & 5 deletions indent/elixir.vim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set cpo&vim
let s:no_colon_before = ':\@<!'
let s:no_colon_after = ':\@!'
let s:symbols_end = '\]\|}'
let s:symbols_start = '\[\|{'
let s:arrow = '^.*->$'
let s:pipeline = '^\s*|>.*$'
let s:skip_syntax = '\%(Comment\|String\)$'
Expand Down Expand Up @@ -54,12 +55,19 @@ function! GetElixirIndent()
let current_line = getline(v:lnum)
let last_line = getline(lnum)

let splited_line = split(last_line, '\zs')
let split_line = split(last_line, '\zs')
let opened_symbol = 0
let opened_symbol += count(splited_line, '[') - count(splited_line, ']')
let opened_symbol += count(splited_line, '{') - count(splited_line, '}')

let ind += (opened_symbol * &sw)
let opened_symbol += count(split_line, '[') - count(split_line, ']')
let opened_symbol += count(split_line, '{') - count(split_line, '}')

" if start symbol is followed by a character, indent based on the
" whitespace after the symbol, otherwise use the default shiftwidth
if last_line =~ '\('.s:symbols_start.'\).'
let opened_prefix = matchlist(last_line, '\('.s:symbols_start.'\)\s*')[0]
let ind += (opened_symbol * strlen(opened_prefix))
else
let ind += (opened_symbol * &sw)
endif

if last_line =~ '^\s*\('.s:symbols_end.'\)' || last_line =~ s:indent_keywords
let ind += &sw
Expand Down
12 changes: 11 additions & 1 deletion spec/indent/lists_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,20 @@ def test do
.should be_elixir_indentation
end

specify "lists without whitespace" do
<<-EOF
def project do
[{:bar, path: "deps/umbrella/apps/bar"},
{:umbrella, path: "deps/umbrella"}]
end
EOF
.should be_elixir_indentation
end

specify "lists with line break after square brackets" do
<<-EOF
def project do
deps: [
[
{ :bar, path: "deps/umbrella/apps/bar" },
{ :umbrella, path: "deps/umbrella" }
]
Expand Down

0 comments on commit 5083b7d

Please sign in to comment.