move indentexpr function to autoload

This commit is contained in:
Dag Odenhall 2013-05-14 19:10:05 +02:00
parent ccebc890ba
commit 11fcbbeeca
2 changed files with 24 additions and 33 deletions

View file

@ -1,3 +1,26 @@
function! fish#Indent()
let l:lnum = prevnonblank(v:lnum - 1)
if l:lnum ==# 0
return 0
endif
let l:ind = 0
if getline(l:lnum) =~# '\v^\s*switch>'
let l:ind = &shiftwidth * 2
elseif getline(l:lnum) =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
let l:ind = &shiftwidth
endif
if getline(v:lnum) =~# '\v^\s*end>'
if l:ind ==# 0
return indent(v:lnum) - &shiftwidth
else
return indent(v:lnum) - l:ind
endif
elseif getline(v:lnum) =~# '\v^\s*%(case|else)>'
return indent(v:lnum) - &shiftwidth
endif
return indent(l:lnum) + l:ind
endfunction
function! fish#Complete(findstart, base)
if a:findstart
if getline('.') =~# '\v^\s*$'

View file

@ -1,34 +1,2 @@
setlocal indentexpr=GetFishIndent()
setlocal indentexpr=fish#Indent()
setlocal indentkeys+==end,=else,=case
if exists('*GetFishIndent')
finish
endif
function GetFishIndent()
let l:lnum = prevnonblank(v:lnum - 1)
if l:lnum ==# 0
return 0
endif
let l:ind = 0
if getline(l:lnum) =~# '\v^\s*switch>'
let l:ind = &shiftwidth * 2
elseif getline(l:lnum) =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
let l:ind = &shiftwidth
endif
if getline(v:lnum) =~# '\v^\s*end>'
if l:ind ==# 0
return indent(v:lnum) - &shiftwidth
else
return indent(v:lnum) - l:ind
endif
elseif getline(v:lnum) =~# '\v^\s*%(case|else)>'
return indent(v:lnum) - &shiftwidth
endif
return indent(l:lnum) + l:ind
endfunction