ref: 77a41acbc02d1a63dd8d1345e3cf1875befd7eaa
parent: c00dc0165d9730b64ae1de42da0bae29c87ee175
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 17 17:14:56 EDT 2015
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
--- a/support/vim/indent/myr.vim
+++ b/support/vim/indent/myr.vim
@@ -6,7 +6,19 @@
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
@@ -13,7 +25,13 @@
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 @@
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 @@
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.