comparison runtime/indent/vim.vim @ 7:3fc0f57ecb91 v7.0001

updated for version 7.0001
author vimboss
date Sun, 13 Jun 2004 20:20:40 +0000
parents
children cc049b00ee70
comparison
equal deleted inserted replaced
6:c2daee826b8f 7:3fc0f57ecb91
1 " Vim indent file
2 " Language: Vim script
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last Change: 2003 May 25
5
6 " Only load this indent file when no other was loaded.
7 if exists("b:did_indent")
8 finish
9 endif
10 let b:did_indent = 1
11
12 setlocal indentexpr=GetVimIndent()
13 setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\
14
15 " Only define the function once.
16 if exists("*GetVimIndent")
17 finish
18 endif
19
20 function GetVimIndent()
21 " Find a non-blank line above the current line.
22 let lnum = prevnonblank(v:lnum - 1)
23
24 " If the current line doesn't start with '\' and below a line that starts
25 " with '\', use the indent of the line above it.
26 if getline(v:lnum) !~ '^\s*\\'
27 while lnum > 0 && getline(lnum) =~ '^\s*\\'
28 let lnum = lnum - 1
29 endwhile
30 endif
31
32 " At the start of the file use zero indent.
33 if lnum == 0
34 return 0
35 endif
36
37 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
38 " and :else. Add it three times for a line that starts with '\' after
39 " a line that doesn't.
40 let ind = indent(lnum)
41 if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\'
42 let ind = ind + &sw * 3
43 elseif getline(lnum) =~ '\(^\||\)\s*\(if\|wh\%[ile]\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>'
44 let ind = ind + &sw
45 elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
46 let ind = ind + &sw
47 endif
48
49 " If the previous line contains an "end" after a pipe, but not in an ":au"
50 " command.
51 if getline(lnum) =~ '|\s*\(ene\@!\)' && getline(lnum) !~ '^\s*au\%[tocmd]'
52 let ind = ind - &sw
53 endif
54
55
56 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry,
57 " :endfun, :else and :augroup END.
58 if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)'
59 let ind = ind - &sw
60 endif
61
62 return ind
63 endfunction
64
65 " vim:sw=2