diff options
-rw-r--r-- | mdoc_term.c | 14 | ||||
-rw-r--r-- | term.c | 14 | ||||
-rw-r--r-- | term.h | 1 |
3 files changed, 18 insertions, 11 deletions
diff --git a/mdoc_term.c b/mdoc_term.c index 5247c2f9..7861e080 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1014,14 +1014,14 @@ termp_it_post(DECL_ARGS) /* FALLTHROUGH */ case (LIST_inset): if (MDOC_BODY == n->type) - term_flushln(p); + term_newln(p); break; case (LIST_column): if (MDOC_HEAD == n->type) term_flushln(p); break; default: - term_flushln(p); + term_newln(p); break; } @@ -1633,11 +1633,9 @@ termp_bd_pre(DECL_ARGS) for (nn = n->child; nn; nn = nn->next) { p->flags |= TERMP_NOSPACE; print_mdoc_node(p, pair, m, nn); - if (NULL == nn->next) - continue; - if (nn->prev && nn->prev->line < nn->line) - term_flushln(p); - else if (NULL == nn->prev) + if (NULL == nn->prev || + nn->prev->line < nn->line || + NULL == nn->next) term_flushln(p); } p->tabwidth = tabwidth; @@ -1668,7 +1666,7 @@ termp_bd_post(DECL_ARGS) p->rmargin = p->maxrmargin = TERM_MAXMARGIN; p->flags |= TERMP_NOSPACE; - term_flushln(p); + term_newln(p); p->rmargin = rm; p->maxrmargin = rmax; @@ -207,10 +207,12 @@ term_flushln(struct termp *p) vend -= vis; putchar('\n'); if (TERMP_NOBREAK & p->flags) { + p->viscol = p->rmargin; for (j = 0; j < (int)p->rmargin; j++) putchar(' '); vend += p->rmargin - p->offset; } else { + p->viscol = 0; vbl = p->offset; } @@ -251,9 +253,11 @@ term_flushln(struct termp *p) if (vbl) { for (j = 0; j < (int)vbl; j++) putchar(' '); + p->viscol += vbl; vbl = 0; } putchar(p->buf[i]); + p->viscol += 1; } vend += vbl; vis = vend; @@ -263,6 +267,7 @@ term_flushln(struct termp *p) p->overstep = 0; if ( ! (TERMP_NOBREAK & p->flags)) { + p->viscol = 0; putchar('\n'); return; } @@ -294,11 +299,13 @@ term_flushln(struct termp *p) /* Right-pad. */ if (maxvis > vis + /* LINTED */ - ((TERMP_TWOSPACE & p->flags) ? 1 : 0)) + ((TERMP_TWOSPACE & p->flags) ? 1 : 0)) { + p->viscol += maxvis - vis; for ( ; vis < maxvis; vis++) putchar(' '); - else { /* ...or newline break. */ + } else { /* ...or newline break. */ putchar('\n'); + p->viscol = p->rmargin; for (i = 0; i < (int)p->rmargin; i++) putchar(' '); } @@ -315,7 +322,7 @@ term_newln(struct termp *p) { p->flags |= TERMP_NOSPACE; - if (0 == p->col) { + if (0 == p->col && 0 == p->viscol) { p->flags &= ~TERMP_NOLPAD; return; } @@ -335,6 +342,7 @@ term_vspace(struct termp *p) { term_newln(p); + p->viscol = 0; putchar('\n'); } @@ -39,6 +39,7 @@ struct termp { size_t offset; /* Margin offest. */ size_t tabwidth; /* Distance of tab positions. */ size_t col; /* Bytes in buf. */ + size_t viscol; /* Chars on current line. */ int overstep; /* See termp_flushln(). */ int flags; #define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */ |