shithub: neatroff

Download patch

ref: 860466c3d6b463f1a149463c31aeeb96543f6bd2
parent: ad010bdfe465964f5c901be74d3abeff4edd94ce
author: Ali Gholami Rudi <ali@rudi.ir>
date: Fri Sep 26 12:04:55 EDT 2014

ren: better diversion output in fill-mode

--- a/ren.c
+++ b/ren.c
@@ -24,6 +24,7 @@
 static struct div divs[NPREV];	/* diversion stack */
 static struct div *cdiv;	/* current diversion */
 static int ren_div;		/* rendering a diversion */
+static int ren_divvs;		/* the amount of .v in diversions */
 static int trap_em = -1;	/* end macro */
 
 static int ren_nl;		/* just after a newline */
@@ -109,6 +110,11 @@
 	ren_div--;
 }
 
+void tr_divvs(char **args)
+{
+	ren_divvs = eval(args[1], 'u');
+}
+
 void tr_transparent(char **args)
 {
 	if (cdiv)
@@ -151,16 +157,16 @@
 static void ren_sp(int n, int nodiv)
 {
 	ren_first();
+	if (!n && ren_div && ren_divvs && !n_u)
+		n = ren_divvs;	/* .v at the time of diversion */
+	ren_divvs = 0;
 	n_ns = 0;
-	/* ignore .sp without arguments when reading diversions */
-	if (!n && ren_div && !n_u)
-		return;
 	n_d += n ? n : n_v;
 	if (n_d > n_h)
 		n_h = n_d;
 	if (cdiv && !nodiv)
-		sbuf_printf(&cdiv->sbuf, "%csp %du\n", c_cc, n ? n : n_v);
-	else
+		sbuf_printf(&cdiv->sbuf, "%c%s %du\n", c_cc, TR_DIVVS, n_v);
+	if (!cdiv)
 		n_nl = n_d;
 }
 
--- a/roff.h
+++ b/roff.h
@@ -343,6 +343,7 @@
 void tr_di(char **args);
 void tr_divbeg(char **args);
 void tr_divend(char **args);
+void tr_divvs(char **args);
 void tr_dt(char **args);
 void tr_em(char **args);
 void tr_ev(char **args);
@@ -403,6 +404,7 @@
 /* internal commands */
 #define TR_DIVBEG	"\07<"	/* diversion begins */
 #define TR_DIVEND	"\07>"	/* diversion ends */
+#define TR_DIVVS	"\07V"	/* the amount of \n(.v inside diversions */
 #define TR_POPREN	"\07P"	/* exit render_rec() */
 
 /* mapping register, macro and environment names to indices */
--- a/tr.c
+++ b/tr.c
@@ -869,6 +869,7 @@
 } cmds[] = {
 	{TR_DIVBEG, tr_divbeg},
 	{TR_DIVEND, tr_divend},
+	{TR_DIVVS, tr_divvs},
 	{TR_POPREN, tr_popren},
 	{"ab", tr_ab, mkargs_eol},
 	{"ad", tr_ad},