summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2022-08-15 10:22:14 +0000
committerIngo Schwarze <schwarze@openbsd.org>2022-08-15 10:22:14 +0000
commitb8c2ddec80f36a42b137370c233bb4a858567168 (patch)
treec6363b9498575b5f80fdf26949bd5a61ca705f1b
parentd1209cefa23aa348425c687c38c5820947fd050c (diff)
downloadmandoc-b8c2ddec80f36a42b137370c233bb4a858567168.tar.gz
In GNU, Heirloom, and Plan 9 roff, literal tab characters are
non-breakable in exactly the same way as "\ ". That is, the preceding word, the tab character, and the following word are always kept together on the same output line. If filling is enabled and an output line break is required before the end of the following word, the break occurs before the beginning of the preceding word. Make mandoc behave in the same way. Of course, using literal tab characters in filled text remains a bad idea, and the "WARNING: tab in filled text" remains unchanged.
-rw-r--r--term.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/term.c b/term.c
index b06fe569..2795cc5c 100644
--- a/term.c
+++ b/term.c
@@ -268,22 +268,11 @@ term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
vis -= (*p->width)(p, p->tcol->buf[ic - 1]);
continue;
- case '\t': /* Normal ASCII whitespace. */
case ' ':
case ASCII_BREAK: /* Escape \: (breakpoint). */
- switch (p->tcol->buf[ic]) {
- case '\t':
- vn = term_tab_next(vis);
- break;
- case ' ':
- vn = vis + (*p->width)(p, ' ');
- break;
- case ASCII_BREAK:
- vn = vis;
- break;
- default:
- abort();
- }
+ vn = vis;
+ if (p->tcol->buf[ic] == ' ')
+ vn += (*p->width)(p, ' ');
/* Can break at the end of a word. */
if (breakline || vn > vtarget)
break;
@@ -317,12 +306,19 @@ term_fill(struct termp *p, size_t *nbr, size_t *vbr, size_t vtarget)
*vbr = vis;
continue;
- case ASCII_NBRSP: /* Non-breakable space. */
- p->tcol->buf[ic] = ' ';
- /* FALLTHROUGH */
- default: /* Printable character. */
+ default:
+ switch (p->tcol->buf[ic]) {
+ case '\t':
+ vis = term_tab_next(vis);
+ break;
+ case ASCII_NBRSP: /* Non-breakable space. */
+ p->tcol->buf[ic] = ' ';
+ /* FALLTHROUGH */
+ default: /* Printable character. */
+ vis += (*p->width)(p, p->tcol->buf[ic]);
+ break;
+ }
graph = 1;
- vis += (*p->width)(p, p->tcol->buf[ic]);
if (vis > vtarget && *nbr > 0)
return;
continue;