ref: ad3da8e78225fcd945766edbb9bc97a24083b8e1
parent: a1df687064dca2079aff7f1630d050de1e304b2f
author: Ori Bernstein <[email protected]>
date: Tue Jul 14 19:36:23 EDT 2015
Improve indentation script. Simpler code, more consistency in the indentation. We no longer outdent after something like: foo([ ])
--- a/support/vim/indent/myr.vim
+++ b/support/vim/indent/myr.vim
@@ -62,47 +62,42 @@
let curln = getline(ln)
- let inpat = ['\<if\>', '\<elif\>', '\<else\>',
- \ '\<while\>','\<for\>', '\<match\>',
- \ '\<struct\>', '\<union\>',
- \ '{', '\[', '(', '^\s*|.*:', '=\s*$']
- let outpat = ['}', ']', ')']
- let outalone = ['\<else\>', '\<elif\>.*', ';;', '|.*',
- \ '].*', '}.*']
+ let inpat = ['\<if\>', '\<while\>','\<for\>', '\<match\>',
+ \ '\<struct\>', '\<union\>', '{', '\[', '(', '=\s*$']
+ let outpat = ['}', ']', ')', ';;']
+ let outalone = ['].*', ').*', '}.*', ';;']
+ let inoutalone = ['\<else\>', '\<elif\>.*', '|.*']
let width = &tabstop
let n_in = s:CountMatches(prevln, ln - i, inpat)
- let n_out = s:CountMatches(prevln, ln - i, outpat)
+ echo "inpat matches: " n_in
+ if s:LineMatch(prevln, outalone) != 0
+ let n_out = 0
+ else
+ let n_out = s:CountMatches(prevln, ln - i, outpat)
+ endif
+ echo "outpat matches: " n_out
+ let n_in += s:LineMatch(prevln, inoutalone)
+ echo "post-inoutalone in matches: " n_in
+ let n_out += s:LineMatch(curln, outalone)
+ let n_out += s:LineMatch(curln, inoutalone)
+ echo "post-outalone out matches: " n_out
" indent escaped line endings
if prevln =~ '\\\s*$' && getline(ln - i - 1) !~ '\\\s*$'
let n_in = n_in + 1
endif
-
" if we break the set of indented line endings, outdent
if getline(ln - i - 1) =~ '\\\s*$' && getline(ln - i) !~ '\\\s*$'
let n_out = n_out + 1
endif
- " we already outdented if we had an outalone, but since all
- " outpats are also outalones, we don't want to double count.
- if s:LineMatch(prevln, outalone) != 0 && n_out > 0
- let n_out = n_out - 1
- endif
- let n_out = n_out + s:LineMatch(curln, outalone)
-
- let change = 0
- if n_in - n_out > 0
- let change = 1
- elseif n_in - n_out < 0
- let change = -1
- endif
- let ind = ind + change * &tabstop
+ let ind = ind + (n_in - n_out) * &tabstop
endif
return ind
endfunction
-setlocal indentkeys+=,;\|],=elif
+setlocal indentkeys+=,;\|]),=elif,=else
setlocal indentexpr=GetMyrIndent(v:lnum)
let b:did_indent = 1