Subject: Re: bug#3717: M-x man completion

From: Kevin Ryde <[email-masked]>
Date: Wed, 25 Nov 2009 09:58:09 +1100

Juri Linkov <[email-masked]> writes:
>
> man-completion.el are the cache for `man -k'

It's pretty vital for me, since man -k is about 1 to 2 seconds per run,
which is too slow if you hit tab a few times (twice each to see the
completion list).

> handling same names in different sections.

It's been through a few goes at making it friendly for both page names
and file names and stuff. :-)

> Also part of man-completion.el deals with man-completion-at-point
> that returns a man page name as a string found at point.

That's another been though loosening and tightening.  I quite like what
I got to for line-break hyphenations.  I looked last week at
Man-hyphenated-reference-regexp and wondered if it was the same thing,
but the docstring of Man-possibly-hyphenated-word about returning the
previous line's word like "tcgetp-" suggested not.  If it is the same
then a U+2010 hyphen could be worked in there -- it comes out of recent
groff "-Tutf8".

If nothing else then give the following bit a go.  man-db truncates page
names longer than about half the screen width.  (Long names arise from
perl classes.)

2009-11-24  Kevin Ryde  <[email-masked]>

	* man.el (Man-completion-table): default-directory "/" in case
	doesn't otherwise exist.  process-environment COLUMNS=999 so as
	not to truncate long names.  process-connection-type pipe to avoid
	any chance of hitting the pseudo-tty TIOCGWINSZ.

--- man.el.~1.187.~	2009-11-25 09:08:03.000000000 +1100
+++ man.el	2009-11-25 09:26:02.000000000 +1100
@@ -754,13 +754,17 @@
    ((memq action '(t nil))
     (let ((table '()))
       (with-temp-buffer
+	(setq default-directory "/") ;; in case inherited doesn't exist
         ;; Actually for my `man' the arg is a regexp.  Don't know how
         ;; standard that is.  Also, it's not clear what kind of
         ;; regexp are accepted: under GNU/Linux it seems it's ERE-style,
         ;; whereas under MacOSX it seems to be BRE-style and
         ;; doesn't accept backslashes at all.  Let's not bother to
         ;; quote anything.
-        (call-process "man" nil '(t nil) nil "-k" (concat "^" string))
+ 	(let ((process-connection-type nil) ;; pipe
+	      (process-environment (copy-sequence process-environment)))
+	  (setenv "COLUMNS" "999") ;; don't truncate long names
+	  (call-process "man" nil '(t nil) nil "-k" (concat "^" string)))
         (goto-char (point-min))
         (while (re-search-forward "^[^ \t\n]+" nil t)
           (push (match-string 0) table)))