" Vim indent file, another yet!
" Language: Eiffel
" Maintainer: Huang Liang <huangl@tfol.net>
" Ref Maintainer: Jocelyn Fiat <eiffel@djoce.net>
" Previous-Maintainer: David Clarke <gadicath@dishevelled.net>
" $Date: 2006/12/28 21:33:52 $
" $Revision: 1.0 $
" URL: http://www.djoce.net/page/vim/
" Last Change: 2006 dec 28 : rewrite the indent rule
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
"finish
endif
let b:did_indent = 2
setlocal indentexpr=GetEiffelIndent()
setlocal nolisp
setlocal nosmartindent
setlocal nocindent
setlocal autoindent
setlocal comments=:--
setlocal indentkeys=o
setlocal indentkeys+==end,=else,=ensure,=require,=check,=loop,=until
setlocal indentkeys+==creation,=feature,=inherit,=insert, =class,=is,=redefine,=rename,=variant
setlocal indentkeys+==invariant,=do,=local,=export,=indexing
" Define some stuff
" keywords grouped by indenting
let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$'
let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|insert\|loop\|from\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|once\|external\|alias\|local\|invariant\|variant\|rename\|redefine\|export\)\>'
let s:outdent = '^\s*\(else\|invariant\|variant\|do\|once\|external\|alias\|require\|ensure\|until\|loop\|local\)\>'
let s:no_indent = '^\s*\(\(\(\w\+ \)\?class\)\|feature\|creation\|inherit\|insert\|indexing\)\>'
let s:single_dent = '.*is\s*\(--.*\)\=$'
let s:inheritance_dent = '\s*\(redefine\|rename\|export\)\>'
" Only define the function once.
if exists("*GetEiffelIndent")
"finish
endif
function! s:GetPrevNonCommentLineNum( line_num )
" Skip lines starting with a comment
let SKIP_LINES = '^\s*--.*$'
let nline = a:line_num
while nline > 0
let nline = prevnonblank(nline-1)
if getline(nline) !~? SKIP_LINES
break
endif
endwhile
return nline
endfunction
function! GetEiffelIndent()
" Eiffel Class indenting
"
"
if v:lnum == 0
return 0
endif
let this_codeline = getline( v:lnum)
" The following should always be at the start of a line, no indenting
" Section word : class, feature, creation, inherit, insert, create, indexing
if this_codeline =~ s:no_indent
return 0
endif
" Indent to single indent
if this_codeline =~ s:single_dent && this_codeline !~ '\s*\<\(and\|or\|implies\)\>'
return &sw
endif
" Indent to double indent
if this_codeline =~ s:inheritance_dent
return 2 * &sw
endif
" Find a non-blank/non-comment line above the current line.
let prev_codeline_num = s:GetPrevNonCommentLineNum(v:lnum)
let prev_codeline = getline(prev_codeline_num)
let ind = indent(prev_codeline_num)
if this_codeline =~ s:outdent
if prev_codeline =~ s:single_dent
return 2 * &sw
endif
" Subtract a 'shiftwidth', if this isn't the first thing after the 'is'
" or first thing after the 'do'
if prev_codeline !~ '^\s*do\>' && prev_codeline !~ s:relative_indent
return ind - &sw
endif
return ind
endif
" Subtract a shiftwidth for end "statements
if this_codeline =~ '^\s*end\>'
let this_ind = indent(v:lnum)
if this_ind > &sw
return ind - &sw
else
return this_ind
endif
endif
" Indent line after the first line of the function definition
if prev_codeline =~ s:single_dent
return ind + 2 * &sw
endif
" Add a 'shiftwidth' after lines that start with an indent word
if prev_codeline =~ s:relative_indent
return ind + &sw
endif
if prev_codeline =~ s:no_indent
return &sw
endif
return ind
" trust the user's indenting
"if prev_codeline =~ s:trust_user_indent
" return -1
"endif
endfunction
" vim:sw=2
正文
Vim indent file, another yet!2006-12-29 15:34:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/nothing/22049.html
阅读(3816) | 评论(1)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论