source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Add a new term_flushln() flag TERMP_BRIND (if break, then
@ 2014-04-08  7:13 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-04-08  7:13 UTC (permalink / raw)
  To: source

Log Message:
-----------
Add a new term_flushln() flag TERMP_BRIND (if break, then indent) 
to control indentation of continuation lines in TERMP_NOBREAK mode.
In the past, this was always on; continue using it 
for .Bl, .Nm, .Fn, .Fo, and .HP, but no longer for .IP and .TP.

I looked at this because sthen@ reported the issue in a manual
of a Perl module from ports, but it affects base, too: This patch
reduces groff-mandoc differences in base by more than 15%.

Modified Files:
--------------
    mdocml:
        man_term.c
        mdoc_term.c
        term.c
        term.h

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.220
retrieving revision 1.221
diff -Lterm.c -Lterm.c -u -p -r1.220 -r1.221
--- term.c
+++ term.c
@@ -72,34 +72,27 @@ term_end(struct termp *p)
 }
 
 /*
- * Flush a line of text.  A "line" is loosely defined as being something
- * that should be followed by a newline, regardless of whether it's
- * broken apart by newlines getting there.  A line can also be a
- * fragment of a columnar list (`Bl -tag' or `Bl -column'), which does
- * not have a trailing newline.
- *
+ * Flush a chunk of text.  By default, break the output line each time
+ * the right margin is reached, and continue output on the next line
+ * at the same offset as the chunk itself.  By default, also break the
+ * output line at the end of the chunk.
  * The following flags may be specified:
  *
- *  - TERMP_NOBREAK: this is the most important and is used when making
- *    columns.  In short: don't print a newline and instead expect the
- *    next call to do the padding up to the start of the next column.
- *    p->trailspace may be set to 0, 1, or 2, depending on how many
- *    space characters are required at the end of the column.
- *
- *  - TERMP_DANGLE: don't newline when TERMP_NOBREAK is specified and
- *    the line is overrun, and don't pad-right if it's underrun.
- *
- *  - TERMP_HANG: like TERMP_DANGLE, but doesn't newline when
- *    overrunning, instead save the position and continue at that point
- *    when the next invocation.
- *
- *  In-line line breaking:
- *
- *  If TERMP_NOBREAK is specified and the line overruns the right
- *  margin, it will break and pad-right to the right margin after
- *  writing.  If maxrmargin is violated, it will break and continue
- *  writing from the right-margin, which will lead to the above scenario
- *  upon exit.  Otherwise, the line will break at the right margin.
+ *  - TERMP_NOBREAK: Do not break the output line at the right margin,
+ *    but only at the max right margin.  Also, do not break the output
+ *    line at the end of the chunk, such that the next call can pad to
+ *    the next column.  However, if less than p->trailspace blanks,
+ *    which can be 0, 1, or 2, remain to the right margin, the line
+ *    will be broken.
+ *  - TERMP_BRIND: If the chunk does not fit and the output line has
+ *    to be broken, start the next line at the right margin instead
+ *    of at the offset.  Used together with TERMP_NOBREAK for the tags
+ *    in various kinds of tagged lists.
+ *  - TERMP_DANGLE: Do not break the output line at the right margin,
+ *    append the next chunk after it even if this one is too long.
+ *    To be used together with TERMP_NOBREAK.
+ *  - TERMP_HANG: Like TERMP_DANGLE, and also suppress padding before
+ *    the next chunk if this column is not full.
  */
 void
 term_flushln(struct termp *p)
@@ -201,7 +194,7 @@ term_flushln(struct termp *p)
 			vend -= vis;
 			(*p->endline)(p);
 			p->viscol = 0;
-			if (TERMP_NOBREAK & p->flags) {
+			if (TERMP_BRIND & p->flags) {
 				vbl = p->rmargin;
 				vend += p->rmargin - p->offset;
 			} else
Index: term.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v
retrieving revision 1.99
retrieving revision 1.100
diff -Lterm.h -Lterm.h -u -p -r1.99 -r1.100
--- term.h
+++ term.h
@@ -77,11 +77,12 @@ struct	termp {
 #define	TERMP_PREKEEP	 (1 << 6)	/* ...starting with the next one. */
 #define	TERMP_SKIPCHAR	 (1 << 7)	/* Skip the next character. */
 #define	TERMP_NOBREAK	 (1 << 8)	/* See term_flushln(). */
-#define	TERMP_DANGLE	 (1 << 9)	/* See term_flushln(). */
-#define	TERMP_HANG	 (1 << 10)	/* See term_flushln(). */
-#define	TERMP_NOSPLIT	 (1 << 11)	/* See termp_an_pre/post(). */
-#define	TERMP_SPLIT	 (1 << 12)	/* See termp_an_pre/post(). */
-#define	TERMP_ANPREC	 (1 << 13)	/* See termp_an_pre(). */
+#define	TERMP_BRIND	 (1 << 9)	/* See term_flushln(). */
+#define	TERMP_DANGLE	 (1 << 10)	/* See term_flushln(). */
+#define	TERMP_HANG	 (1 << 11)	/* See term_flushln(). */
+#define	TERMP_NOSPLIT	 (1 << 12)	/* See termp_an_pre/post(). */
+#define	TERMP_SPLIT	 (1 << 13)	/* See termp_an_pre/post(). */
+#define	TERMP_ANPREC	 (1 << 14)	/* See termp_an_pre(). */
 	int		 *buf;		/* Output buffer. */
 	enum termenc	  enc;		/* Type of encoding. */
 	struct mchars	 *symtab;	/* Encoded-symbol table. */
Index: man_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -Lman_term.c -Lman_term.c -u -p -r1.144 -r1.145
--- man_term.c
+++ man_term.c
@@ -278,7 +278,7 @@ pre_literal(DECL_ARGS)
 		p->offset = p->rmargin;
 		p->rmargin = p->maxrmargin;
 		p->trailspace = 0;
-		p->flags &= ~TERMP_NOBREAK;
+		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		p->flags |= TERMP_NOSPACE;
 	}
 
@@ -547,7 +547,7 @@ pre_HP(DECL_ARGS)
 	}
 
 	if ( ! (MANT_LITERAL & mt->fl)) {
-		p->flags |= TERMP_NOBREAK;
+		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 2;
 	}
 
@@ -582,7 +582,7 @@ post_HP(DECL_ARGS)
 	switch (n->type) {
 	case (MAN_BODY):
 		term_newln(p);
-		p->flags &= ~TERMP_NOBREAK;
+		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
 		p->trailspace = 0;
 		p->offset = mt->offset;
 		p->rmargin = p->maxrmargin;
Index: mdoc_term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v
retrieving revision 1.262
retrieving revision 1.263
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.262 -r1.263
--- mdoc_term.c
+++ mdoc_term.c
@@ -819,14 +819,14 @@ termp_it_pre(DECL_ARGS)
 				 MDOC_Bd == n->next->child->tok))
 			break;
 
-		p->flags |= TERMP_NOBREAK | TERMP_HANG;
+		p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
 		p->trailspace = 1;
 		break;
 	case (LIST_tag):
 		if (MDOC_HEAD != n->type)
 			break;
 
-		p->flags |= TERMP_NOBREAK;
+		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 2;
 
 		if (NULL == n->next || NULL == n->next->child)
@@ -848,7 +848,7 @@ termp_it_pre(DECL_ARGS)
 	case (LIST_diag):
 		if (MDOC_HEAD != n->type)
 			break;
-		p->flags |= TERMP_NOBREAK;
+		p->flags |= TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 1;
 		break;
 	default:
@@ -1002,9 +1002,8 @@ termp_it_post(DECL_ARGS)
 	 * has munged them in the meanwhile.
 	 */
 
-	p->flags &= ~TERMP_DANGLE;
-	p->flags &= ~TERMP_NOBREAK;
-	p->flags &= ~TERMP_HANG;
+	p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
+			TERMP_DANGLE | TERMP_HANG);
 	p->trailspace = 0;
 }
 
@@ -1041,7 +1040,7 @@ termp_nm_pre(DECL_ARGS)
 		synopsis_pre(p, n->parent);
 
 	if (MDOC_HEAD == n->type && n->next->child) {
-		p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
+		p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
 		p->trailspace = 1;
 		p->rmargin = p->offset + term_len(p, 1);
 		if (NULL == n->child) {
@@ -1072,7 +1071,7 @@ termp_nm_post(DECL_ARGS)
 		p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
 	} else if (MDOC_HEAD == n->type && n->next->child) {
 		term_flushln(p);
-		p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
 		p->trailspace = 0;
 	} else if (MDOC_BODY == n->type && n->child)
 		term_flushln(p);
@@ -1561,7 +1560,7 @@ termp_fn_pre(DECL_ARGS)
 	if (pretty) {
 		rmargin = p->rmargin;
 		p->rmargin = p->offset + term_len(p, 4);
-		p->flags |= TERMP_NOBREAK | TERMP_HANG;
+		p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
 	}
 
 	assert(MDOC_TEXT == n->type);
@@ -1571,7 +1570,7 @@ termp_fn_pre(DECL_ARGS)
 
 	if (pretty) {
 		term_flushln(p);
-		p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+		p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
 		p->offset = p->rmargin;
 		p->rmargin = rmargin;
 	}
@@ -2063,14 +2062,16 @@ termp_fo_pre(DECL_ARGS)
 		if (pretty) {
 			rmargin = p->rmargin;
 			p->rmargin = p->offset + term_len(p, 4);
-			p->flags |= TERMP_NOBREAK | TERMP_HANG;
+			p->flags |= TERMP_NOBREAK | TERMP_BRIND |
+					TERMP_HANG;
 		}
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, "(");
 		p->flags |= TERMP_NOSPACE;
 		if (pretty) {
 			term_flushln(p);
-			p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+			p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
+					TERMP_HANG);
 			p->offset = p->rmargin;
 			p->rmargin = rmargin;
 		}
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-08  7:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-08  7:13 mdocml: Add a new term_flushln() flag TERMP_BRIND (if break, then schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).