Mercurial > vim
annotate runtime/indent/vim.vim @ 10528:3ea703795a4f v8.0.0154
commit https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 8 14:14:43 2017 +0100
patch 8.0.0154: system() test fails on OS/X
Problem: system() test fails on OS/X.
Solution: Deal with leading spaces.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 08 Jan 2017 14:15:04 +0100 |
parents | 619a98a67f67 |
children | bdbb049c2aa8 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: Vim script | |
3 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
4 " Last Change: 2016 Jun 27 |
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. | |
6238 | 40 let cur_text = getline(v:lnum) |
41 if cur_text !~ '^\s*\\' | |
7 | 42 while lnum > 0 && getline(lnum) =~ '^\s*\\' |
43 let lnum = lnum - 1 | |
44 endwhile | |
45 endif | |
46 | |
47 " At the start of the file use zero indent. | |
48 if lnum == 0 | |
49 return 0 | |
50 endif | |
6238 | 51 let prev_text = getline(lnum) |
7 | 52 |
53 " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function | |
54 " and :else. Add it three times for a line that starts with '\' after | |
22 | 55 " a line that doesn't (or g:vim_indent_cont if it exists). |
7 | 56 let ind = indent(lnum) |
6238 | 57 if cur_text =~ '^\s*\\' && v:lnum > 1 && prev_text !~ '^\s*\\' |
22 | 58 if exists("g:vim_indent_cont") |
59 let ind = ind + g:vim_indent_cont | |
60 else | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
61 let ind = ind + shiftwidth() * 3 |
22 | 62 endif |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
63 elseif prev_text =~ '^\s*aug\%[roup]\s\+' && prev_text !~ '^\s*aug\%[roup]\s\+[eE][nN][dD]\>' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
64 let ind = ind + shiftwidth() |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
65 else |
6238 | 66 " A line starting with :au does not increment/decrement indent. |
67 if prev_text !~ '^\s*au\%[tocmd]' | |
68 let i = match(prev_text, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>') | |
69 if i >= 0 | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
70 let ind += shiftwidth() |
6238 | 71 if strpart(prev_text, i, 1) == '|' && has('syntax_items') |
72 \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$' | |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
73 let ind -= shiftwidth() |
6238 | 74 endif |
2729
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
75 endif |
12f838be9c59
Updated runtime file. Fix Italian translations.
Bram Moolenaar <bram@vim.org>
parents:
395
diff
changeset
|
76 endif |
7 | 77 endif |
78 | |
79 " If the previous line contains an "end" after a pipe, but not in an ":au" | |
333 | 80 " command. And not when there is a backslash before the pipe. |
395 | 81 " And when syntax HL is enabled avoid a match inside a string. |
6238 | 82 let i = match(prev_text, '[^\\]|\s*\(ene\@!\)') |
83 if i > 0 && prev_text !~ '^\s*au\%[tocmd]' | |
395 | 84 if !has('syntax_items') || synIDattr(synID(lnum, i + 2, 1), "name") !~ '\(Comment\|String\)$' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
85 let ind = ind - shiftwidth() |
395 | 86 endif |
7 | 87 endif |
88 | |
89 | |
90 " Subtract a 'shiftwidth' on a :endif, :endwhile, :catch, :finally, :endtry, | |
91 " :endfun, :else and :augroup END. | |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
8951
diff
changeset
|
92 if cur_text =~ '^\s*\(ene\@!\|cat\|fina\|el\|aug\%[roup]\s\+[eE][nN][dD]\)' |
7742
5f6f35a3cb12
commit https://github.com/vim/vim/commit/705ada1aff27ecd9c47c690df817d043c2ceb5e2
Christian Brabandt <cb@256bit.org>
parents:
6447
diff
changeset
|
93 let ind = ind - shiftwidth() |
7 | 94 endif |
95 | |
96 return ind | |
97 endfunction | |
98 | |
3526
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
99 let &cpo = s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
100 unlet s:keepcpo |
dd6c2497c997
Fix more 'cpo' issues in runtime files.
Bram Moolenaar <bram@vim.org>
parents:
2729
diff
changeset
|
101 |
7 | 102 " vim:sw=2 |