Annotation of 43BSD/contrib/emacs/lisp/man.el, revision 1.1.1.1

1.1       root        1: ;; Read in and display parts of Unix manual.
                      2: ;; Copyright (C) 1985 Richard M. Stallman.
                      3: 
                      4: ;; This file is part of GNU Emacs.
                      5: 
                      6: ;; GNU Emacs is distributed in the hope that it will be useful,
                      7: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                      8: ;; accepts responsibility to anyone for the consequences of using it
                      9: ;; or for whether it serves any particular purpose or works at all,
                     10: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     11: ;; License for full details.
                     12: 
                     13: ;; Everyone is granted permission to copy, modify and redistribute
                     14: ;; GNU Emacs, but only under the conditions described in the
                     15: ;; GNU Emacs General Public License.   A copy of this license is
                     16: ;; supposed to have been given to you along with GNU Emacs so you
                     17: ;; can know your rights and responsibilities.  It should be in a
                     18: ;; file named COPYING.  Among other things, the copyright notice
                     19: ;; and this notice must be preserved on all copies.
                     20: 
                     21: 
                     22: (defun manual-entry (topic &optional section)
                     23:   "Display the Unix manual entry for TOPIC."
                     24:   (interactive "sManual entry (topic): ")
                     25:   (if (and (null section)
                     26:           (string-match "\\`[ \t]*\\([^( \t]+\\)[ \t]*(\\(.+\\))[ \t]*\\'" topic))
                     27:       (setq section (substring topic (match-beginning 2)
                     28:                                     (match-end 2))
                     29:            topic (substring topic (match-beginning 1)
                     30:                                   (match-end 1))))
                     31:   (with-output-to-temp-buffer "*Manual Entry*"
                     32:     (buffer-flush-undo standard-output)
                     33:     (save-excursion
                     34:       (set-buffer standard-output)
                     35:       (message "Looking for formatted entry for %s%s..."
                     36:               topic (if section (concat "(" section ")") ""))
                     37:       (let ((dirlist '("/usr/man/cat1"
                     38:                       "/usr/man/cat2" "/usr/man/cat3" "/usr/man/cat4"
                     39:                       "/usr/man/cat5" "/usr/man/cat6" "/usr/man/cat7"
                     40:                       "/usr/man/cat8" "/usr/man/catl" "/usr/man/catn"))
                     41:            name)
                     42:        (if (and section (file-exists-p
                     43:                           (setq name (concat "/usr/man/cat" (aref section 0)
                     44:                                              "/"
                     45:                                              topic "." section))))
                     46:            (insert-file-contents name)
                     47:          (while dirlist
                     48:            (let* ((dir (car dirlist))
                     49:                   (name1 (concat dir "/"
                     50:                                  topic "." (or section (substring dir -1))))
                     51:                   completions)
                     52:              (if (file-exists-p name1)
                     53:                  (insert-file-contents name1)
                     54:                (condition-case ()
                     55:                    (progn
                     56:                      (setq completions (file-name-all-completions topic dir))
                     57:                      (while completions
                     58:                        (insert-file-contents (concat dir "/" (car completions)))
                     59:                        (setq completions (cdr completions))))
                     60:                  (file-error nil)))
                     61:              (goto-char (point-max)))
                     62:            (setq dirlist (cdr dirlist)))))
                     63: 
                     64:       (if (= (buffer-size) 0)
                     65:          (progn
                     66:            (message "No formatted entry, invoking man %s%s..."
                     67:                     (if section (concat section " ") "") topic)
                     68:            (if section
                     69:                (call-process "/usr/ucb/man" nil t nil section topic)
                     70:                (call-process "/usr/ucb/man" nil t nil topic))
                     71:            (if (< (buffer-size) 80)
                     72:                (progn
                     73:                  (goto-char (point-min))
                     74:                  (end-of-line)
                     75:                  (error (buffer-substring 1 (point)))))))
                     76: 
                     77:       (let ((case-fold-search nil))
                     78:        (message "Cleaning manual entry for %s..." topic)
                     79: 
                     80:        ;; Nuke underlining
                     81:        (goto-char (point-min))
                     82:        (while (search-forward "_\b" nil t)
                     83:          (replace-match ""))
                     84: 
                     85:        ;; Nuke headers: "MORE(1) UNIX Programmer's Manual MORE(1)"
                     86:        (goto-char (point-min))
                     87:        (while (re-search-forward "^[A-Za-z][A-Za-z]*([0-9]*).*)$" nil t)
                     88:          (replace-match ""))
                     89: 
                     90:        ;; Nuke footers: "Printed 12/3/85       27 April 1981   1"
                     91:        (goto-char (point-min))
                     92:        (while (re-search-forward "^Printed [0-9].*[0-9]$" nil t)
                     93:          (replace-match ""))
                     94: 
                     95:        ;; Crunch blank lines
                     96:        (goto-char (point-min))
                     97:        (while (re-search-forward "\n\n\n\n*" nil t)
                     98:          (replace-match "\n\n"))
                     99: 
                    100:        ;; Nuke blanks lines at start.
                    101:        (goto-char (point-min))
                    102:        (skip-chars-forward "\n")
                    103:        (delete-region (point-min) (point))
                    104: 
                    105:        (set-buffer-modified-p nil)
                    106:        (message "")))))
                    107: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.