@@ -325,13 +325,7 @@ function s:PythonCompiler.compile_excmd(node)
325
325
throw ' NotImplemented: excmd'
326
326
endfunction
327
327
328
- function s: PythonCompiler .compile_function (node)
329
- let left = self .compile (a: node .left )
330
- let rlist = map (a: node .rlist, ' self.compile(v:val)' )
331
- if ! empty (rlist) && rlist[-1 ] == ' ...'
332
- let rlist[-1 ] = ' *a000'
333
- endif
334
-
328
+ function s: PythonCompiler .insert_empty_lines_before_comment (count )
335
329
" Find start of preceding comment (block).
336
330
let comment_start = 0
337
331
let len_lines = len (self .lines )
@@ -344,17 +338,30 @@ function s:PythonCompiler.compile_function(node)
344
338
endif
345
339
endif
346
340
347
- " if self.in_class
341
+ if comment_start
342
+ for c in range (a: count )
343
+ call insert (self .lines , ' ' , comment_start)
344
+ endfor
345
+ else
346
+ for c in range (a: count )
347
+ call self .emptyline ()
348
+ endfor
349
+ endif
350
+ endfunction
351
+
352
+ function s: PythonCompiler .compile_function (node)
353
+ let left = self .compile (a: node .left )
354
+ let rlist = map (a: node .rlist, ' self.compile(v:val)' )
355
+ if ! empty (rlist) && rlist[-1 ] == ' ...'
356
+ let rlist[-1 ] = ' *a000'
357
+ endif
358
+
348
359
if left = ~ ' ^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\)\.'
349
360
let left = matchstr (left , ' \.\zs.*' )
350
361
if left == ' new'
351
362
return
352
363
endif
353
- if comment_start
354
- call insert (self .lines , ' ' , comment_start)
355
- else
356
- call self .emptyline ()
357
- endif
364
+ call self .insert_empty_lines_before_comment (1 )
358
365
call insert (rlist, ' self' )
359
366
call self .out (' def %s(%s):' , left , join (rlist, ' , ' ))
360
367
call self .incindent (' ' )
@@ -365,13 +372,7 @@ function s:PythonCompiler.compile_function(node)
365
372
let self .in_class = 0
366
373
call self .decindent ()
367
374
endif
368
- if comment_start
369
- call insert (self .lines , ' ' , comment_start)
370
- call insert (self .lines , ' ' , comment_start)
371
- else
372
- call self .emptyline ()
373
- call self .emptyline ()
374
- endif
375
+ call self .insert_empty_lines_before_comment (2 )
375
376
call self .out (' def %s(%s):' , left , join (rlist, ' , ' ))
376
377
call self .incindent (' ' )
377
378
call self .compile_body (a: node .body)
@@ -419,8 +420,7 @@ function s:PythonCompiler.compile_let(node)
419
420
if self .in_class
420
421
call self .decindent ()
421
422
endif
422
- call self .emptyline ()
423
- call self .emptyline ()
423
+ call self .insert_empty_lines_before_comment (2 )
424
424
call self .out (' class %s:' , class_def)
425
425
let self .in_class = 1
426
426
call self .incindent (' ' )
0 commit comments