@@ -512,14 +512,17 @@ function! GetPythonPEPFormat(lnum, count)
512512 endwhile
513513 endif
514514
515- call cursor (a: lnum , l: tw + 1 )
515+ let l: twplus1 = s: VirtcolToCol (a: lnum , l: tw + 1 )
516+ let l: twminus1 = s: VirtcolToCol (a: lnum , l: tw - 1 )
517+
518+ call cursor (a: lnum , l: twplus1 )
516519 let l: orig_breakpoint = searchpos (' ' , ' bcW' , a: lnum )
517520 let l: orig_breakpointview = winsaveview ()
518521 " If breaking inside string extra space is needed for the space and quote
519- call cursor (a: lnum , l: tw - 1 )
522+ call cursor (a: lnum , l: twminus1 )
520523 let l: better_orig_breakpoint = searchpos (' ' , ' bcW' , a: lnum )
521524 let l: better_orig_breakpointview = winsaveview ()
522- call cursor (a: lnum , l: tw + 1 )
525+ call cursor (a: lnum , l: twplus1 )
523526 let l: breakpoint = s: SearchPosWithSkip (' ' , ' bcW' , s: skip_string , a: lnum )
524527 let l: breakpointview = winsaveview ()
525528
@@ -609,7 +612,7 @@ function! GetPythonPEPFormat(lnum, count)
609612 call feedkeys (" a\\ \<CR>\<esc> " , ' n' )
610613 endif
611614 else
612- call cursor (a: lnum , l: tw + 1 )
615+ call cursor (a: lnum , l: twplus1 )
613616 " Search for a space that is not trailing whitespace
614617 let l: afterbreakpoint = s: SearchPosWithSkip (' [^ ]' , ' cW' , s: skip_string , a: lnum )
615618
@@ -639,3 +642,14 @@ function s:isBetweenPair(left, right, winview, skip)
639642 let l: bracket = searchpairpos (a: left , ' ' , a: right , ' bW' , a: skip )
640643 return l: bracket [0 ] != 0
641644endfunction
645+
646+ function s: VirtcolToCol (lnum, cnum)
647+ let l: last = virtcol ([a: lnum , ' $' ])
648+ let l: cnum = a: cnum
649+ let l: vcol = virtcol ([a: lnum , l: cnum ])
650+ while l: vcol <= a: cnum && l: vcol < l: last
651+ let l: cnum += 1
652+ let l: vcol = virtcol ([a: lnum , l: cnum ])
653+ endwhile
654+ return l: cnum - 1
655+ endfunction
0 commit comments