summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-06-22 12:04:05 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-06-22 12:04:05 +0000
commit5ff3d11b2e760657dd7adae6fb66cdc78ebd34ad (patch)
tree83cbd924ee999aea6b128ebb6553fb4a04fdba0d
parent39df69a9d68b05fb09136083471adee4d2817687 (diff)
downloadmandoc-5ff3d11b2e760657dd7adae6fb66cdc78ebd34ad.tar.gz
Added "Spacing" part of "Punctuation and Spacing" in mandoc.1 manual.
Fixed `Ds' meta-macro default width. Fixed -width and -offset "indent", "indent-two", and "left" widths. Fixed -width and -offset literal-word and numeric widths. Fixed off-by-one errors in whitespace output (schwarze@openbsd.org).
-rw-r--r--mandoc.122
-rw-r--r--mdoc_action.c2
-rw-r--r--mdoc_term.c18
-rw-r--r--term.c46
4 files changed, 52 insertions, 36 deletions
diff --git a/mandoc.1 b/mandoc.1
index 3aa48aa9..174d81e3 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -98,19 +98,19 @@ were provided.
.Pp
.Ex -std mandoc
.\" SUB-SECTION
-.Ss Punctuation
+.Ss Punctuation and Spacing
If punctuation is set apart from words, such as in the phrase
.Dq to be \&, or not to be ,
it's processed by
.Nm
-according to the following rules. Opening punctuation
+according to the following rules: opening punctuation
.Po
.Sq \&( ,
.Sq \&[ ,
and
.Sq \&{
.Pc
-is not followed by a space. Closing punctuation
+is not followed by a space; closing punctuation
.Po
.Sq \&. ,
.Sq \&, ,
@@ -128,6 +128,15 @@ is not preceded by whitespace.
If the input is
.Xr mdoc 7 ,
these rules are also applied to macro arguments when appropriate.
+.Pp
+White-space, in non-literal (normal) mode, is stripped from input and
+replaced on output by a single space. Thus, if you wish to preserve
+multiple spaces, they must be space-escaped
+.Sq \e\ .
+or used in a literal display mode, e.g.,
+.Sq \&.Bd \-literal
+in
+.Xr mdoc 7 .
.\" SUB-SECTION
.Ss Input Formats
The
@@ -253,14 +262,17 @@ A list or display following
.Sq \&.Ss
does not assert a prior vertical break, just as it doesn't with
.Sq \&.Sh .
-.\" LIST-ITEM
.It
The \-literal and \-unfilled
.Sq \&.Bd
displays types are synonyms, as are \-filled and \-ragged.
-.\" LIST-ITEM
.It
Words aren't hyphenated.
+.It
+In normal mode (not a literal block), blocks of spaces aren't preserved,
+so double spaces following sentence closure
+.Pq Qq French spacing
+are reduced to a single space.
.El
.\" SECTION
.Sh SEE ALSO
diff --git a/mdoc_action.c b/mdoc_action.c
index e1517a11..3941f4fb 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -614,7 +614,7 @@ post_bl_width(struct mdoc *m)
*/
if (0 == strcmp(p, "Ds"))
- width = 8;
+ width = 6;
else if (MDOC_MAX == (tok = mdoc_hash_find(m->htab, p)))
return(1);
else if (0 == (width = mdoc_macro2len(tok)))
diff --git a/mdoc_term.c b/mdoc_term.c
index c91ffb29..f1f28e7c 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -533,9 +533,9 @@ arg_width(const struct mdoc_argv *arg, int pos)
assert(pos < (int)arg->sz && pos >= 0);
assert(arg->value[pos]);
if (0 == strcmp(arg->value[pos], "indent"))
- return(INDENT);
+ return(INDENT + 3);
if (0 == strcmp(arg->value[pos], "indent-two"))
- return(INDENT * 2);
+ return(INDENT * 2 + 2);
if (0 == (len = (int)strlen(arg->value[pos])))
return(0);
@@ -545,13 +545,14 @@ arg_width(const struct mdoc_argv *arg, int pos)
break;
if (i == len - 1) {
- if ('n' == arg->value[pos][len - 1]) {
+ if ('n' == arg->value[pos][len - 1] ||
+ 'm' == arg->value[pos][len - 1]) {
v = (size_t)atoi(arg->value[pos]);
- return(v);
+ return(v + 2);
}
}
- return(strlen(arg->value[pos]) + 1);
+ return(strlen(arg->value[pos]) + 2);
}
@@ -603,9 +604,9 @@ arg_offset(const struct mdoc_argv *arg)
assert(*arg->value);
if (0 == strcmp(*arg->value, "left"))
- return(0);
+ return(INDENT - 1);
if (0 == strcmp(*arg->value, "indent"))
- return(INDENT);
+ return(INDENT + 1);
if (0 == strcmp(*arg->value, "indent-two"))
return(INDENT * 2);
@@ -1340,7 +1341,8 @@ termp_d1_pre(DECL_ARGS)
if (MDOC_BLOCK != node->type)
return(1);
term_newln(p);
- p->offset += (pair->offset = INDENT);
+ pair->offset = INDENT + 1;
+ p->offset += pair->offset;
return(1);
}
diff --git a/term.c b/term.c
index 41f606c2..ad42fc62 100644
--- a/term.c
+++ b/term.c
@@ -205,7 +205,7 @@ void
term_flushln(struct termp *p)
{
int i, j;
- size_t vsz, vis, maxvis, mmax, bp;
+ size_t vbl, vsz, vis, maxvis, mmax, bp;
/*
* First, establish the maximum columns of "visible" content.
@@ -250,35 +250,37 @@ term_flushln(struct termp *p)
}
/*
- * Do line-breaking. If we're greater than our
- * break-point and already in-line, break to the next
- * line and start writing. If we're at the line start,
- * then write out the word (TODO: hyphenate) and break
- * in a subsequent loop invocation.
+ * Choose the number of blanks to prepend: no blank at the
+ * beginning of a line, one between words -- but do not
+ * actually write them yet.
*/
+ vbl = (size_t)(0 == vis ? 0 : 1);
- if ( ! (TERMP_NOBREAK & p->flags)) {
- if (vis && vis + vsz > bp) {
- putchar('\n');
+ /*
+ * Find out whether we would exceed the right margin.
+ * If so, break to the next line. (TODO: hyphenate)
+ * Otherwise, write the chosen number of blanks now.
+ */
+ if (vis && vis + vbl + vsz > bp) {
+ putchar('\n');
+ if (TERMP_NOBREAK & p->flags) {
+ for (j = 0; j < (int)p->rmargin; j++)
+ putchar(' ');
+ vis = p->rmargin - p->offset;
+ } else {
for (j = 0; j < (int)p->offset; j++)
putchar(' ');
vis = 0;
- }
- } else if (vis && vis + vsz > bp) {
- putchar('\n');
- for (j = 0; j < (int)p->rmargin; j++)
+ }
+ } else {
+ for (j = 0; j < (int)vbl; j++)
putchar(' ');
- vis = p->rmargin - p->offset;
+ vis += vbl;
}
/*
- * Prepend a space if we're not already at the beginning
- * of the line, then the word.
+ * Finally, write out the word.
*/
-
- if (0 < vis++)
- putchar(' ');
-
for ( ; i < (int)p->col; i++) {
if (' ' == p->buf[i])
break;
@@ -292,7 +294,7 @@ term_flushln(struct termp *p)
* cause a newline and offset at the right margin.
*/
- if ((TERMP_NOBREAK & p->flags) && vis > maxvis) {
+ if ((TERMP_NOBREAK & p->flags) && vis >= maxvis) {
if ( ! (TERMP_NONOBREAK & p->flags)) {
putchar('\n');
for (i = 0; i < (int)p->rmargin; i++)
@@ -309,7 +311,7 @@ term_flushln(struct termp *p)
if (p->flags & TERMP_NOBREAK) {
if ( ! (TERMP_NONOBREAK & p->flags))
- for ( ; vis <= maxvis; vis++)
+ for ( ; vis < maxvis; vis++)
putchar(' ');
} else
putchar('\n');