annotate lisp/=man.el @ 177:7de1e620fb6b

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Wed, 30 Jan 1991 10:30:18 +0000
parents 5f14cf951acb
children 5ed62d0099e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 ;; Read in and display parts of Unix manual.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
3
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
4 ;; This file is part of GNU Emacs.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
5
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
7 ;; it under the terms of the GNU General Public License as published by
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 ;; the Free Software Foundation; either version 1, or (at your option)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
9 ;; any later version.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
10
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is distributed in the hope that it will be useful,
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 ;; GNU General Public License for more details.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
20 (defun manual-entry (topic &optional section)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
21 "Display the Unix manual entry for TOPIC.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
22 TOPIC is either the title of the entry, or has the form TITLE(SECTION)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23 where SECTION is the desired section of the manual, as in `tty(4)'."
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
24 (interactive "sManual entry (topic): ")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
25 (if (= (length topic) 0)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
26 (error "Must specify topic"))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27 (if (and (null section)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 (string-match "\\`[ \t]*\\([^( \t]+\\)[ \t]*(\\(.+\\))[ \t]*\\'" topic))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29 (setq section (substring topic (match-beginning 2)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30 (match-end 2))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 topic (substring topic (match-beginning 1)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 (match-end 1))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
33 (with-output-to-temp-buffer (concat "*" topic " Manual Entry*")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 (buffer-disable-undo standard-output)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
35 (save-excursion
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
36 (set-buffer standard-output)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
37 (message "Looking for formatted entry for %s%s..."
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
38 topic (if section (concat "(" section ")") ""))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39 (let ((dirlist manual-formatted-dirlist)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 (case-fold-search nil)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 name)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
42 (if (and section (or (file-exists-p
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43 (setq name (concat manual-formatted-dir-prefix
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
44 (substring section 0 1)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
45 "/"
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
46 topic "." section)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
47 (file-exists-p
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
48 (setq name (concat manual-formatted-dir-prefix
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
49 section
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
50 "/"
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
51 topic "." section)))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
52 (insert-man-file name)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
53 (while dirlist
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
54 (let* ((dir (car dirlist))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
55 (name1 (concat dir "/" topic "."
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
56 (or section
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
57 (substring
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
58 dir
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
59 (1+ (or (string-match "\\.[^./]*$" dir)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
60 -2))))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
61 completions)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
62 (if (file-exists-p name1)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
63 (insert-man-file name1)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
64 (condition-case ()
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
65 (progn
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
66 (setq completions (file-name-all-completions
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
67 (concat topic "." (or section ""))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
68 dir))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
69 (while completions
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
70 (insert-man-file (concat dir "/" (car completions)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
71 (setq completions (cdr completions))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
72 (file-error nil)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
73 (goto-char (point-max)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
74 (setq dirlist (cdr dirlist)))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
75
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
76 (if (= (buffer-size) 0)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
77 (progn
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
78 (message "No formatted entry, invoking man %s%s..."
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
79 (if section (concat section " ") "") topic)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
80 (if section
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
81 (call-process manual-program nil t nil section topic)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
82 (call-process manual-program nil t nil topic))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
83 (if (< (buffer-size) 80)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
84 (progn
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
85 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
86 (end-of-line)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
87 (error (buffer-substring 1 (point)))))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
88
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
89 (message "Cleaning manual entry for %s..." topic)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
90 (nuke-nroff-bs)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
91 (set-buffer-modified-p nil)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
92 (setq buffer-read-only t)
74
2c14d4cb1256 *** empty log message ***
root <root>
parents: 58
diff changeset
93 (view-mode nil 'bury-buffer)
58
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
94 (message ""))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
95
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
96 ;; Hint: BS stands form more things than "back space"
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
97 (defun nuke-nroff-bs ()
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
98 (interactive "*")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
99 ;; Nuke headers: "MORE(1) UNIX Programmer's Manual MORE(1)"
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
100 ;; We expext to find a footer just before the header except at the beginning.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
101 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
102 (while (re-search-forward "^ *\\([A-Za-z][-_.A-Za-z0-9]*([0-9A-Z]+)\\).*\\1$" nil t)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
103 (let (start end)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
104 ;; Put START and END around footer and header and garbage blank lines.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
105 ;; Fixed line counts are risky, but allow us to preserve
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
106 ;; significant blank lines.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
107 (setq start (save-excursion (forward-line -10) (point)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
108 (setq end (save-excursion (forward-line 4) (point)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
109 (delete-region start end)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
110 ;; Catch the final footer.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
111 (goto-char (point-max))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
112 (delete-region (point) (save-excursion (forward-line -7) (point)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
113
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
114 ;; Nuke underlining and overstriking (only by the same letter)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
115 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
116 (while (search-forward "\b" nil t)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
117 (let* ((preceding (char-after (- (point) 2)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
118 (following (following-char)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
119 (cond ((= preceding following)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
120 ;; x\bx
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
121 (delete-char -2))
103
5f14cf951acb *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 74
diff changeset
122 ((and (= preceding ?o) (= following ?\+))
5f14cf951acb *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 74
diff changeset
123 ;; o\b+
5f14cf951acb *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 74
diff changeset
124 (delete-char -2))
58
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
125 ((= preceding ?\_)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
126 ;; _\b
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
127 (delete-char -2))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
128 ((= following ?\_)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
129 ;; \b_
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
130 (delete-region (1- (point)) (1+ (point)))))))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
131
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
132 ;; Zap ESC7, ESC8, and ESC9.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
133 ;; This is for Sun man pages like "man 1 csh"
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
134 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
135 (while (re-search-forward "\e[789]" nil t)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
136 (replace-match ""))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
137
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
138 ;; Crunch blank lines
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
139 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
140 (while (re-search-forward "\n\n\n\n*" nil t)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
141 (replace-match "\n\n"))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
142
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
143 ;; Nuke blanks lines at start.
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
144 (goto-char (point-min))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
145 (skip-chars-forward "\n")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
146 (delete-region (point-min) (point)))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
147
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
148
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
149 (defun insert-man-file (name)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
150 ;; Insert manual file (unpacked as necessary) into buffer
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
151 (if (or (equal (substring name -2) ".Z")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
152 (string-match "/cat[0-9][a-z]?\\.Z/" name))
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
153 (call-process "zcat" name t nil)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
154 (if (equal (substring name -2) ".z")
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
155 (call-process "pcat" nil t nil name)
035f2a0c8d64 Initial revision
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
156 (insert-file-contents name))))