summaryrefslogtreecommitdiffstats
path: root/indent/elixir.vim
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2016-01-22 09:08:00 +0100
committerAdam Stankiewicz <sheerun@sher.pl>2016-01-22 09:08:00 +0100
commit61390f58850c34b27d2a28dc14ebd760de152cc9 (patch)
treeef4822fc1f712ef0e2bdc50a435d7ef590da4d77 /indent/elixir.vim
parentf8a0fb37bf57fdf705747cc3aacbe50b6b2d6482 (diff)
downloadvim-polyglot-61390f58850c34b27d2a28dc14ebd760de152cc9.tar.gz
vim-polyglot-61390f58850c34b27d2a28dc14ebd760de152cc9.zip
Update
Diffstat (limited to 'indent/elixir.vim')
-rw-r--r--indent/elixir.vim53
1 files changed, 26 insertions, 27 deletions
diff --git a/indent/elixir.vim b/indent/elixir.vim
index 863104d3..58179973 100644
--- a/indent/elixir.vim
+++ b/indent/elixir.vim
@@ -1,10 +1,5 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'elixir') == -1
-" Vim indent file
-" Language: Elixir
-" Maintainer: Carlos Galdino <carloshsgaldino@gmail.com>
-" Last Change: 2013 Apr 24
-
if exists("b:did_indent")
finish
endif
@@ -13,7 +8,7 @@ let b:did_indent = 1
setlocal nosmartindent
setlocal indentexpr=GetElixirIndent()
-setlocal indentkeys+=0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
+setlocal indentkeys+=0),0],0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
if exists("*GetElixirIndent")
finish
@@ -22,17 +17,23 @@ endif
let s:cpo_save = &cpo
set cpo&vim
-let s:skip_syntax = '\%(Comment\|String\)$'
-let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" . s:skip_syntax . "'"
-let s:block_start = 'do\|fn'
-let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
-let s:block_end = 'end'
-let s:symbols_end = '\]\|}'
-let s:arrow = '^.*->$'
-let s:pipeline = '^\s*|>.*$'
+let s:no_colon_before = ':\@<!'
+let s:no_colon_after = ':\@!'
+let s:symbols_end = '\]\|}'
+let s:arrow = '^.*->$'
+let s:pipeline = '^\s*|>.*$'
+let s:skip_syntax = '\%(Comment\|String\)$'
+let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:skip_syntax."'"
+let s:block_start = 'do\|fn'
+let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
+let s:block_end = 'end'
+
+let s:indent_keywords = '\<'.s:no_colon_before.'\%('.s:block_start.'\|'.s:block_middle.'\)$'.'\|'.s:arrow
+let s:deindent_keywords = '^\s*\<\%('.s:block_end.'\|'.s:block_middle.'\)\>'.'\|'.s:arrow
-let s:indent_keywords = '\<\%(' . s:block_start . '\|' . s:block_middle . '\)$' . '\|' . s:arrow
-let s:deindent_keywords = '^\s*\<\%(' . s:block_end . '\|' . s:block_middle . '\)\>' . '\|' . s:arrow
+let s:pair_start = '\<\%('.s:no_colon_before.s:block_start.'\)\>'.s:no_colon_after
+let s:pair_middle = '\<\%('.s:block_middle.'\)\>'.s:no_colon_after.'\zs'
+let s:pair_end = '\<\%('.s:no_colon_before.s:block_end.'\)\>\zs'
function! GetElixirIndent()
let lnum = prevnonblank(v:lnum - 1)
@@ -60,20 +61,16 @@ function! GetElixirIndent()
let opened_symbol += count(splited_line, '[') - count(splited_line, ']')
let opened_symbol += count(splited_line, '{') - count(splited_line, '}')
- let ind += opened_symbol * &sw
+ let ind += (opened_symbol * &sw)
- if last_line =~ '^\s*\(' . s:symbols_end . '\)'
+ if last_line =~ '^\s*\('.s:symbols_end.'\)' || last_line =~ s:indent_keywords
let ind += &sw
endif
- if current_line =~ '^\s*\(' . s:symbols_end . '\)'
+ if current_line =~ '^\s*\('.s:symbols_end.'\)'
let ind -= &sw
endif
- if last_line =~ s:indent_keywords
- let ind += &sw
- endif
-
" if line starts with pipeline
" and last line contains pipeline(s)
" align them
@@ -99,11 +96,13 @@ function! GetElixirIndent()
endif
if current_line =~ s:deindent_keywords
- let bslnum = searchpair( '\<\%(' . s:block_start . '\):\@!\>',
- \ '\<\%(' . s:block_middle . '\):\@!\>\zs',
- \ '\<:\@<!' . s:block_end . '\>\zs',
+ let bslnum = searchpair(
+ \ s:pair_start,
+ \ s:pair_middle,
+ \ s:pair_end,
\ 'nbW',
- \ s:block_skip )
+ \ s:block_skip
+ \ )
let ind = indent(bslnum)
endif