Re: reformatting man pages at SIGWINCH

Alejandro Colomar <[email protected]>
Newsgroups gmane.linux.man,gmane.comp.tex.texinfo.general,gmane.comp.printing.groff.general
Message-ID <[email protected]>
Hi Dirk,

On 4/10/23 21:05, Dirk Gouders wrote:
>> For something simpler, you could just count words since the start of the
>> section divided by total words in the section.  That should be fast, and
>> I expect, also quite precise.  Hyphenating might work against you on
>> this, but on average it shouldn't move you too much.
> 
> very pragmatic -- very effective, thanks for that suggestion.  I
> started with implementing a simpler version of that (no counting of all
> words in the section):
> 
> - Backwards count words until we reach an empty line, the section
>   header or the beginning of the document
> 
>         Stop if it was the section header or beginning of the document
> 
>         Continue and just count empty lines until we reach the
>         section header or the beginning of the document

Hmmmm, good idea.

$ man gcc 2>/dev/null | grep "^$" | wc -l
5462
$ man gcc 2>/dev/null | grep "^$" | wc -l
5462
$ man gcc 2>/dev/null | grep "^$" | wc -l
5464

$ man tzset 2>/dev/null | grep "^$" | wc -l
41
$ man tzset 2>/dev/null | grep "^$" | wc -l
41
$ man tzset 2>/dev/null | grep "^$" | wc -l
41

$ man bash 2>/dev/null | grep "^$" | wc -l
657
$ man bash 2>/dev/null | grep "^$" | wc -l
657
$ man bash 2>/dev/null | grep "^$" | wc -l
658


Of course there were important resizes between those invocations. 

> 
> This relies on the assumption that horizontal resizes don't create or
> delete emty lines and it still has the weakness that manual pages
> (e.g. bash(1)) contain large areas without empty lines but it's
> definitely better than just staying at the position as it was before.

 
That should give you a quite precise idea of where you were.

> 
> If it turns out to still be too weak, I could count all words between
> two empty lines and set that in relation to the words from the
> preceeding empty line.
> 
> But perhaps, I now learn that empty lines are by no means that constant
> value that I assume...

They seem to be constant.  Only with the shortest terminal size I can
have, that number changes, and only by one or two per entire page.

> 
> Dirk

Cheers,
Alex

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
OpenPGP_signature (application/pgp-signature, 833 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.