Mercurial > vim
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 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Vim script | |
3 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
3750 | 4 " Last Change: 2012 Aug 02 |
7 | 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 | |
3557 | 15 let b:undo_indent = "setl indentkeys< indentexpr<" |
16 | |
7 | 17 " Only define the function once. |
18 if exists("*GetVimIndent") | |
19 finish | |
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 | 23 |
24 function GetVimIndent() | |
3750 | 25 let ignorecase_save = &ignorecase |
26 try | |
27 let &ignorecase = 0 | |
28 return GetVimIndentIntern() | |
29 finally | |
30 let &ignorecase = ignorecase_save | |
31 endtry | |
32 endfunc | |
33 | |
34 function GetVimIndentIntern() | |
7 | 35 " Find a non-blank line above the current line. |
36 let lnum = prevnonblank(v:lnum - 1) | |
37 | |
38 " If the current line doesn't start with '\' and below a line that starts | |
39 " with '\', use the indent of the line above it. | |
40 if getline(v:lnum) !~ '^\s*\\' | |
41 while lnum > 0 && getline(lnum) =~ '^\s*\\' | |
42 let lnum = lnum - 1 | |
43 endwhile | |
44 endif | |
45 | |
46 " At the start of the file use zero indent. | |
47 if lnum == 0 | |
48 return 0 | |
49 endif | |
50 | |
51 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function | |
52 " and :else. Add it three times for a line that starts with '\' after | |
22 | 53 " a line that doesn't (or g:vim_indent_cont if it exists). |
7 | 54 let ind = indent(lnum) |
55 if getline(v:lnum) =~ '^\s*\\' && v:lnum > 1 && getline(lnum) !~ '^\s*\\' | |
22 | 56 if exists("g:vim_indent_cont") |
57 let ind = ind + g:vim_indent_cont | |
58 else | |
59 let ind = ind + &sw * 3 | |
60 endif | |
7 | 61 elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END' |
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 | 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 | 73 endif |
74 | |
75 " If the previous line contains an "end" after a pipe, but not in an ":au" | |
333 | 76 " command. And not when there is a backslash before the pipe. |
395 | 77 " And when syntax HL is enabled avoid a match inside a string. |
78 let line = getline(lnum) | |
79 let i = match(line, '[^\\]|\s*\(ene\@!\)') | |
80 if i > 0 && line !~ '^\s*au\%[tocmd]' | |
81 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$' | |
82 let ind = ind - &sw | |
83 endif | |
7 | 84 endif |
85 | |
86 | |
87 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, | |
88 " :endfun, :else and :augroup END. | |
89 if getline(v:lnum) =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s*!\=\s\+END\)' | |
90 let ind = ind - &sw | |
91 endif | |
92 | |
93 return ind | |
94 endfunction | |
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 | 99 " vim:sw=2 |