Function: Man-parse-man-k

Man-parse-man-k is a byte-compiled function defined in man.el.gz.

Signature

(Man-parse-man-k)

Documentation

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

Source Code

;; Defined in /usr/src/emacs/lisp/man.el.gz
(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"
  (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)))