Subject: bug#13160: 24.3.50; [PATCH] man page completion support beyond man-db

From: Stefan Monnier <[email-masked]>
Date: Sun, 23 Dec 2012 20:20:53 -0500

[ Second part of my reply, sorry I had to leave in a hurry.  ]

>> That indeed the part of the change log I did not understand.  How does
>> the "man -k" argument relate to the "output flavor"?
> Well, I wrote in the proposed change log:
> 	Conveniently, the change entails that we don't have to guess the
> 	output format of `man -k' in order to pass it a useful regexp.
> The problem is that the page names are not necessarily anchored at the
> beginning of a summary line (there are examples in the proposed
> man-tests.el), so we can't always use "man -k ^foo" to find all summary
> lines for man page names starting with "foo".  A previous version of the
> patch posted here introduced a new variable holding a suitable regexp
> `anchor', which, however, would depend on the output format of `man -k',
> its flavour :-)

Oh, so you're saying that the regexp passed to "man -k" is matched not
against plain command names, but against lines of the same shape as the
output of "man -k"?  IOW, "man -k RE" is barely more than "man -k ^ |
grep RE"? Oh, yes, I see that now, indeed (I guess I did know that
a some point, but it doesn't even ring a remote bell).

> I think that parsing the full listing obtained with `man -k ^' is the
> best solution, it's just that storing the result in a plain list is not
> quite optimal, hence my babbling about tries.

The problem is not only the lookup time (which is usually small enough
not to be a problem), but the actual memory use (which slows down GC
among other things).  My earlier estimate was very optimistic since it
didn't take into account the `help-echo' text-property, which more than
doubles the size.

The easiest is probably to keep the current structure and just drop the
^ if the string is non-empty (we'll get lots more false-positives than
with the ^, but we still gain: even for some single letters, like
"man -k b", we get less than half as much data as "man -k ^").

        Stefan