@@ -58,23 +58,11 @@ endif
58
58
let s: stop_statement = ' ^\s*\(break\|continue\|raise\|return\|pass\)\>'
59
59
60
60
" Skip strings and comments. Return 1 for chars to skip.
61
- " jedi* refers to syntax definitions from jedi-vim for call signatures, which
62
- " are inserted temporarily into the buffer.
63
61
let s: skip_special_chars = ' synIDattr(synID(line("."), col("."), 0), "name") ' .
64
- \ ' =~? "\\vstring|comment|^pythonbytes%(contents)=$|jedi\\S "'
62
+ \ ' =~? "\\vstring|comment|^pythonbytes%(contents)=$"'
65
63
66
64
let s: skip_after_opening_paren = ' synIDattr(synID(line("."), col("."), 0), "name") ' .
67
- \ ' =~? "\\vcomment|jedi\\S"'
68
-
69
- " Also ignore anything concealed.
70
- " Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI).
71
- function ! s: is_concealed (line , col )
72
- let concealed = synconcealed (a: line , a: col )
73
- return len (concealed) && concealed[0 ]
74
- endfunction
75
- if has (' conceal' )
76
- let s: skip_special_chars .= ' || s:is_concealed(line("."), col("."))'
77
- endif
65
+ \ ' =~? "\\vcomment"'
78
66
79
67
80
68
let s: skip_search = ' synIDattr(synID(line("."), col("."), 0), "name") ' .
@@ -122,8 +110,8 @@ endfunction
122
110
function ! s: find_start_of_multiline_statement (lnum)
123
111
let lnum = a: lnum
124
112
while lnum > 0
125
- if getline (lnum - 1 ) = ~# ' \\$'
126
- let lnum = prevnonblank (lnum - 1 )
113
+ if s: getline (lnum - 1 ) = ~# ' \\$'
114
+ let lnum = s: prevnonblank (lnum - 1 )
127
115
else
128
116
let [paren_lnum, _] = s: find_opening_paren (lnum)
129
117
if paren_lnum < 1
@@ -144,7 +132,7 @@ function! s:find_start_of_block(lnum, types, multiple)
144
132
while lnum > 0 && last_indent > 0
145
133
let indent = indent (lnum)
146
134
if indent < last_indent
147
- if getline (lnum) = ~# re
135
+ if s: getline (lnum) = ~# re
148
136
if ! a: multiple
149
137
return [indent ]
150
138
endif
@@ -154,15 +142,15 @@ function! s:find_start_of_block(lnum, types, multiple)
154
142
let last_indent = indent
155
143
endif
156
144
endif
157
- let lnum = prevnonblank (lnum - 1 )
145
+ let lnum = s: prevnonblank (lnum - 1 )
158
146
endwhile
159
147
return r
160
148
endfunction
161
149
162
150
" Is "expr" true for every position in "lnum", beginning at "start"?
163
151
" (optionally up to a:1 / 4th argument)
164
152
function ! s: match_expr_on_line (expr , lnum, start , ... )
165
- let text = getline (a: lnum )
153
+ let text = s: getline (a: lnum )
166
154
let end = a: 0 ? a: 1 : len (text)
167
155
if a: start > end
168
156
return 1
@@ -186,12 +174,12 @@ function! s:indent_like_opening_paren(lnum)
186
174
if paren_lnum <= 0
187
175
return -2
188
176
endif
189
- let text = getline (paren_lnum)
177
+ let text = s: getline (paren_lnum)
190
178
let base = indent (paren_lnum)
191
179
192
180
let nothing_after_opening_paren = s: match_expr_on_line (
193
181
\ s: skip_after_opening_paren , paren_lnum, paren_col+ 1 )
194
- let starts_with_closing_paren = getline (a: lnum ) = ~# ' ^\s*[])}]'
182
+ let starts_with_closing_paren = s: getline (a: lnum ) = ~# ' ^\s*[])}]'
195
183
196
184
let hang_closing = get (b: , ' python_pep8_indent_hang_closing' ,
197
185
\ get (g: , ' python_pep8_indent_hang_closing' , 0 ))
@@ -222,7 +210,7 @@ endfunction
222
210
223
211
" Match indent of first block of this type.
224
212
function ! s: indent_like_block (lnum)
225
- let text = getline (a: lnum )
213
+ let text = s: getline (a: lnum )
226
214
for [multiple, block_rules] in [
227
215
\ [0 , s: block_rules ],
228
216
\ [1 , s: block_rules_multiple ]]
@@ -252,15 +240,45 @@ function! s:indent_like_block(lnum)
252
240
return -2
253
241
endfunction
254
242
243
+ " Wrapper around getline that looks up jedi-vim's b:_jedi_callsig_orig to get
244
+ " the original line.
245
+ function ! s: getline (lnum) abort
246
+ let line = get (get (b: , ' _jedi_callsig_orig' , {}), a: lnum , 0 )
247
+ if line is 0
248
+ return getline (a: lnum )
249
+ endif
250
+ return line
251
+ endfunction
252
+
253
+ " Wrapper around prevnonblank that looks up jedi-vim's b:_jedi_callsig_orig to
254
+ " check the original line's contents additionally.
255
+ function ! s: prevnonblank (lnum) abort
256
+ let lnum = a: lnum
257
+ while 1
258
+ let lnum = prevnonblank (lnum)
259
+ if lnum < 1
260
+ return lnum
261
+ endif
262
+ let orig_line = get (get (b: , ' _jedi_callsig_orig' , {}), lnum, 0 )
263
+ if orig_line is 0
264
+ return lnum
265
+ endif
266
+ if ! empty (orig_line)
267
+ return lnum
268
+ endif
269
+ let lnum -= 1
270
+ endwhile
271
+ endfunction
272
+
255
273
function ! s: indent_like_previous_line (lnum)
256
- let lnum = prevnonblank (a: lnum - 1 )
274
+ let lnum = s: prevnonblank (a: lnum - 1 )
257
275
258
276
" No previous line, keep current indent.
259
277
if lnum < 1
260
278
return -1
261
279
endif
262
280
263
- let text = getline (lnum)
281
+ let text = s: getline (lnum)
264
282
let start = s: find_start_of_multiline_statement (lnum)
265
283
let base = indent (start )
266
284
let current = indent (a: lnum )
@@ -286,25 +304,25 @@ function! s:indent_like_previous_line(lnum)
286
304
" If this line is the continuation of a control statement
287
305
" indent further to distinguish the continuation line
288
306
" from the next logical line.
289
- if getline (start ) = ~# b: control_statement
307
+ if s: getline (start ) = ~# b: control_statement
290
308
return base + s: sw () * 2
291
309
endif
292
310
293
311
" Nest (other) explicit continuations only one level deeper.
294
312
return base + s: sw ()
295
313
endif
296
314
297
- let empty = getline (a: lnum ) = ~# ' ^\s*$'
315
+ let empty = s: getline (a: lnum ) = ~# ' ^\s*$'
298
316
299
317
" Current and prev line are empty, next is not -> indent like next.
300
318
if empty && a: lnum > 1 &&
301
- \ (getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
302
- \ ! (getline (a: lnum + 1 ) = ~# ' ^\s*$' )
319
+ \ (s: getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
320
+ \ ! (s: getline (a: lnum + 1 ) = ~# ' ^\s*$' )
303
321
return indent (a: lnum + 1 )
304
322
endif
305
323
306
324
" If the previous statement was a stop-execution statement or a pass
307
- if getline (start ) = ~# s: stop_statement
325
+ if s: getline (start ) = ~# s: stop_statement
308
326
" Remove one level of indentation if the user hasn't already dedented
309
327
if empty || current > base - s: sw ()
310
328
return base - s: sw ()
@@ -330,11 +348,10 @@ endfunction
330
348
331
349
" Is the syntax at lnum (and optionally cnum) a python string?
332
350
function ! s: is_python_string (lnum, ... )
333
- let line = getline (a: lnum )
334
351
if a: 0
335
352
let cols = type (a: 1 ) != type ([]) ? [a: 1 ] : a: 1
336
353
else
337
- let cols = range (1 , max ([1 , len (line )]))
354
+ let cols = range (1 , max ([1 , len (s: getline ( a: lnum ) )]))
338
355
endif
339
356
for cnum in cols
340
357
if match (map (synstack (a: lnum , cnum),
@@ -351,8 +368,8 @@ function! GetPythonPEPIndent(lnum)
351
368
return 0
352
369
endif
353
370
354
- let line = getline (a: lnum )
355
- let prevline = getline (a: lnum- 1 )
371
+ let line = s: getline (a: lnum )
372
+ let prevline = s: getline (a: lnum- 1 )
356
373
357
374
" Multilinestrings: continous, docstring or starting.
358
375
if s: is_python_string (a: lnum- 1 , max ([1 , len (prevline)]))
0 commit comments