67
67
let s: stop_statement = ' ^\s*\(break\|continue\|raise\|return\|pass\)\>'
68
68
69
69
let s: skip_after_opening_paren = ' synIDattr(synID(line("."), col("."), 0), "name") ' .
70
- \ ' =~? "\\vcomment|jedi\\S "'
70
+ \ ' =~? "\\vcomment"'
71
71
72
- let s: special_chars_syn_pattern = " \\ vstring|comment|^pythonbytes%(contents)=$|pythonTodo|jedi \\ S "
72
+ let s: special_chars_syn_pattern = " \\ vstring|comment|^pythonbytes%(contents)=$|pythonTodo"
73
73
74
74
if ! get (g: , ' python_pep8_indent_skip_concealed' , 0 ) || ! has (' conceal' )
75
75
" Skip strings and comments. Return 1 for chars to skip.
@@ -136,8 +136,8 @@ endfunction
136
136
function ! s: find_start_of_multiline_statement (lnum)
137
137
let lnum = a: lnum
138
138
while lnum > 0
139
- if getline (lnum - 1 ) = ~# ' \\$'
140
- let lnum = prevnonblank (lnum - 1 )
139
+ if s: getline (lnum - 1 ) = ~# ' \\$'
140
+ let lnum = s: prevnonblank (lnum - 1 )
141
141
else
142
142
let [paren_lnum, _] = s: find_opening_paren (lnum, 1 )
143
143
if paren_lnum < 1
@@ -163,7 +163,7 @@ function! s:find_start_of_block(lnum, types, skip, multiple) abort
163
163
while lnum > 0 && last_indent > 0
164
164
let indent = indent (lnum)
165
165
if indent < last_indent
166
- let line = getline (lnum)
166
+ let line = s: getline (lnum)
167
167
if ! empty (re_skip) && line = ~# re_skip
168
168
let last_indent = indent
169
169
elseif line = ~# re
@@ -176,15 +176,15 @@ function! s:find_start_of_block(lnum, types, skip, multiple) abort
176
176
let last_indent = indent
177
177
endif
178
178
endif
179
- let lnum = prevnonblank (lnum - 1 )
179
+ let lnum = s: prevnonblank (lnum - 1 )
180
180
endwhile
181
181
return r
182
182
endfunction
183
183
184
184
" Is "expr" true for every position in "lnum", beginning at "start"?
185
185
" (optionally up to a:1 / 4th argument)
186
186
function ! s: match_expr_on_line (expr , lnum, start , ... )
187
- let text = getline (a: lnum )
187
+ let text = s: getline (a: lnum )
188
188
let end = a: 0 ? a: 1 : len (text)
189
189
if a: start > end
190
190
return 1
@@ -208,12 +208,12 @@ function! s:indent_like_opening_paren(lnum)
208
208
if paren_lnum <= 0
209
209
return -2
210
210
endif
211
- let text = getline (paren_lnum)
211
+ let text = s: getline (paren_lnum)
212
212
let base = indent (paren_lnum)
213
213
214
214
let nothing_after_opening_paren = s: match_expr_on_line (
215
215
\ s: skip_after_opening_paren , paren_lnum, paren_col+ 1 )
216
- let starts_with_closing_paren = getline (a: lnum ) = ~# ' ^\s*[])}]'
216
+ let starts_with_closing_paren = s: getline (a: lnum ) = ~# ' ^\s*[])}]'
217
217
218
218
let hang_closing = get (b: , ' python_pep8_indent_hang_closing' ,
219
219
\ get (g: , ' python_pep8_indent_hang_closing' , 0 ))
@@ -249,7 +249,7 @@ endfunction
249
249
250
250
" Match indent of first block of this type.
251
251
function ! s: indent_like_block (lnum)
252
- let text = getline (a: lnum )
252
+ let text = s: getline (a: lnum )
253
253
for [multiple, block_rules] in [
254
254
\ [0 , s: block_rules ],
255
255
\ [1 , s: block_rules_multiple ],
@@ -281,15 +281,45 @@ function! s:indent_like_block(lnum)
281
281
return -2
282
282
endfunction
283
283
284
+ " Wrapper around getline that looks up jedi-vim's b:_jedi_callsig_orig to get
285
+ " the original line.
286
+ function ! s: getline (lnum) abort
287
+ let line = get (get (b: , ' _jedi_callsig_orig' , {}), a: lnum , 0 )
288
+ if line is 0
289
+ return getline (a: lnum )
290
+ endif
291
+ return line
292
+ endfunction
293
+
294
+ " Wrapper around prevnonblank that looks up jedi-vim's b:_jedi_callsig_orig to
295
+ " check the original line's contents additionally.
296
+ function ! s: prevnonblank (lnum) abort
297
+ let lnum = a: lnum
298
+ while 1
299
+ let lnum = prevnonblank (lnum)
300
+ if lnum < 1
301
+ return lnum
302
+ endif
303
+ let orig_line = get (get (b: , ' _jedi_callsig_orig' , {}), lnum, 0 )
304
+ if orig_line is 0
305
+ return lnum
306
+ endif
307
+ if ! empty (orig_line)
308
+ return lnum
309
+ endif
310
+ let lnum -= 1
311
+ endwhile
312
+ endfunction
313
+
284
314
function ! s: indent_like_previous_line (lnum)
285
- let lnum = prevnonblank (a: lnum - 1 )
315
+ let lnum = s: prevnonblank (a: lnum - 1 )
286
316
287
317
" No previous line, keep current indent.
288
318
if lnum < 1
289
319
return -1
290
320
endif
291
321
292
- let text = getline (lnum)
322
+ let text = s: getline (lnum)
293
323
let start = s: find_start_of_multiline_statement (lnum)
294
324
let base = indent (start )
295
325
let current = indent (a: lnum )
@@ -314,25 +344,25 @@ function! s:indent_like_previous_line(lnum)
314
344
" If this line is the continuation of a control statement
315
345
" indent further to distinguish the continuation line
316
346
" from the next logical line.
317
- if getline (start ) = ~# b: control_statement
347
+ if s: getline (start ) = ~# b: control_statement
318
348
return base + s: sw () * 2
319
349
endif
320
350
321
351
" Nest (other) explicit continuations only one level deeper.
322
352
return base + s: sw ()
323
353
endif
324
354
325
- let empty = getline (a: lnum ) = ~# ' ^\s*$'
355
+ let empty = s: getline (a: lnum ) = ~# ' ^\s*$'
326
356
327
357
" Current and prev line are empty, next is not -> indent like next.
328
358
if empty && a: lnum > 1 &&
329
- \ (getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
330
- \ ! (getline (a: lnum + 1 ) = ~# ' ^\s*$' )
359
+ \ (s: getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
360
+ \ ! (s: getline (a: lnum + 1 ) = ~# ' ^\s*$' )
331
361
return indent (a: lnum + 1 )
332
362
endif
333
363
334
364
" If the previous statement was a stop-execution statement or a pass
335
- if getline (start ) = ~# s: stop_statement
365
+ if s: getline (start ) = ~# s: stop_statement
336
366
" Remove one level of indentation if the user hasn't already dedented
337
367
if empty || current > base - s: sw ()
338
368
return base - s: sw ()
@@ -358,11 +388,10 @@ endfunction
358
388
359
389
" Is the syntax at lnum (and optionally cnum) a python string?
360
390
function ! s: is_python_string (lnum, ... )
361
- let line = getline (a: lnum )
362
391
if a: 0
363
392
let cols = type (a: 1 ) != type ([]) ? [a: 1 ] : a: 1
364
393
else
365
- let cols = range (1 , max ([1 , len (line )]))
394
+ let cols = range (1 , max ([1 , len (s: getline ( a: lnum ) )]))
366
395
endif
367
396
for cnum in cols
368
397
if match (map (synstack (a: lnum , cnum),
@@ -379,8 +408,8 @@ function! GetPythonPEPIndent(lnum)
379
408
return 0
380
409
endif
381
410
382
- let line = getline (a: lnum )
383
- let prevline = getline (a: lnum- 1 )
411
+ let line = s: getline (a: lnum )
412
+ let prevline = s: getline (a: lnum- 1 )
384
413
385
414
" Multilinestrings: continous, docstring or starting.
386
415
if s: is_python_string (a: lnum- 1 , max ([1 , len (prevline)]))
0 commit comments