diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-04-17 14:59:49 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-04-17 15:16:28 -0700 |
commit | 8b5f4cf211ff980f796058bef0ec1696e894b033 (patch) | |
tree | b7860b82caeacbe986cbcd4b503c7b85d76b23b5 /support/vim/indent | |
parent | bc529a54b673dfe0769f6f139dc85e440b8051cf (diff) | |
download | mc-8b5f4cf211ff980f796058bef0ec1696e894b033.tar.gz |
Add vim support files.
Diffstat (limited to 'support/vim/indent')
-rw-r--r-- | support/vim/indent/mbld.vim | 54 | ||||
-rw-r--r-- | support/vim/indent/myr.vim | 74 |
2 files changed, 128 insertions, 0 deletions
diff --git a/support/vim/indent/mbld.vim b/support/vim/indent/mbld.vim new file mode 100644 index 0000000..acf3d5e --- /dev/null +++ b/support/vim/indent/mbld.vim @@ -0,0 +1,54 @@ +" Vim Indentation file +" Language: Myrddin +" Maintainer: Ori Bernstein + +if exists("b:did_indent") + finish +endif + +function! s:CheckMatch(line, pats) + for p in a:pats + let idx = match(a:line, p) + if idx >= 0 + return 1 + endif + endfor + return 0 +endfunction + + +function! GetMbldIndent(ln) + let ln = a:ln + + if ln == 1 + let ind = 0 + else + let i = 1 + let prevln = '' + while prevln =~ '^\s*$' + let prevln = getline(ln - i) + let ind = indent(ln - i) + let i = i + 1 + endwhile + echo "IND IS " ind + let curln = getline(ln) + let inpat = ['^\s*\<bin\>', '^\s*\<lib\>', + \'^\s*\<gen\>', '^\s*\<test\>', + \'^\s*\<man\>', '^\s*\<sub\>'] + let level = 0 + if s:CheckMatch(prevln, inpat) + let level = level + 1 + endif + + if match(curln, ';;\s*$') > 0 + let level = level - 1 + endif + echo "TABSTOP IS " &tabstop + let ind = ind + (level * &tabstop) + endif + return ind +endfunction + +setlocal indentkeys+=,; +setlocal indentexpr=GetMbldIndent(v:lnum) +let b:did_indent = 1 diff --git a/support/vim/indent/myr.vim b/support/vim/indent/myr.vim new file mode 100644 index 0000000..1cd4fa9 --- /dev/null +++ b/support/vim/indent/myr.vim @@ -0,0 +1,74 @@ +" Vim Indentation file +" Language: Myrddin +" Maintainer: Ori Bernstein + +if exists("b:did_indent") + finish +endif + +function! s:CountMatches(line, pats) + let matches = 0 + for p in a:pats + let idx = 0 + while idx >= 0 + let idx = match(a:line, p, idx) + if idx >= 0 + let matches = matches + 1 + let idx = idx + strlen(p) + endif + endwhile + endfor + return matches +endfunction + +function! s:LineMatch(line, pats) + for p in a:pats + let pat = '^\s*'.p.'\s*$' + if match(a:line, pat, 0) >= 0 + return 1 + endif + endfor + return 0 +endfunction + +function! GetMyrIndent(ln) + let ln = a:ln + + if ln == 1 + let ind = 0 + else + let i = 1 + let prevln = '' + while prevln =~ '^\s*$' + let prevln = getline(ln - i) + let ind = indent(ln - i) + + let i = i + 1 + endwhile + + let curln = getline(ln) + + let inpat = ['\<if\>', '\<elif\>', '\<else\>', + \ '\<while\>','\<for\>', '\<match\>', + \ '\<struct\>', '\<union\>', + \ '{', '^\s*|', '=\s*$'] + let outpat = ['}', ';;'] + let outalone = ['\<else\>', '\<elif\>', '}', ';;', '|.*'] + let width = &tabstop + + let n_in = s:CountMatches(prevln, inpat) + let n_out = s:CountMatches(prevln, outpat) + if s:LineMatch(curln, outalone) != 0 + let ind = n_in * &tabstop + ind - &tabstop + " avoid double-counting outdents from outalones. + elseif s:LineMatch(prevln, outpat) == 0 + let ind = ind + (n_in - n_out) * &tabstop + endif + endif + return ind +endfunction + +setlocal indentkeys+=,;\|,=elif +setlocal indentexpr=GetMyrIndent(v:lnum) + +let b:did_indent = 1 |