summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2013-12-23 02:19:57 +0000
committerschwarze <schwarze@openbsd.org>2013-12-23 02:19:57 +0000
commitbcb728413546938d7c76f38e03ce3a7da9948bbf (patch)
tree87805e77770a475708ad7e59e10c526a61e8f85f
parentsync (diff)
downloadwireguard-openbsd-bcb728413546938d7c76f38e03ce3a7da9948bbf.tar.xz
wireguard-openbsd-bcb728413546938d7c76f38e03ce3a7da9948bbf.zip
Implement a long-standing desideratum,
hanging indentation for .Fn in SYNOPSIS mode, exploiting the new trailspace feature by deliberately *NOT* using it.
-rw-r--r--usr.bin/mandoc/mdoc_term.c18
-rw-r--r--usr.bin/mandoc/term.c19
2 files changed, 32 insertions, 5 deletions
diff --git a/usr.bin/mandoc/mdoc_term.c b/usr.bin/mandoc/mdoc_term.c
index aa1a687af1d..fdf0b2b3858 100644
--- a/usr.bin/mandoc/mdoc_term.c
+++ b/usr.bin/mandoc/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.152 2013/12/22 23:33:52 schwarze Exp $ */
+/* $Id: mdoc_term.c,v 1.153 2013/12/23 02:19:57 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -1534,6 +1534,7 @@ termp_ft_pre(DECL_ARGS)
static int
termp_fn_pre(DECL_ARGS)
{
+ size_t width, rmargin = 0;
int pretty;
pretty = MDOC_SYNPRETTY & n->flags;
@@ -1543,11 +1544,25 @@ termp_fn_pre(DECL_ARGS)
if (NULL == (n = n->child))
return(0);
+ if (pretty) {
+ width = term_len(p, 4);
+ rmargin = p->rmargin;
+ p->rmargin = p->offset + width;
+ p->flags |= TERMP_NOBREAK | TERMP_HANG;
+ }
+
assert(MDOC_TEXT == n->type);
term_fontpush(p, TERMFONT_BOLD);
term_word(p, n->string);
term_fontpop(p);
+ if (pretty) {
+ term_flushln(p);
+ p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+ p->offset = p->rmargin;
+ p->rmargin = rmargin;
+ }
+
p->flags |= TERMP_NOSPACE;
term_word(p, "(");
p->flags |= TERMP_NOSPACE;
@@ -1570,6 +1585,7 @@ termp_fn_pre(DECL_ARGS)
if (pretty) {
p->flags |= TERMP_NOSPACE;
term_word(p, ";");
+ term_flushln(p);
}
return(0);
diff --git a/usr.bin/mandoc/term.c b/usr.bin/mandoc/term.c
index bca3dedb110..7f9340661a7 100644
--- a/usr.bin/mandoc/term.c
+++ b/usr.bin/mandoc/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.72 2013/12/22 23:33:52 schwarze Exp $ */
+/* $Id: term.c,v 1.73 2013/12/23 02:19:57 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -116,7 +116,12 @@ term_flushln(struct termp *p)
* First, establish the maximum columns of "visible" content.
* This is usually the difference between the right-margin and
* an indentation, but can be, for tagged lists or columns, a
- * small set of values.
+ * small set of values.
+ *
+ * The following unsigned-signed subtractions look strange,
+ * but they are actually correct. If the int p->overstep
+ * is negative, it gets sign extended. Subtracting that
+ * very large size_t effectively adds a small number to dv.
*/
assert (p->rmargin >= p->offset);
dv = p->rmargin - p->offset;
@@ -195,7 +200,11 @@ term_flushln(struct termp *p)
if (0 < ntab)
vbl += ntab * p->tabwidth;
- /* Remove the p->overstep width. */
+ /*
+ * Remove the p->overstep width.
+ * Again, if p->overstep is negative,
+ * sign extension does the right thing.
+ */
bp += (size_t)p->overstep;
p->overstep = 0;
@@ -271,8 +280,10 @@ term_flushln(struct termp *p)
* If we have overstepped the margin, temporarily move
* it to the right and flag the rest of the line to be
* shorter.
+ * If there is a request to keep the columns together,
+ * allow negative overstep when the column is not full.
*/
- if (p->overstep < 0)
+ if (p->trailspace && p->overstep < 0)
p->overstep = 0;
return;