discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* more spacing badness
@ 2010-09-10 21:14 Jason McIntyre
  2010-09-15 15:53 ` Kristaps Dzonsons
  0 siblings, 1 reply; 5+ messages in thread
From: Jason McIntyre @ 2010-09-10 21:14 UTC (permalink / raw)
  To: discuss

from vi(1):

     ex [-FRrSsv] [-c cmd] [-t tag] [-w size] [file ...]
     vi [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]
     view [-eFrS] [-c cmd] [-t tag] [-w size] [file ...]

i wanted to format those nicely (in my opinion anyway) so i tried to put
a double space between "vi" and its args. current code does this:

	.Nm vi
	.Op Fl eFRrS
	.Op Fl c Ar cmd
	.Op Fl t Ar tag
	.Op Fl w Ar size
	.Op Ar

so i tried:

	.Nm vi\ \&

old and new groff produce:

	vi  [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]

but mandoc seems to inject a tab:

	vi    [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]

jmc
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more spacing badness
  2010-09-10 21:14 more spacing badness Jason McIntyre
@ 2010-09-15 15:53 ` Kristaps Dzonsons
  2010-09-21 23:05   ` Ingo Schwarze
  0 siblings, 1 reply; 5+ messages in thread
From: Kristaps Dzonsons @ 2010-09-15 15:53 UTC (permalink / raw)
  To: discuss

> from vi(1):
> 
>      ex [-FRrSsv] [-c cmd] [-t tag] [-w size] [file ...]
>      vi [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]
>      view [-eFrS] [-c cmd] [-t tag] [-w size] [file ...]
> 
> i wanted to format those nicely (in my opinion anyway) so i tried to put
> a double space between "vi" and its args. current code does this:

I gather you're trying to align to the maximum length Nm token.  I agree
it looks better.  Something to think about later, maybe.

> so i tried:
> 
> 	.Nm vi\ \&
> 
> old and new groff produce:
> 
> 	vi  [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]
> 
> but mandoc seems to inject a tab:
> 
> 	vi    [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]

My last commit fixes this in a general way.  The problem was "\ \&"
being read as the string length.  Now string length calculations (for
-Tascii, -Tpdf, and -Tps) all take into account escapes.  This lifts a
long-standing feature request in the TODO.

Thanks,

Kristaps
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more spacing badness
  2010-09-15 15:53 ` Kristaps Dzonsons
@ 2010-09-21 23:05   ` Ingo Schwarze
  2010-09-22  7:09     ` Jason McIntyre
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Schwarze @ 2010-09-21 23:05 UTC (permalink / raw)
  To: discuss

Hi Kristaps,

Kristaps Dzonsons wrote on Wed, Sep 15, 2010 at 05:53:58PM +0200:
> Jason McIntyre wrote:

>> so i tried:
>> 
>> 	.Nm vi\ \&
>> 
>> old and new groff produce:
>> 
>> 	vi  [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]
>> 
>> but mandoc seems to inject a tab:
>> 
>> 	vi    [-eFRrS] [-c cmd] [-t tag] [-w size] [file ...]

> My last commit fixes this in a general way.  The problem was "\ \&"
> being read as the string length.  Now string length calculations (for
> -Tascii, -Tpdf, and -Tps) all take into account escapes.  This lifts a
> long-standing feature request in the TODO.

WOW, great.
I wouldn't have thought that could be done with so little code.

Admittedly, it's a bit of code duplication, but by far less annoying
than i would have expected.  And it's very nice to have from a
user perspective.  Thanks!


Of course, i was eager to see whether Jason's "vi\ \&" would now work.
Guess what - it didn't.  I first had to fix *two* bugs in my own code.

First, my favourite function term_flushline() handled trailing white
space correctly, but not trailing escaped blank characters.  In the
initial parsing loop, escaped whitespace is counted as normal
characters, then in the final output loop, it gets converted to
normal blanks, and finally, normal blanks (which break out of the
initial parsing loop) are counted again, so trailing escaped blanks
ended up being counted twice against the column width.

Having fixed that one, Jason's "vi\ \&" still wouldn't work.
The reason was a quirk implemented for mdoc's .Bl -hang lists.
In such lists, when the head is wider than the declared head
width, the body gets pushed ahead to make room for the head;
when the head is shorter, the body gets aligned at the declared
position.  The quirk being that when the head is exactly one
character shorter than the declared width, the body gets pulled
back one character - for whatever reason.  That quirk got triggered
and defeated Jason's nicely escaped blank.

So, the second fix is to remove the -hang flag from the SYNOPSIS
.Nm block handling.  I don't remember why i put that flag there
in the first place, it is clearly not needed.  The width is
calculated such that the header will always fit, so pushing ahead
is never needed, and we certainly do not want to pull back.

OK?

Yours,
  Ingo


Index: mdoc_term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mdoc_term.c,v
retrieving revision 1.104
diff -u -p -r1.104 mdoc_term.c
--- mdoc_term.c	20 Sep 2010 20:02:27 -0000	1.104
+++ mdoc_term.c	21 Sep 2010 22:34:20 -0000
@@ -1027,7 +1027,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 | TERMP_HANG;
+		p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
 		p->rmargin = p->offset + term_len(p, 1) +
 		    (NULL == n->child ? term_strlen(p, m->name) :
 		     MDOC_TEXT == n->child->type ?
@@ -1049,7 +1049,7 @@ termp_nm_post(DECL_ARGS)
 
 	if (MDOC_HEAD == n->type && n->next->child) {
 		term_flushln(p);
-		p->flags &= ~(TERMP_NOBREAK | TERMP_HANG);
+		p->flags &= ~TERMP_NOBREAK;
 	} else if (MDOC_BODY == n->type && n->child) {
 		term_flushln(p);
 		p->flags &= ~TERMP_NOLPAD;
Index: term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term.c,v
retrieving revision 1.50
diff -u -p -r1.50 term.c
--- term.c	21 Sep 2010 22:33:41 -0000	1.50
+++ term.c	21 Sep 2010 22:34:20 -0000
@@ -130,6 +130,7 @@ term_flushln(struct termp *p)
 	size_t		 vbl;   /* number of blanks to prepend to output */
 	size_t		 vend;	/* end of word visual position on output */
 	size_t		 bp;    /* visual right border position */
+	size_t		 dv;    /* temporary for visual pos calculations */
 	int		 j;     /* temporary loop index for p->buf */
 	int		 jhy;	/* last hyph before overflow w/r/t j */
 	size_t		 maxvis; /* output position of visible boundary */
@@ -233,7 +234,9 @@ term_flushln(struct termp *p)
 				j = i;
 				while (' ' == p->buf[i])
 					i++;
-				vbl += (i - j) * (*p->width)(p, ' ');
+				dv = (i - j) * (*p->width)(p, ' ');
+				vbl += dv;
+				vend += dv;
 				break;
 			}
 			if (ASCII_NBRSP == p->buf[i]) {
@@ -260,7 +263,6 @@ term_flushln(struct termp *p)
 				p->viscol += (*p->width)(p, p->buf[i]);
 			}
 		}
-		vend += vbl;
 		vis = vend;
 	}
 

--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more spacing badness
  2010-09-21 23:05   ` Ingo Schwarze
@ 2010-09-22  7:09     ` Jason McIntyre
  2010-09-22  8:11       ` Kristaps Dzonsons
  0 siblings, 1 reply; 5+ messages in thread
From: Jason McIntyre @ 2010-09-22  7:09 UTC (permalink / raw)
  To: discuss

On Wed, Sep 22, 2010 at 01:05:13AM +0200, Ingo Schwarze wrote:
> 
> > My last commit fixes this in a general way.  The problem was "\ \&"
> > being read as the string length.  Now string length calculations (for
> > -Tascii, -Tpdf, and -Tps) all take into account escapes.  This lifts a
> > long-standing feature request in the TODO.
> 
> WOW, great.
> I wouldn't have thought that could be done with so little code.
> 
> Admittedly, it's a bit of code duplication, but by far less annoying
> than i would have expected.  And it's very nice to have from a
> user perspective.  Thanks!
> 

not only that, but somewhere along the way the SYNOPSIS for test(1) got
fixed! now we have:

	[ test ]
instead of
	[    test ]

not only that, but the -column alignments in sysctl(3) got fixed
somewhere along the way too.

super!

> 
> Of course, i was eager to see whether Jason's "vi\ \&" would now work.
> Guess what - it didn't.  I first had to fix *two* bugs in my own code.
> 
> First, my favourite function term_flushline() handled trailing white
> space correctly, but not trailing escaped blank characters.  In the
> initial parsing loop, escaped whitespace is counted as normal
> characters, then in the final output loop, it gets converted to
> normal blanks, and finally, normal blanks (which break out of the
> initial parsing loop) are counted again, so trailing escaped blanks
> ended up being counted twice against the column width.
> 
> Having fixed that one, Jason's "vi\ \&" still wouldn't work.
> The reason was a quirk implemented for mdoc's .Bl -hang lists.
> In such lists, when the head is wider than the declared head
> width, the body gets pushed ahead to make room for the head;
> when the head is shorter, the body gets aligned at the declared
> position.  The quirk being that when the head is exactly one
> character shorter than the declared width, the body gets pulled
> back one character - for whatever reason.  That quirk got triggered
> and defeated Jason's nicely escaped blank.
> 
> So, the second fix is to remove the -hang flag from the SYNOPSIS
> .Nm block handling.  I don't remember why i put that flag there
> in the first place, it is clearly not needed.  The width is
> calculated such that the header will always fit, so pushing ahead
> is never needed, and we certainly do not want to pull back.
> 
> OK?
> 

with this my vi hack does work correctly. thanks.

jmc
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: more spacing badness
  2010-09-22  7:09     ` Jason McIntyre
@ 2010-09-22  8:11       ` Kristaps Dzonsons
  0 siblings, 0 replies; 5+ messages in thread
From: Kristaps Dzonsons @ 2010-09-22  8:11 UTC (permalink / raw)
  To: discuss

> not only that, but somewhere along the way the SYNOPSIS for test(1) got
> fixed! now we have:
> 
> 	[ test ]
> instead of
> 	[    test ]

Yes, I forgot to mention that test(1) was used as test input.  This was 
an effect of those commits.

> not only that, but the -column alignments in sysctl(3) got fixed
> somewhere along the way too.
> 
> super!

Great!  I hadn't noticed that.

>> Of course, i was eager to see whether Jason's "vi\ \&" would now work.
>> Guess what - it didn't.  I first had to fix *two* bugs in my own code.
>>
>> First, my favourite function term_flushline() handled trailing white
>> space correctly, but not trailing escaped blank characters.  In the
>> initial parsing loop, escaped whitespace is counted as normal
>> characters, then in the final output loop, it gets converted to
>> normal blanks, and finally, normal blanks (which break out of the
>> initial parsing loop) are counted again, so trailing escaped blanks
>> ended up being counted twice against the column width.
>>
>> Having fixed that one, Jason's "vi\ \&" still wouldn't work.
>> The reason was a quirk implemented for mdoc's .Bl -hang lists.
>> In such lists, when the head is wider than the declared head
>> width, the body gets pushed ahead to make room for the head;
>> when the head is shorter, the body gets aligned at the declared
>> position.  The quirk being that when the head is exactly one
>> character shorter than the declared width, the body gets pulled
>> back one character - for whatever reason.  That quirk got triggered
>> and defeated Jason's nicely escaped blank.
>>
>> So, the second fix is to remove the -hang flag from the SYNOPSIS
>> .Nm block handling.  I don't remember why i put that flag there
>> in the first place, it is clearly not needed.  The width is
>> calculated such that the header will always fit, so pushing ahead
>> is never needed, and we certainly do not want to pull back.
>>
>> OK?
>>
> 
> with this my vi hack does work correctly. thanks.

Ingo, feel free to commit it, then, if it doesn't regress anything.

Thanks,

Kristaps
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-09-22  8:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-10 21:14 more spacing badness Jason McIntyre
2010-09-15 15:53 ` Kristaps Dzonsons
2010-09-21 23:05   ` Ingo Schwarze
2010-09-22  7:09     ` Jason McIntyre
2010-09-22  8:11       ` Kristaps Dzonsons

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).