summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:51:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2010-05-24 21:51:20 +0000
commite4081855b3ccc752fd8d5c743e87ad84478c748c (patch)
tree3547f69f52972cb996e650c41652f7fd47b5cf5a
parentd0f1de7c988060895fa78550174754f334d3b8ff (diff)
downloadmandoc-e4081855b3ccc752fd8d5c743e87ad84478c748c.tar.gz
sync to OpenBSD:
save the visual cursor position in term_flushln() and use that to avoid multiple blank lines in nested lists while still putting subsequent empty list tags each on their own line; "go ahead" kristaps@
-rw-r--r--mdoc_term.c14
-rw-r--r--term.c14
-rw-r--r--term.h1
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;
diff --git a/term.c b/term.c
index 471056c4..a41162c4 100644
--- a/term.c
+++ b/term.c
@@ -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');
}
diff --git a/term.h b/term.h
index 043178e4..0adbfd13 100644
--- a/term.h
+++ b/term.h
@@ -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. */