annotate runtime/indent/make.vim @ 4109:3b2a771abb39 v7.3.808

updated for version 7.3.808 Problem: Python threads still do not work properly. Solution: Fix both Python 2 and 3. Add tests. (Ken Takata)
author Bram Moolenaar <bram@vim.org>
date Wed, 13 Feb 2013 14:17:08 +0100
parents f58cb9bf1260
children 1218c5353e2b
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
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
2 " Language: Makefile
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
3 " Maintainer: Nikolai Weibull <now@bitwi.se>
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
4 " Latest Revision: 2007-05-07
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 setlocal indentexpr=GetMakeIndent()
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
12 setlocal indentkeys=!^F,o,O,<:>,=else,=endif
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 839
diff changeset
13 setlocal nosmartindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 if exists("*GetMakeIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
19 let s:comment_rx = '^\s*#'
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
20 let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
21 let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)'
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
22 let s:continuation_rx = '\\$'
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
23 let s:assignment_rx = '^\s*\h\w*\s*[+?]\==\s*\zs.*\\$'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
24 let s:folded_assignment_rx = '^\s*\h\w*\s*[+?]\=='
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
25 " TODO: This needs to be a lot more restrictive in what it matches.
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
26 let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
27 let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
28 let s:end_conditional_directive_rx = '^\s*\%(else\|endif\)\>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
30 function s:remove_continuation(line)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
31 return substitute(a:line, s:continuation_rx, "", "")
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
32 endfunction
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
33
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 function GetMakeIndent()
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
35 " TODO: Should this perhaps be v:lnum -1?
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
36 " let prev_lnum = prevnonblank(v:lnum - 1)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
37 let prev_lnum = v:lnum - 1
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
38 if prev_lnum == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 endif
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
41 let prev_line = getline(prev_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
43 let prev_prev_lnum = prev_lnum - 1
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
44 let prev_prev_line = prev_prev_lnum != 0 ? getline(prev_prev_lnum) : ""
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
45
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
46 " TODO: Deal with comments. In comments, continuations aren't interesting.
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
47 if prev_line =~ s:continuation_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
48 if prev_prev_line =~ s:continuation_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
49 return indent(prev_lnum)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
50 elseif prev_line =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
51 return &sw
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
52 elseif prev_line =~ s:assignment_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
53 call cursor(prev_lnum, 1)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
54 if search(s:assignment_rx, 'W') != 0
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
55 return virtcol('.') - 1
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
56 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
57 " TODO: ?
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
58 return &sw
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 839
diff changeset
59 endif
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
60 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
61 " TODO: OK, this might be a continued shell command, so perhaps indent
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
62 " properly here? Leave this out for now, but in the next release this
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
63 " should be using indent/sh.vim somehow.
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
64 "if prev_line =~ '^\t' " s:rule_command_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
65 " if prev_line =~ '^\s\+[@-]\%(if\)\>'
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
66 " return indent(prev_lnum) + 2
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
67 " endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
68 "endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
69 return indent(prev_lnum) + &sw
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 839
diff changeset
70 endif
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
71 elseif prev_prev_line =~ s:continuation_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
72 let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
73 let lnum = prev_prev_lnum - 1
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
74 let line = getline(lnum)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
75 while line =~ s:continuation_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
76 let folded_line = s:remove_continuation(line) . ' ' . folded_line
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
77 let lnum -= 1
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
78 let line = getline(lnum)
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
79 endwhile
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
80 let folded_lnum = lnum + 1
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
81 if folded_line =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
82 if getline(v:lnum) =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
83 return 0
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
84 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
85 return &ts
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
86 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
87 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
88 " elseif folded_line =~ s:folded_assignment_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
89 if getline(v:lnum) =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
90 return 0
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
91 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
92 return indent(folded_lnum)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
93 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
94 " else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
95 " " TODO: ?
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
96 " return indent(prev_lnum)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
97 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
98 elseif prev_line =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
99 if getline(v:lnum) =~ s:rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
100 return 0
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
101 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
102 return &ts
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
103 endif
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
104 elseif prev_line =~ s:conditional_directive_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
105 return &sw
839
1f3b1021f002 updated for version 7.0e05
vimboss
parents: 375
diff changeset
106 else
1200
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
107 let line = getline(v:lnum)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
108 if line =~ s:just_inserted_rule_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
109 return 0
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
110 elseif line =~ s:end_conditional_directive_rx
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
111 return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - &sw
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
112 else
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
113 return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1)
f58cb9bf1260 updated for version 7.1b
vimboss
parents: 856
diff changeset
114 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 endfunction