@@ -186,7 +186,7 @@ static int isoptype(char c) {
186186}
187187
188188/* import keyword; print(*keyword.kwlist) */
189- /* todo: build fast detection state matchine , testing inclusion is 30% */
189+ /* todo: build fast detection state machine , testing inclusion is 30% */
190190static const char * specnames [] = {
191191 "and" , "as" , "assert" , "break" , "class" , "continue" , "def" ,
192192 "del" , "elif" , "else" , "except" , "finally" , "for" , "from" ,
@@ -712,7 +712,6 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
712712 /* TODO: create a 'nesting depth' field */
713713
714714 int length_left = 80 - leading_spaces ;
715- int first = 1 ;
716715 formfilelen = vlbuf_append (formfile , lsp .d .ch , formfilelen , out );
717716
718717 if (nsplits > 0 ) {
@@ -740,7 +739,8 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
740739 int len = to - fr ;
741740 int isc = 100 ;
742741 /* Just by previous. Q: split tok? or 'saved length' field, w/
743- * comments counting as -inf */
742+ * comments counting as -inf ls. Issue: what if there's less than N
743+ * fields left ?*/
744744 if (laccum .d .ch [ofr ] == ',' ) {
745745 isc = rleft - len - 15 ;
746746 } else if (laccum .d .ch [ofr ] == ':' ) {
@@ -753,9 +753,24 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
753753 bscore = isc ;
754754 bk = k ;
755755 }
756+ /* Never hold up a terminator */
757+ if (rleft >= 0 && k == nsplits - 1 ) {
758+ bk = -1 ;
759+ }
760+ }
761+ int want_split = bk == i ;
762+ int length_split = nlen >= length_left ;
763+
764+ int continuing = 1 ;
765+ if (i == 0 ) {
766+ continuing = 1 ;
767+ } else if (force_split || length_split || want_split ) {
768+ continuing = 0 ;
769+ } else {
770+ continuing = 1 ;
756771 }
757- if (( nlen < length_left || first ) && ! force_split && bk != i ) {
758- first = 0 ;
772+
773+ if ( continuing ) {
759774 length_left -= nlen ;
760775 formfilelen =
761776 vlbuf_append (formfile , lineout .d .ch , formfilelen , out );
@@ -774,7 +789,6 @@ static void pyformat(FILE *file, FILE *out, struct vlbuf *origfile,
774789 length_left = 80 - leading_spaces - 4 - nlen ;
775790 formfilelen = vlbuf_append (formfile , lsp .d .ch , formfilelen , out );
776791 formfilelen = vlbuf_append (formfile , prn , formfilelen , out );
777- first = 1 ;
778792 }
779793 }
780794 formfilelen = vlbuf_append (formfile , "\n" , formfilelen , out );
0 commit comments