@@ -349,34 +349,61 @@ function! GetPythonPEPIndent(lnum)
349
349
return 0
350
350
endif
351
351
352
+ let line = getline (a: lnum )
353
+ let prevline = getline (a: lnum- 1 )
354
+
352
355
" Multilinestrings: continous, docstring or starting.
353
- if s: is_python_string (a: lnum , 1 )
354
- \ && s: is_python_string (a: lnum- 1 , len (getline (a: lnum- 1 )))
355
- " Keep existing indent.
356
- if match (getline (a: lnum ), ' \v^\s*\S' ) != -1
357
- return -1
356
+ if s: is_python_string (a: lnum- 1 , len (prevline))
357
+ \ && (s: is_python_string (a: lnum , 1 )
358
+ \ || match (line , ' ^\%("""\|'''''' \)' ) != -1 )
359
+
360
+ " Indent closing quotes as the line with the opening ones.
361
+ let match_quotes = match (line , ' ^\s*\zs\%("""\|'''''' \)' )
362
+ if match_quotes != -1
363
+ " closing multiline string
364
+ let quotes = line [match_quotes: match_quotes+ 2 ]
365
+ let pairpos = searchpairpos (quotes, ' ' , quotes, ' b' )
366
+ if pairpos[0 ] != 0
367
+ return indent (pairpos[0 ])
368
+ else
369
+ " TODO: test to cover this!
370
+ endif
358
371
endif
359
372
360
373
if s: is_python_string (a: lnum- 1 )
361
374
" Previous line is (completely) a string.
362
375
return indent (a: lnum- 1 )
363
376
endif
364
377
365
- if match (getline ( a: lnum - 1 ) , ' ^\s*\%("""\|'''''' \)' ) != -1
378
+ if match (prevline , ' ^\s*\%("""\|'''''' \)' ) != -1
366
379
" docstring.
367
380
return indent (a: lnum- 1 )
368
381
endif
369
382
370
383
let indent_multi = get (b: , ' python_pep8_indent_multiline_string' ,
371
384
\ get (g: , ' python_pep8_indent_multiline_string' , 0 ))
385
+ if match (prevline, ' \v%("""|'''''' )$' ) != -1
386
+ " Opening multiline string, started in previous line.
387
+ if (&autoindent && indent (a: lnum ) == indent (a: lnum- 1 ))
388
+ \ || match (line , ' \v^\s+$' ) != -1
389
+ " <CR> with empty line or to split up 'foo("""bar' into
390
+ " 'foo("""' and 'bar'.
391
+ if indent_multi == -2
392
+ return indent (a: lnum- 1 ) + s: sw ()
393
+ endif
394
+ return indent_multi
395
+ endif
396
+ endif
397
+
398
+ " Keep existing indent.
399
+ if match (line , ' \v^\s*\S' ) != -1
400
+ return -1
401
+ endif
402
+
372
403
if indent_multi != -2
373
404
return indent_multi
374
405
endif
375
406
376
- if match (getline (a: lnum- 1 ), ' \v%("""|'''''' )$' ) != -1
377
- " Opening multiline string, started in previous line.
378
- return indent (a: lnum- 1 ) + s: sw ()
379
- endif
380
407
return s: indent_like_opening_paren (a: lnum )
381
408
endif
382
409
0 commit comments