;; Read in and display parts of Unix manual.
;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 1, or (at your option)
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
(defun manual-entry (topic &optional section)
"Display the Unix manual entry for TOPIC.
TOPIC is either the title of the entry, or has the form TITLE(SECTION)
where SECTION is the desired section of the manual, as in `tty(4)'."
(interactive "sManual entry (topic): ")
(string-match "\\`[ \t]*\\([^( \t]+\\)[ \t]*(\\(.+\\))[ \t]*\\'" topic))
(setq section (substring topic (match-beginning 2)
topic (substring topic (match-beginning 1)
(with-output-to-temp-buffer "*Manual Entry*"
(buffer-flush-undo standard-output)
(set-buffer standard-output)
(message "Looking for formatted entry for %s%s..."
topic (if section (concat "(" section ")") ""))
(let ((dirlist manual-formatted-dirlist)
(if (and section (or (file-exists-p
(setq name (concat manual-formatted-dir-prefix
(setq name (concat manual-formatted-dir-prefix
(let* ((dir (car dirlist))
(name1 (concat dir "/" topic "."
(1+ (or (string-match "\\.[^./]*$" dir)
(if (file-exists-p name1)
(setq completions (file-name-all-completions
(concat topic "." (or section ""))
(insert-man-file (concat dir "/" (car completions)))
(setq completions (cdr completions))))
(setq dirlist (cdr dirlist)))))
(message "No formatted entry, invoking man %s%s..."
(if section (concat section " ") "") topic)
(call-process manual-program nil t nil section topic)
(call-process manual-program nil t nil topic))
(error (buffer-substring 1 (point)))))))
(message "Cleaning manual entry for %s..." topic)
(set-buffer-modified-p nil)
;; Hint: BS stands form more things than "back space"
;; Nuke underlining and overstriking (only by the same letter)
(while (search-forward "\b" nil t)
(let* ((preceding (char-after (- (point) 2)))
(following (following-char)))
(cond ((= preceding following)
(delete-region (1- (point)) (1+ (point)))))))
;; Nuke headers: "MORE(1) UNIX Programmer's Manual MORE(1)"
(while (re-search-forward "^ *\\([A-Za-z][-_A-Za-z0-9]*([0-9A-Z]+)\\).*\\1$" nil t)
;; Nuke footers: "Printed 12/3/85 27 April 1981 1"
;; Sun appear to be on drugz:
;; "Sun Release 3.0
\ eB
\ f Last change: 1 February 1985 1"
;; " Hewlett-Packard -1- (printed 12/31/99)" FMHWA12ID!!
;; System V (well WICATs anyway):
;; "Page 1 (printed 7/24/85)"
;; Who is administering PCP to these corporate bozos?
(while (re-search-forward
(cond ((eq system-type 'hpux)
"^[ \t]*Hewlett-Packard\\(\\| Company\\)[ \t]*- [0-9]* -.*$")
((eq system-type 'usg-unix-v)
"^ *Page [0-9]*.*(printed [0-9/]*)$")
"^\\(Printed\\|Sun Release\\) [0-9].*[0-9]$"))
(while (re-search-forward "\n\n\n\n*" nil t)
;; Nuke blanks lines at start.
(skip-chars-forward "\n")
(delete-region (point-min) (point)))
(defun insert-man-file (name)
;; Insert manual file (unpacked as necessary) into buffer
(if (or (equal (substring name -2) ".Z")
(string-match "/cat[0-9][a-z]?\\.Z/" name))
(call-process "zcat" name t nil)
(if (equal (substring name -2) ".z")
(call-process "pcat" nil t nil name)
(insert-file-contents name))))