+(defvar Man-man-k-use-anchor
+ ;; man-db or man-1.*
+ (memq system-type '(gnu gnu/linux gnu/kfreebsd))
+ "If non-nil prepend ^ to the prefix passed to \"man -k\" for completion.
+The value should be nil if \"man -k ^PREFIX\" may omit some man
+pages whose names start with PREFIX.
+
+Currently, the default value depends on `system-type' and is
+non-nil where the standard man programs are known to behave
+properly. Setting the value to nil always gives correct results
+but computing the list of completions may take a bit longer.")
+
+(defun Man-parse-man-k ()
+ "Parse \"man -k\" output and return the list of page names.
+
+The current buffer should contain the output of a command of the
+form \"man -k keyword\", which is traditionally also available with
+apropos(1).
+
+While POSIX man(1p) is a bit vague about what to expect here,
+this function tries to parse some commonly used formats, which
+can be described in the following informal way, with square brackets
+indicating optional parts and whitespace being interpreted
+somewhat loosely.
+
+foo[, bar [, ...]] [other stuff] (sec) - description
+foo(sec)[, bar(sec) [, ...]] [other stuff] - description
+
+For more details and some regression tests, please see
+test/automated/man-tests.el in the emacs bzr repository."
+ (goto-char (point-min))
+ ;; See man-tests for data about which systems use which format (hopefully we
+ ;; will be able to simplify the code if/when some of those formats aren't
+ ;; used any more).
+ (let (table)
+ (while (search-forward-regexp "^\\([^ \t,\n]+\\)\\(.*?\\)\
+\\(?:[ \t]\\(([^ \t,\n]+?)\\)\\)?\\(?:[ \t]+- ?\\(.*\\)\\)?$" nil t)
+ (let ((section (match-string 3))
+ (description (match-string 4))
+ (bound (match-end 2)))
+ (goto-char (match-end 1))
+ (while
+ (progn
+ ;; The first regexp grouping may already match the section
+ ;; tacked on to the name, which is ok since for the formats we
+ ;; claim to support the third (non-shy) grouping does not
+ ;; match in this case, i.e., section is nil.
+ (push (propertize (concat (match-string 1) section)
+ 'help-echo description)
+ table)
+ (search-forward-regexp "\\=, *\\([^ \t,]+\\)" bound t)))))
+ (nreverse table)))
+