annotate runtime/indent/awk.vim @ 19789:25836c21ccf9 v8.2.0451

patch 8.2.0451: Win32: double-width character displayed incorrectly Commit: https://github.com/vim/vim/commit/82e743c5b343847d88b958594ad3433213ef9405 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 26 15:39:53 2020 +0100 patch 8.2.0451: Win32: double-width character displayed incorrectly Problem: Win32: double-width character displayed incorrectly. Solution: First move the cursor to the first column. (Nobuhiro Takasaki, closes #5848)
author Bram Moolenaar <Bram@vim.org>
date Thu, 26 Mar 2020 15:45:03 +0100
parents 1eaf34420bb3
children 6dd88e45d47d
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: set sw=3 sts=3:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Awk indent script. It can handle multi-line statements and expressions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " It works up to the point where the distinction between correct/incorrect
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " and personal taste gets fuzzy. Drop me an e-mail for bug reports and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " reasonable style suggestions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " Bugs:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " =====
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " - Some syntax errors may cause erratic indentation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " - Same for very unusual but syntacticly correct use of { }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " - In some cases it's confused by the use of ( and { in strings constants
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " - This version likes the closing brace of a multiline pattern-action be on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 " character position 1 before the following pattern-action combination is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " formatted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " Author:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " =======
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " Erik Janssen, ejanssen@itmatters.nl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " History:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " ========
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " 26-04-2002 Got initial version working reasonably well
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " 29-04-2002 Fixed problems in function headers and max line width
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " Added support for two-line if's without curly braces
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
26 " Fixed hang: 2011 Aug 31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 setlocal indentexpr=GetAwkIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " Mmm, copied from the tcl indent program. Is this okay?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 setlocal indentkeys-=:,0#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if exists("*GetAwkIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 " This function contains a lot of exit points. It checks for simple cases
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " first to get out of the function as soon as possible, thereby reducing the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " number of possibilities later on in the difficult parts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 function! GetAwkIndent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
16610
1eaf34420bb3 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
50 " Find previous line and get its indentation
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 let prev_lineno = s:Get_prev_line( v:lnum )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 if prev_lineno == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 let prev_data = getline( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 let ind = indent( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " Increase indent if the previous line contains an opening brace. Search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 " for this brace the hard way to prevent errors if the previous line is a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 " 'pattern { action }' (simple check match on /{/ increases the indent then)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 if s:Get_brace_balance( prev_data, '{', '}' ) > 0
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 3099
diff changeset
63 return ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 let brace_balance = s:Get_brace_balance( prev_data, '(', ')' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 " If prev line has positive brace_balance and starts with a word (keyword
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 " or function name), align the current line on the first '(' of the prev
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 if brace_balance > 0 && s:Starts_with_word( prev_data )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " If this line starts with an open brace bail out now before the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " continuation checks.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 if getline( v:lnum ) =~ '^\s*{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 " If prev line seems to be part of multiline statement:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 " 1. Prev line is first line of a multiline statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 " -> attempt to indent on first ' ' or '(' of prev line, just like we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 " indented the positive brace balance case above
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 " 2. Prev line is not first line of a multiline statement
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 " -> copy indent of prev line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let continue_mode = s:Seems_continuing( prev_data )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 if continue_mode > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 if s:Seems_continuing( getline(s:Get_prev_line( prev_lineno )) )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 " Case 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " Case 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if continue_mode == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 " Need continuation due to comma, backslash, etc
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 " if/for/while without '{'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 3099
diff changeset
102 return ind + shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 " If the previous line doesn't need continuation on the current line we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 " on the start of a new statement. We have to make sure we align with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 " previous statement instead of just the previous line. This is a bit
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 " complicated because the previous statement might be multi-line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " The start of a multiline statement can be found by:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 " 1 If the previous line contains closing braces and has negative brace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 " balance, search backwards until cumulative brace balance becomes zero,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 " take indent of that line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 " 2 If the line before the previous needs continuation search backward
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 " until that's not the case anymore. Take indent of one line down.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 " Case 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 if prev_data =~ ')' && brace_balance < 0
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 7
diff changeset
122 while brace_balance != 0 && prev_lineno > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 let prev_lineno = s:Get_prev_line( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 let prev_data = getline( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 let brace_balance=brace_balance+s:Get_brace_balance(prev_data,'(',')' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 let ind = indent( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 " Case 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 if s:Seems_continuing( getline( prev_lineno - 1 ) )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 let prev_lineno = prev_lineno - 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 let prev_data = getline( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 while prev_lineno > 0 && (s:Seems_continuing( prev_data ) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 let prev_lineno = s:Get_prev_line( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 let prev_data = getline( prev_lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 let ind = indent( prev_lineno + 1 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 " Decrease indent if this line contains a '}'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 if getline(v:lnum) =~ '^\s*}'
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 3099
diff changeset
143 let ind = ind - shiftwidth()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 " Find the open and close braces in this line and return how many more open-
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 " than close braces there are. It's also used to determine cumulative balance
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 " across multiple lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 function! s:Get_brace_balance( line, b_open, b_close )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 let line2 = substitute( a:line, a:b_open, "", "g" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 let openb = strlen( a:line ) - strlen( line2 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 let line3 = substitute( line2, a:b_close, "", "g" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 let closeb = strlen( line2 ) - strlen( line3 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 return openb - closeb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 " Find out whether the line starts with a word (i.e. keyword or function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 " call). Might need enhancements here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 function! s:Starts_with_word( line )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 if a:line =~ '^\s*[a-zA-Z_0-9]\+\s*('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 " Find the length of the first word in a line. This is used to be able to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 " align a line relative to the 'print ' or 'if (' on the previous line in case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 " such a statement spans multiple lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 " Precondition: only to be used on lines where 'Starts_with_word' returns 1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 function! s:First_word_len( line )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 let white_end = matchend( a:line, '^\s*' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 if match( a:line, '^\s*func' ) != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 let word_end = matchend( a:line, '[a-z]\+\s\+[a-zA-Z_0-9]\+[ (]*' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 let word_end = matchend( a:line, '[a-zA-Z_0-9]\+[ (]*' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 return word_end - white_end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 " Determine if 'line' completes a statement or is continued on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 " This one is far from complete and accepts illegal code. Not important for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 " indenting, however.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 function! s:Seems_continuing( line )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 " Unfinished lines
3099
887d6d91882e Updated a few runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3082
diff changeset
192 if a:line =~ '\(--\|++\)\s*$'
887d6d91882e Updated a few runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3082
diff changeset
193 return 0
887d6d91882e Updated a few runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3082
diff changeset
194 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 if a:line =~ '[\\,\|\&\+\-\*\%\^]\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 return 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 " if/for/while (cond) eol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 if a:line =~ '^\s*\(if\|while\|for\)\s*(.*)\s*$' || a:line =~ '^\s*else\s*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 return 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 " Get previous relevant line. Search back until a line is that is no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 " comment or blank and return the line number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 function! s:Get_prev_line( lineno )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 let lnum = a:lineno - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 let data = getline( lnum )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 while lnum > 0 && (data =~ '^\s*#' || data =~ '^\s*$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 let lnum = lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 let data = getline( lnum )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 return lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 " This function checks whether an indented line exceeds a maximum linewidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 " (hardcoded 80). If so and it is possible to stay within 80 positions (or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 " limit num of characters beyond linewidth) by decreasing the indent (keeping
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 " it > base_indent), do so.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 function! s:Safe_indent( base, wordlen, this_line )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 let line_base = matchend( a:this_line, '^\s*' )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 let line_len = strlen( a:this_line ) - line_base
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 let indent = a:base
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 if (indent + a:wordlen + line_len) > 80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 " Simple implementation good enough for the time being
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 let indent = indent + 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 return indent + a:wordlen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 endfunction