@@ -325,13 +325,7 @@ function s:PythonCompiler.compile_excmd(node)
325325 throw ' NotImplemented: excmd'
326326endfunction
327327
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 )
335329 " Find start of preceding comment (block).
336330 let comment_start = 0
337331 let len_lines = len (self .lines )
@@ -344,17 +338,30 @@ function s:PythonCompiler.compile_function(node)
344338 endif
345339 endif
346340
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+
348359 if left = ~ ' ^\(VimLParser\|ExprTokenizer\|ExprParser\|LvalueParser\|StringReader\|Compiler\|RegexpParser\)\.'
349360 let left = matchstr (left , ' \.\zs.*' )
350361 if left == ' new'
351362 return
352363 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 )
358365 call insert (rlist, ' self' )
359366 call self .out (' def %s(%s):' , left , join (rlist, ' , ' ))
360367 call self .incindent (' ' )
@@ -365,13 +372,7 @@ function s:PythonCompiler.compile_function(node)
365372 let self .in_class = 0
366373 call self .decindent ()
367374 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 )
375376 call self .out (' def %s(%s):' , left , join (rlist, ' , ' ))
376377 call self .incindent (' ' )
377378 call self .compile_body (a: node .body)
@@ -419,8 +420,7 @@ function s:PythonCompiler.compile_let(node)
419420 if self .in_class
420421 call self .decindent ()
421422 endif
422- call self .emptyline ()
423- call self .emptyline ()
423+ call self .insert_empty_lines_before_comment (2 )
424424 call self .out (' class %s:' , class_def)
425425 let self .in_class = 1
426426 call self .incindent (' ' )
0 commit comments