begingroupundo; if ( getconfig( "AutoAdjustOrikaeshi" ) == 2 ) { #width = windowwidth; } else { #width = getconfig( "Orikaeshi" ); } if ( !selecting ) { #top = 1; #end = linecount2; } else { #top = seltoplineno; #end = selendlineno; escape; } #i = #top; while( #i <= #end ) { movetolineno 1, #i; #margin = #width - linelen2; if ( #margin >= 0 ) { #j = #margin / 2; $margin = ""; while( #j > 0 ) { $margin = $margin + " "; #j = #j - 1; } insert $margin; } else { beginsel; movetolineno linelen2 + 1, #i; $text = gettext( seltopx, seltopy, selendx, selendy, 1 ); delete; call cutstr, $text, #width; insert $$return; } #i = #i + 1; } endgroupundo; endmacro; cutstr: $$src = $$1; ##width = ##2; if ( ##width < 0 ) { ##width = 0; } if ( ##width > strlen( $$src ) ) { ##width = strlen( $$src ); } ##start = strlen( $$src ) - ##width; ##end = strlen( $$src ) + ##width; ##i = 0; $$dest = ""; $$left = ""; $$right = ""; while( ##i * 2 < ##end ) { ##char = ascii( $$src ); ##bytes = strlen( char( ##char ) ); if ( ##i * 2 < ##start ) { $$left = char( ##char ); } if ( ( ( ##i + ##bytes ) * 2 > ##end ) && ( $$right == "" ) ) { $$right = char( ##char ); } if ( ( ##i * 2 >= ##start ) && ( ( ##i + ##bytes ) * 2 <= ##end ) ) { $$dest = $$dest + char( ##char ); } $$src = rightstr( $$src, strlen( $$src ) - ##bytes ); ##i = ##i + ##bytes; } if ( $$right == "" ) { $$right = char( ascii( $$src ) ); } if ( strlen( $$dest ) >= ##width ) { return $$dest; } if ( ( strlen( $$left + $$dest ) <= ##width ) && ( $$left != "" ) ) { return $$left + $$dest; } if ( ( strlen( $$dest + $$right ) <= ##width ) && ( $$right != "" ) ) { return $$dest + $$right; } return $$dest;