annotate runtime/indent/vim.vim @ 3750:536aa8b0c934

Update runtime files.
author Bram Moolenaar <bram@vim.org>
date Wed, 15 Aug 2012 17:43:31 +0200
parents 9cb3a75a20b9
children 47b1887483da
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>
3750
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
4 " Last Change: 2012 Aug 02
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
3557
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
15 let b:undo_indent = "setl indentkeys< indentexpr<"
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
16
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 if exists("*GetVimIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 endif
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2729
diff changeset
21 let s:keepcpo= &cpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2729
diff changeset
22 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 function GetVimIndent()
3750
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
25 let ignorecase_save = &ignorecase
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
26 try
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
27 let &ignorecase = 0
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
28 return GetVimIndentIntern()
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
29 finally
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
30 let &ignorecase = ignorecase_save
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
31 endtry
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
32 endfunc
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
33
536aa8b0c934 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3557
diff changeset
34 function GetVimIndentIntern()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let lnum = prevnonblank(v:lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " If the current line doesn't start with '\' and below a line that starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " with '\', use the indent of the line above it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if getline(v:lnum) !~ '^\s*\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 while lnum > 0 && getline(lnum) =~ '^\s*\\'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " At the start of the file use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 " 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
53 " a line that doesn't (or g:vim_indent_cont if it exists).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\'
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
56 if exists("g:vim_indent_cont")
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
57 let ind = ind + g:vim_indent_cont
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
58 else
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
59 let ind = ind + &sw * 3
cc049b00ee70 updated for version 7.0014
vimboss
parents: 7
diff changeset
60 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 let ind = ind + &sw
2729
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
63 else
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
64 let line = getline(lnum)
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
65 let i = match(line, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>')
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
66 if i >= 0
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
67 let ind += &sw
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
68 if strpart(line, i, 1) == '|' && has('syntax_items')
3557
9cb3a75a20b9 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3526
diff changeset
69 \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$'
2729
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
70 let ind -= &sw
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
71 endif
12f838be9c59 Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents: 395
diff changeset
72 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 " 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
76 " command. And not when there is a backslash before the pipe.
395
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
77 " And when syntax HL is enabled avoid a match inside a string.
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
78 let line = getline(lnum)
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
79 let i = match(line, '[^\\]|\s*\(ene\@!\)')
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
80 if i > 0 && line !~ '^\s*au\%[tocmd]'
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
81 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$'
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
82 let ind = ind - &sw
339c55711247 updated for version 7.0104
vimboss
parents: 333
diff changeset
83 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 " :endfun, :else and :augroup END.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3526
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2729
diff changeset
96 let &cpo = s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2729
diff changeset
97 unlet s:keepcpo
dd6c2497c997 Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2729
diff changeset
98
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 " vim:sw=2