@@ -67,15 +67,15 @@ endif
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
72
if ! get (g: , ' python_pep8_indent_skip_concealed' , 0 ) || ! has (' conceal' )
73
73
" Skip strings and comments. Return 1 for chars to skip.
74
74
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
75
75
" are inserted temporarily into the buffer.
76
76
function ! s: _skip_special_chars (line , col )
77
77
return synIDattr (synID (a: line , a: col , 0 ), ' name' )
78
- \ = ~? " \\ vstring|comment|^pythonbytes%(contents)=$|jedi \\ S "
78
+ \ = ~? " \\ vstring|comment|^pythonbytes%(contents)=$"
79
79
endfunction
80
80
else
81
81
" Also ignore anything concealed.
@@ -134,8 +134,8 @@ endfunction
134
134
function ! s: find_start_of_multiline_statement (lnum)
135
135
let lnum = a: lnum
136
136
while lnum > 0
137
- if getline (lnum - 1 ) = ~# ' \\$'
138
- let lnum = prevnonblank (lnum - 1 )
137
+ if s: getline (lnum - 1 ) = ~# ' \\$'
138
+ let lnum = s: prevnonblank (lnum - 1 )
139
139
else
140
140
let [paren_lnum, _] = s: find_opening_paren (lnum, 1 )
141
141
if paren_lnum < 1
@@ -156,7 +156,7 @@ function! s:find_start_of_block(lnum, types, multiple)
156
156
while lnum > 0 && last_indent > 0
157
157
let indent = indent (lnum)
158
158
if indent < last_indent
159
- if getline (lnum) = ~# re
159
+ if s: getline (lnum) = ~# re
160
160
if ! a: multiple
161
161
return [indent ]
162
162
endif
@@ -166,15 +166,15 @@ function! s:find_start_of_block(lnum, types, multiple)
166
166
let last_indent = indent
167
167
endif
168
168
endif
169
- let lnum = prevnonblank (lnum - 1 )
169
+ let lnum = s: prevnonblank (lnum - 1 )
170
170
endwhile
171
171
return r
172
172
endfunction
173
173
174
174
" Is "expr" true for every position in "lnum", beginning at "start"?
175
175
" (optionally up to a:1 / 4th argument)
176
176
function ! s: match_expr_on_line (expr , lnum, start , ... )
177
- let text = getline (a: lnum )
177
+ let text = s: getline (a: lnum )
178
178
let end = a: 0 ? a: 1 : len (text)
179
179
if a: start > end
180
180
return 1
@@ -198,12 +198,12 @@ function! s:indent_like_opening_paren(lnum)
198
198
if paren_lnum <= 0
199
199
return -2
200
200
endif
201
- let text = getline (paren_lnum)
201
+ let text = s: getline (paren_lnum)
202
202
let base = indent (paren_lnum)
203
203
204
204
let nothing_after_opening_paren = s: match_expr_on_line (
205
205
\ s: skip_after_opening_paren , paren_lnum, paren_col+ 1 )
206
- let starts_with_closing_paren = getline (a: lnum ) = ~# ' ^\s*[])}]'
206
+ let starts_with_closing_paren = s: getline (a: lnum ) = ~# ' ^\s*[])}]'
207
207
208
208
let hang_closing = get (b: , ' python_pep8_indent_hang_closing' ,
209
209
\ get (g: , ' python_pep8_indent_hang_closing' , 0 ))
@@ -234,7 +234,7 @@ endfunction
234
234
235
235
" Match indent of first block of this type.
236
236
function ! s: indent_like_block (lnum)
237
- let text = getline (a: lnum )
237
+ let text = s: getline (a: lnum )
238
238
for [multiple, block_rules] in [
239
239
\ [0 , s: block_rules ],
240
240
\ [1 , s: block_rules_multiple ]]
@@ -264,15 +264,45 @@ function! s:indent_like_block(lnum)
264
264
return -2
265
265
endfunction
266
266
267
+ " Wrapper around getline that looks up jedi-vim's b:_jedi_callsig_orig to get
268
+ " the original line.
269
+ function ! s: getline (lnum) abort
270
+ let line = get (get (b: , ' _jedi_callsig_orig' , {}), a: lnum , 0 )
271
+ if line is 0
272
+ return getline (a: lnum )
273
+ endif
274
+ return line
275
+ endfunction
276
+
277
+ " Wrapper around prevnonblank that looks up jedi-vim's b:_jedi_callsig_orig to
278
+ " check the original line's contents additionally.
279
+ function ! s: prevnonblank (lnum) abort
280
+ let lnum = a: lnum
281
+ while 1
282
+ let lnum = prevnonblank (lnum)
283
+ if lnum < 1
284
+ return lnum
285
+ endif
286
+ let orig_line = get (get (b: , ' _jedi_callsig_orig' , {}), lnum, 0 )
287
+ if orig_line is 0
288
+ return lnum
289
+ endif
290
+ if ! empty (orig_line)
291
+ return lnum
292
+ endif
293
+ let lnum -= 1
294
+ endwhile
295
+ endfunction
296
+
267
297
function ! s: indent_like_previous_line (lnum)
268
- let lnum = prevnonblank (a: lnum - 1 )
298
+ let lnum = s: prevnonblank (a: lnum - 1 )
269
299
270
300
" No previous line, keep current indent.
271
301
if lnum < 1
272
302
return -1
273
303
endif
274
304
275
- let text = getline (lnum)
305
+ let text = s: getline (lnum)
276
306
let start = s: find_start_of_multiline_statement (lnum)
277
307
let base = indent (start )
278
308
let current = indent (a: lnum )
@@ -297,25 +327,25 @@ function! s:indent_like_previous_line(lnum)
297
327
" If this line is the continuation of a control statement
298
328
" indent further to distinguish the continuation line
299
329
" from the next logical line.
300
- if getline (start ) = ~# b: control_statement
330
+ if s: getline (start ) = ~# b: control_statement
301
331
return base + s: sw () * 2
302
332
endif
303
333
304
334
" Nest (other) explicit continuations only one level deeper.
305
335
return base + s: sw ()
306
336
endif
307
337
308
- let empty = getline (a: lnum ) = ~# ' ^\s*$'
338
+ let empty = s: getline (a: lnum ) = ~# ' ^\s*$'
309
339
310
340
" Current and prev line are empty, next is not -> indent like next.
311
341
if empty && a: lnum > 1 &&
312
- \ (getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
313
- \ ! (getline (a: lnum + 1 ) = ~# ' ^\s*$' )
342
+ \ (s: getline (a: lnum - 1 ) = ~# ' ^\s*$' ) &&
343
+ \ ! (s: getline (a: lnum + 1 ) = ~# ' ^\s*$' )
314
344
return indent (a: lnum + 1 )
315
345
endif
316
346
317
347
" If the previous statement was a stop-execution statement or a pass
318
- if getline (start ) = ~# s: stop_statement
348
+ if s: getline (start ) = ~# s: stop_statement
319
349
" Remove one level of indentation if the user hasn't already dedented
320
350
if empty || current > base - s: sw ()
321
351
return base - s: sw ()
@@ -341,11 +371,10 @@ endfunction
341
371
342
372
" Is the syntax at lnum (and optionally cnum) a python string?
343
373
function ! s: is_python_string (lnum, ... )
344
- let line = getline (a: lnum )
345
374
if a: 0
346
375
let cols = type (a: 1 ) != type ([]) ? [a: 1 ] : a: 1
347
376
else
348
- let cols = range (1 , max ([1 , len (line )]))
377
+ let cols = range (1 , max ([1 , len (s: getline ( a: lnum ) )]))
349
378
endif
350
379
for cnum in cols
351
380
if match (map (synstack (a: lnum , cnum),
@@ -362,8 +391,8 @@ function! GetPythonPEPIndent(lnum)
362
391
return 0
363
392
endif
364
393
365
- let line = getline (a: lnum )
366
- let prevline = getline (a: lnum- 1 )
394
+ let line = s: getline (a: lnum )
395
+ let prevline = s: getline (a: lnum- 1 )
367
396
368
397
" Multilinestrings: continous, docstring or starting.
369
398
if s: is_python_string (a: lnum- 1 , max ([1 , len (prevline)]))
0 commit comments