annotate runtime/indent/vim.vim @ 1685:7015ddf81055 v7.2b.018

updated for version 7.2b-018
author vimboss
date Thu, 24 Jul 2008 18:29:37 +0000
parents 339c55711247
children 12f838be9c59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Vim script
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
395
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
4 " Last Change: 2005 Jul 06
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentexpr=GetVimIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 if exists("*GetVimIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 function GetVimIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " If the current line doesn't start with '\' and below a line that starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " with '\', use the indent of the line above it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 if getline(v:lnum) !~ '^\s*\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 while lnum > 0 && getline(lnum) =~ '^\s*\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " At the start of the file use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " and :else. Add it three times for a line that starts with '\' after
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
39 " a line that doesn't (or g:vim_indent_cont if it exists).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\'
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
42 if exists("g:vim_indent_cont")
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
43 let ind = ind + g:vim_indent_cont
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
44 else
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
45 let ind = ind + &sw * 3
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
46 endif
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 22
diff changeset
47 elseif getline(lnum) =~ '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 " If the previous line contains an "end" after a pipe, but not in an ":au"
333
18f024844150 updated for version 7.0086
vimboss
parents: 170
diff changeset
54 " command. And not when there is a backslash before the pipe.
395
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
55 " And when syntax HL is enabled avoid a match inside a string.
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
56 let line = getline(lnum)
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
57 let i = match(line, '[^\\]|\s*\(ene\@!\)')
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
58 if i > 0 && line !~ '^\s*au\%[tocmd]'
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
59 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$'
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
60 let ind = ind - &sw
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
61 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 " :endfun, :else and :augroup END.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " vim:sw=2