comparison runtime/indent/make.vim @ 856:8cd729851562 v7.0g

updated for version 7.0g
author vimboss
date Sun, 30 Apr 2006 18:54:39 +0000
parents d3bbb5dd3913
children f58cb9bf1260
comparison
equal deleted inserted replaced
855:d2a4f08396fe 856:8cd729851562
1 " Vim indent file 1 " Vim indent file
2 " Language: Makefile 2 " Language: Makefile
3 " Maintainer: Nikolai Weibull <now@bitwi.se> 3 " Maintainer: Nikolai Weibull <now@bitwi.se>
4 " Latest Revision: 2006-04-26 4 " Latest Revision: 2006-04-26
5 5
6 if exists("b:did_indent") 6 if exists("b:did_indent")
7 finish 7 finish
8 endif 8 endif
20 let s:continuation_rx = '\\$' 20 let s:continuation_rx = '\\$'
21 let s:assignment_rx = '^\s*\h\w*\s*+\==\s*\zs.*\\$' 21 let s:assignment_rx = '^\s*\h\w*\s*+\==\s*\zs.*\\$'
22 22
23 " TODO: Deal with comments, string, and all kinds of other crap, e.g., defines. 23 " TODO: Deal with comments, string, and all kinds of other crap, e.g., defines.
24 " TODO: Unwrap the whole logic of this function into something that requires a 24 " TODO: Unwrap the whole logic of this function into something that requires a
25 " lot less “return”s. 25 " lot less 'return's.
26 function GetMakeIndent() 26 function GetMakeIndent()
27 let lnum = v:lnum - 1 27 let lnum = v:lnum - 1
28 if lnum == 0 28 if lnum == 0
29 return 0 29 return 0
30 endif 30 endif
31 31
32 " Figure out if the previous line is part of a rule or not. If it is, then 32 " Figure out if the previous line is part of a rule or not. If it is, then
33 " we more or less just indent by a ‘tabstop’, the previous’ lines indent, or 33 " we more or less just indent by a 'tabstop', the previous' lines indent, or
34 " remove all indent if the current line is itself a rule. Also, if the line 34 " remove all indent if the current line is itself a rule. Also, if the line
35 " in question is part of a continuation-line set constituting the rule line 35 " in question is part of a continuation-line set constituting the rule line
36 " itself, we indent by either a ‘shiftwidth’, if the line is the first in the 36 " itself, we indent by either a 'shiftwidth', if the line is the first in the
37 " continuation, or use the indent of the previous line, if not. 37 " continuation, or use the indent of the previous line, if not.
38 while lnum > 0 38 while lnum > 0
39 let line = getline(lnum) 39 let line = getline(lnum)
40 if line[0] != "\t" 40 if line[0] != "\t"
41 " We found a non-shell-command line, i.e., one that doesn’t have a 41 " We found a non-shell-command line, i.e., one that doesn't have a
42 " leading tab. 42 " leading tab.
43 if line =~ s:rule_rx 43 if line =~ s:rule_rx
44 " The line looks like a rule line, so we must therefore either be inside a 44 " The line looks like a rule line, so we must therefore either be inside a
45 " rule or we are a continuation line to that rule line. 45 " rule or we are a continuation line to that rule line.
46 if line =~ s:continuation_rx 46 if line =~ s:continuation_rx
47 " Ah, the rule line was continued, so look up the last continuation 47 " Ah, the rule line was continued, so look up the last continuation
48 " line that’s above the current line. 48 " line that's above the current line.
49 while line =~ s:continuation_rx && lnum < v:lnum 49 while line =~ s:continuation_rx && lnum < v:lnum
50 let lnum += 1 50 let lnum += 1
51 let line = getline(lnum) 51 let line = getline(lnum)
52 endwhile 52 endwhile
53 let lnum -= 1 53 let lnum -= 1
54 let line = getline(lnum) 54 let line = getline(lnum)
55 endif 55 endif
56 56
57 " If the line that we’ve found is right above the current line, deal 57 " If the line that we've found is right above the current line, deal
58 " with it specifically. 58 " with it specifically.
59 if lnum == v:lnum - 1 59 if lnum == v:lnum - 1
60 " If it was continued, indent the current line by a shiftwidth, as it 60 " If it was continued, indent the current line by a shiftwidth, as it
61 " is the first to follow it. Otherwise, depending on if the current 61 " is the first to follow it. Otherwise, depending on if the current
62 " line is a rule line, i.e, a rule line following another rule line, 62 " line is a rule line, i.e, a rule line following another rule line,
63 " then indent to the left margin. Otherwise, the current line is the 63 " then indent to the left margin. Otherwise, the current line is the
64 " first shell-command line in the rule, so indent by a ‘tabstop’ 64 " first shell-command line in the rule, so indent by a 'tabstop'
65 if line =~ s:continuation_rx 65 if line =~ s:continuation_rx
66 return &sw 66 return &sw
67 else 67 else
68 return getline(v:lnum) =~ s:rule_rx ? 0 : &ts 68 return getline(v:lnum) =~ s:rule_rx ? 0 : &ts
69 endif 69 endif
70 else 70 else
71 " If the previous line was a continuation line, then unless it was 71 " If the previous line was a continuation line, then unless it was
72 " itself a part of a continuation line, add a ‘shiftwidth’’s worth of 72 " itself a part of a continuation line, add a 'shiftwidth''s worth of
73 " indent. Otherwise, just use the indent of the previous line. 73 " indent. Otherwise, just use the indent of the previous line.
74 " Otherwise, if the previous line wasn’t a continuation line, check 74 " Otherwise, if the previous line wasn't a continuation line, check
75 " if the one above it was. If it was then indent to whatever level 75 " if the one above it was. If it was then indent to whatever level
76 " the “owning” line had. Otherwise, indent to the previous line’s 76 " the 'owning' line had. Otherwise, indent to the previous line's
77 " level. 77 " level.
78 let lnum = v:lnum - 1 78 let lnum = v:lnum - 1
79 let line = getline(lnum) 79 let line = getline(lnum)
80 if line =~ s:continuation_rx 80 if line =~ s:continuation_rx
81 let pnum = v:lnum - 2 81 let pnum = v:lnum - 2
82 let pine = getline(pnum) 82 let pine = getline(pnum)
83 if pine =~ s:continuation_rx 83 if pine =~ s:continuation_rx
84 return indent(lnum) 84 return indent(lnum)
85 else 85 else
86 return indent(lnum) + &sw 86 return indent(lnum) + &sw
87 endif 87 endif
88 else 88 else
89 let lnum = v:lnum - 2 89 let lnum = v:lnum - 2
90 let line = getline(lnum) 90 let line = getline(lnum)
91 if line =~ s:continuation_rx 91 if line =~ s:continuation_rx
92 while lnum > 0 92 while lnum > 0
93 if line !~ s:continuation_rx 93 if line !~ s:continuation_rx
94 let lnum += 1 94 let lnum += 1
95 let line = getline(lnum) 95 let line = getline(lnum)
96 break 96 break
97 endif 97 endif
98 let lnum -= 1 98 let lnum -= 1
99 let line = getline(lnum) 99 let line = getline(lnum)
100 endwhile 100 endwhile
101 " We’ve found the owning line. Indent to it’s level. 101 " We've found the owning line. Indent to it's level.
102 return indent(lnum) 102 return indent(lnum)
103 else 103 else
104 return indent(v:lnum - 1) 104 return indent(v:lnum - 1)
105 endif 105 endif
106 endif 106 endif
107 endif 107 endif
108 endif 108 endif
109 109
110 " The line wasn’t a rule line, so the current line is part of a series 110 " The line wasn't a rule line, so the current line is part of a series
111 " of tab-indented lines that don’t belong to any rule. 111 " of tab-indented lines that don't belong to any rule.
112 break 112 break
113 endif 113 endif
114 let lnum -= 1 114 let lnum -= 1
115 endwhile 115 endwhile
116 116
117 " If the line before the one we are currently indenting ended with a 117 " If the line before the one we are currently indenting ended with a
118 " continuation, then try to figure out what “owns” that line and indent 118 " continuation, then try to figure out what 'owns' that line and indent
119 " appropriately. 119 " appropriately.
120 let lnum = v:lnum - 1 120 let lnum = v:lnum - 1
121 let line = getline(lnum) 121 let line = getline(lnum)
122 if line =~ s:continuation_rx 122 if line =~ s:continuation_rx
123 let indent = indent(lnum) 123 let indent = indent(lnum)
124 if line =~ s:assignment_rx 124 if line =~ s:assignment_rx
125 " The previous line is a continuation line that begins a variable- 125 " The previous line is a continuation line that begins a variable-
126 " assignment expression, so set the indent to just beyond the whitespace 126 " assignment expression, so set the indent to just beyond the whitespace
127 " following the assignment operator (‘=’). 127 " following the assignment operator ('=').
128 call cursor(lnum, 1) 128 call cursor(lnum, 1)
129 if search(s:assignment_rx, 'W') != 0 129 if search(s:assignment_rx, 'W') != 0
130 let indent = virtcol('.') - 1 130 let indent = virtcol('.') - 1
131 endif 131 endif
132 endif 132 endif
133 133
134 " The previous line didn’t constitute an assignment, so just indent to 134 " The previous line didn't constitute an assignment, so just indent to
135 " whatever level it had. 135 " whatever level it had.
136 return indent 136 return indent
137 endif 137 endif
138 138
139 " If the line above the line above the current line ended was continued, 139 " If the line above the line above the current line ended was continued,
140 " then the line above the current line was part of a continued line. Find 140 " then the line above the current line was part of a continued line. Find
141 " the “owning” line and indent to its level. 141 " the 'owning' line and indent to its level.
142 let lnum = v:lnum - 2 142 let lnum = v:lnum - 2
143 let line = getline(lnum) 143 let line = getline(lnum)
144 if line =~ s:continuation_rx 144 if line =~ s:continuation_rx
145 while lnum > 0 145 while lnum > 0
146 if line !~ s:continuation_rx 146 if line !~ s:continuation_rx
147 let lnum += 1 147 let lnum += 1
148 let line = getline(lnum) 148 let line = getline(lnum)
149 break 149 break
150 endif 150 endif
151 let lnum -= 1 151 let lnum -= 1
152 let line = getline(lnum) 152 let line = getline(lnum)
153 endwhile 153 endwhile
154 " We’ve found the owning line. Indent to it’s level. 154 " We've found the owning line. Indent to it's level.
155 return indent(lnum) 155 return indent(lnum)
156 endif 156 endif
157 157
158 " If nothing else caught on, then check if this line is a rule line. If it 158 " If nothing else caught on, then check if this line is a rule line. If it
159 " is, indent it to the left margin. Otherwise, simply use the indent of the 159 " is, indent it to the left margin. Otherwise, simply use the indent of the