diff options
author | Ori Bernstein <ori@eigenstate.org> | 2015-04-17 21:14:56 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2015-04-17 21:14:56 -0700 |
commit | 77a41acbc02d1a63dd8d1345e3cf1875befd7eaa (patch) | |
tree | 59a8c066f032a12ac2d3478127a544ee90d382eb | |
parent | c00dc0165d9730b64ae1de42da0bae29c87ee175 (diff) | |
download | mc-77a41acbc02d1a63dd8d1345e3cf1875befd7eaa.tar.gz |
Update vim scripts. Don't indent comments.
We used to autoindent like this:
stuff
/* for each thing we .. */
erronously indented
Now we do this:
stuff
/* for each thing */
correctly indented
-rw-r--r-- | support/vim/indent/myr.vim | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/support/vim/indent/myr.vim b/support/vim/indent/myr.vim index 1cd4fa9..b2cf671 100644 --- a/support/vim/indent/myr.vim +++ b/support/vim/indent/myr.vim @@ -6,14 +6,32 @@ if exists("b:did_indent") finish endif -function! s:CountMatches(line, pats) +function! InComment(lnum, col) + let stk = synstack(a:lnum, a:col) + if len(stk) + for id in stk + if synIDattr(id, "name") == "myrComment" + return 1 + endif + endfor + endif + return 0 +endfunction + +function! s:CountMatches(line, lnum, 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 ic = InComment(a:lnum, idx) + if !ic + let matches = matches + 1 + echo "NOT IN COMMENT " ic " lnum " a:lnum " idx " idx + else + echo "IN COMMENT" + endif let idx = idx + strlen(p) endif endwhile @@ -42,9 +60,9 @@ function! GetMyrIndent(ln) while prevln =~ '^\s*$' let prevln = getline(ln - i) let ind = indent(ln - i) - let i = i + 1 endwhile + let i = i - 1 let curln = getline(ln) @@ -56,8 +74,8 @@ function! GetMyrIndent(ln) let outalone = ['\<else\>', '\<elif\>', '}', ';;', '|.*'] let width = &tabstop - let n_in = s:CountMatches(prevln, inpat) - let n_out = s:CountMatches(prevln, outpat) + let n_in = s:CountMatches(prevln, ln - i, inpat) + let n_out = s:CountMatches(prevln, ln - i, outpat) if s:LineMatch(curln, outalone) != 0 let ind = n_in * &tabstop + ind - &tabstop " avoid double-counting outdents from outalones. |