> > But it still doesn't indentRfiles correctly. See an indented result
> > below. Can somebody fix the bug in the indentation file forRand add
> > it in future version ofvim?
>
> There is also:http://www.vim.org/scripts/script.php?script_id=2628
>
> And some other files.
>
> I personally use this version:
>
> setlocal indentexpr=GetRIndent()
>
> if exists("*GetRIndent")
> finish
> endif
>
> let s:r_keywords_plus='\<\(if\|while\|for\)\>'
> let s:r_keywords_minus='\<\(else\)\>'
>
> fun! GetRIndent()
> " Find a non-blank line above the current line.
> let lnum = prevnonblank(v:lnum - 1)
>
> " At the start of the file use zero indent.
> if lnum == 0
> return 0
> endif
>
> let ind = indent(lnum)
> let line = getline(lnum) " last line
>
> let cnum = v:lnum
> let cind = indent(cnum)
> let cline = getline(cnum)
> if cline =~ '^\s*#'
> return ind
> endif
>
> let lplus = (line =~ s:r_keywords_plus)
> if cline =~ s:r_keywords_minus
> if lplus
> return ind
> else
> return ind - &sw
> endif
> endif
>
> let cnt = <SID>Count(line, '[[{(]', '[])}]')
> let lrest = s:rest
> if cnt > 0
> return ind + &sw
> endif
>
> let cnt = <SID>Count(cline, '[[{(]', '[])}]')
> let crest = s:rest
> if cnt < 0
> return ind - &sw
> endif
>
> if lplus && lrest == ''
> return ind + &sw
> endif
>
> " Match things like:
> " if (ok)
> " do(something)
> " But don't match:
> " if (ok) do(something)
> let prev = prevnonblank(lnum - 1)
> if prev > 0
> let pline = getline(prev)
> let pplus = (pline =~ s:r_keywords_plus)
> if pplus
> let pcnt = <SID>Count(pline, '[[{(]', '[])}]')
> if pcnt == 0 && s:rest == ''
> return ind - &sw
> endif
> endif
> endif
>
> return ind
> endf
>
> fun! <SID>Count(str, rx_open, rx_close)
> let s:cnt = 0
> let s:pcnt = 0
> let str = substitute(a:str, '^.\{-}\ze'. a:rx_open, '', '')
> let str = substitute(str, a:rx_open, "\\=<SID>Count1(submatch
> (0))", 'g')
> let co = s:cnt
> let p = s:pcnt
> let s:cnt = 0
> let s:pcnt = 0
> let str = substitute(str, a:rx_close, "\\=<SID>Count1(submatch(0),
> ". p .")", 'g')
> let sep = stridx(str, "
> ")
> if sep >= 0
> let s:rest = strpart(str, sep + 1)
> endif
> if s:rest !~ '\S'
> let s:rest = ''
> endif
> let cc = s:cnt
> return co - cc
> endf
>
> fun! <SID>Count1(match, ...)
> let s:cnt = s:cnt + 1
> if a:match =~ '[()]'
> let s:pcnt = s:pcnt + 1
> if a:0 >= 1 && s:pcnt == a:1
> return a:match ."\n"
> endif
> endif
> return a:match
> endf
I put the above code in my ~/.vim/indent/r.vim file. But vim still can
not correctly indent, for example, the following file. Can somebody
take a look what the problem is?
Regards,
Peng
$ cat whatcdf.R
library(makecdfenv)
for (f in list.celfiles()) {
pname=cleancdfname(whatcdf(f))
print(pname)
}
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment