Mercurial > emacs
annotate lisp/man.el @ 6428:633b2d7d12df
(syms_of_emacs): Don't initialize Vinstallation_name
and Vinstallation_directory.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 20 Mar 1994 01:13:53 +0000 |
parents | 284634d109ee |
children | b872dcd6cbbd |
rev | line source |
---|---|
3235 | 1 ;;; man.el --- browse UNIX manual pages |
2 | |
3 ;; Copyright (C) 1993 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com> | |
6 ;; Last-Modified: 31-Jul-1991 | |
7 ;; Version: 1.1 | |
8 ;; Keywords: help | |
9 ;; Adapted-By: ESR | |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
14 ;; it under the terms of the GNU General Public License as published by | |
15 ;; the Free Software Foundation; either version 2, or (at your option) | |
16 ;; any later version. | |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
24 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; This code provides a function, manual-entry, with which you can | |
30 ;; browse UNIX manual pages. Formatting is done in background so that | |
31 ;; you can continue to use your Emacs while processing is going on. | |
32 ;; | |
33 ;; The mode also supports hypertext-like following of manual page SEE | |
34 ;; ALSO references, and other features. See below or do `?' in a | |
35 ;; manual page buffer for details. | |
36 | |
37 ;; ========== Credits and History ========== | |
38 ;; In mid 1991, several people posted some interesting improvements to | |
39 ;; man.el from the standard emacs 18.57 distribution. I liked many of | |
40 ;; these, but wanted everthing in one single package, so I decided | |
41 ;; to encorporate them into a single manual browsing mode. While | |
42 ;; much of the code here has been rewritten, and some features added, | |
43 ;; these folks deserve lots of credit for providing the initial | |
44 ;; excellent packages on which this one is based. | |
45 | |
46 ;; Nick Duffek <duffek@chaos.cs.brandeis.edu>, posted a very nice | |
47 ;; improvement which retrieved and cleaned the manpages in a | |
48 ;; background process, and which correctly deciphered such options as | |
49 ;; man -k. | |
50 | |
51 ;; Eric Rose <erose@jessica.stanford.edu>, submitted manual.el which | |
52 ;; provided a very nice manual browsing mode. | |
53 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3307
diff
changeset
|
54 ;; This package was available as `superman.el' from the LCD package |
3235 | 55 ;; for some time before it was accepted into Emacs 19. The entry |
56 ;; point and some other names have been changed to make it a drop-in | |
57 ;; replacement for the old man.el package. | |
58 | |
59 ;; ========== Features ========== | |
60 ;; + Runs "man" in the background and pipes the results through a | |
61 ;; series of sed and awk scripts so that all retrieving and cleaning | |
62 ;; is done in the background. The cleaning commands are configurable. | |
63 ;; + Syntax is the same as Un*x man | |
64 ;; + Functionality is the same as Un*x man, including "man -k" and | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
65 ;; "man <section>", etc. |
3235 | 66 ;; + Provides a manual browsing mode with keybindings for traversing |
67 ;; the sections of a manpage, following references in the SEE ALSO | |
68 ;; section, and more. | |
69 ;; + Multiple manpages created with the same man command are put into | |
70 ;; a narrowed buffer circular list. | |
71 | |
72 ;;; Code: | |
73 | |
74 (require 'assoc) | |
75 | |
76 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
77 ;; user variables | |
78 | |
79 (defvar Man-notify 'friendly | |
80 "*Selects the behavior when manpage is ready. | |
81 This variable may have one of the following values: | |
82 | |
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
83 newframe -- put the manpage in its own frame (see `Man-frame-parameters') |
3235 | 84 bully -- make the manpage the current buffer and only window |
85 aggressive -- make the manpage the current buffer in the other window | |
86 friendly -- display manpage in other window but don't make current | |
87 polite -- don't display manpage, but prints message when ready (beeps) | |
88 quiet -- like `polite', but don't beep | |
89 meek -- make no indication that manpage is ready | |
90 | |
91 Any other value of `Man-notify' is equivalent to `meek'.") | |
92 | |
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
93 (defvar Man-frame-parameters nil |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
94 "*Frame parameter list for creating a new frame for a manual page.") |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
95 |
3235 | 96 (defvar Man-reuse-okay-p t |
97 "*Reuse a manpage buffer if possible. | |
98 When t, and a manpage buffer already exists with the same invocation, | |
99 man just indicates the manpage is ready according to the value of | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
100 `Man-notify'. When nil, it always fires off a background process, putting |
3235 | 101 the results in a uniquely named buffer.") |
102 | |
103 (defvar Man-downcase-section-letters-p t | |
104 "*Letters in sections are converted to lower case. | |
105 Some Un*x man commands can't handle uppercase letters in sections, for | |
106 example \"man 2V chmod\", but they are often displayed in the manpage | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
107 with the upper case letter. When this variable is t, the section |
3235 | 108 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before |
109 being sent to the man background process.") | |
110 | |
111 (defvar Man-circular-pages-p t | |
112 "*If t, the manpage list is treated as circular for traversal.") | |
113 | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
114 ;; I changed this to nil because it is a bad idea |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
115 ;; to fail to recognize things in other sections. |
3235 | 116 (defvar Man-auto-section-alist |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
117 nil |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
118 ;; '((c-mode . ("2" "3")) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
119 ;; (c++-mode . ("2" "3")) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
120 ;; (c++-c-mode . ("2" "3")) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
121 ;; (shell-mode . ("1" "8")) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
122 ;; (cmushell-mode . ("1" "8")) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
123 ;; (text-mode . "1") |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
124 ;; ) |
3235 | 125 "*Association list of major modes and their default section numbers. |
126 List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current | |
127 major mode is not in list, then the default is to check for manpages | |
128 in all sections.") | |
129 | |
130 (defvar Man-section-translations-alist | |
131 '(("3C++" . "3") | |
4378
088883bdcd70
(Man-section-translations-alist): Add entries for xlib.
Richard M. Stallman <rms@gnu.org>
parents:
4377
diff
changeset
|
132 ("3X" . "3") ; Xlib man pages |
088883bdcd70
(Man-section-translations-alist): Add entries for xlib.
Richard M. Stallman <rms@gnu.org>
parents:
4377
diff
changeset
|
133 ("3X11" . "3") |
3235 | 134 ("1-UCB" . "")) |
135 "*Association list of bogus sections to real section numbers. | |
136 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
137 their references which Un*x `man' does not recognize. This |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3307
diff
changeset
|
138 association list is used to translate those sections, when found, to |
3235 | 139 the associated section number.") |
140 | |
141 (defvar Man-filter-list | |
142 '(("sed " | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
143 (;;"-e 's/.\010//g'" |
3235 | 144 "-e '/[Nn]o such file or directory/d'" |
6292
a52a879c385c
(Man-filter-list): Don't insist on `...done' after `wait'.
Richard M. Stallman <rms@gnu.org>
parents:
5572
diff
changeset
|
145 "-e '/Reformatting page. Wait/d'" |
a52a879c385c
(Man-filter-list): Don't insist on `...done' after `wait'.
Richard M. Stallman <rms@gnu.org>
parents:
5572
diff
changeset
|
146 "-e '/Reformatting entry. Wait/d'" |
6358
250e69a75938
(Man-filter-list): Extend footer pattern for hpux.
Karl Heuer <kwzh@gnu.org>
parents:
6353
diff
changeset
|
147 "-e '/^ *\\([A-Za-z][A-Za-z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" |
3235 | 148 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" |
149 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" | |
150 "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'" | |
151 "-e '/^Printed [0-9].*[0-9]$/d'" | |
3659
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
152 "-e '/^[ \\t]*X Version 1[01].*Release [0-9]/d'" |
4968
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
153 "-e '/^[A-za-z].*Last change:/d'" |
3235 | 154 "-e '/^Sun Release [0-9].*[0-9]$/d'" |
155 "-e '/^\\n$/D'" | |
156 )) | |
4329
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
157 ("awk '\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
158 ("BEGIN { blankline=0; anonblank=0; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
159 "/^$/ { if (anonblank==0) next; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
160 "{ anonblank=1; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
161 "/^$/ { blankline++; next; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
162 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n" |
3235 | 163 "'" |
164 )) | |
165 ) | |
166 "*Manpage cleaning filter command phrases. | |
167 This variable contains an association list of the following form: | |
168 | |
169 '((command-string (phrase-string*))*) | |
170 | |
171 Each phrase-string is concatenated onto the command-string to form a | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
172 command filter. The (standard) output (and standard error) of the Un*x |
3235 | 173 man command is piped through each command filter in the order the |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
174 commands appear in the association list. The final output is placed in |
3235 | 175 the manpage buffer.") |
176 | |
177 (defvar Man-mode-line-format | |
178 '("" mode-line-modified | |
179 mode-line-buffer-identification " " | |
180 global-mode-string | |
4009
4edc10a61fa7
(Man-mode-line-format): Add a space after global-mode-string.
Richard M. Stallman <rms@gnu.org>
parents:
4002
diff
changeset
|
181 " " Man-page-mode-string |
3235 | 182 " %[(" mode-name minor-mode-alist mode-line-process ")%]----" |
183 (-3 . "%p") "-%-") | |
184 "*Mode line format for manual mode buffer.") | |
185 | |
186 (defvar Man-mode-map nil | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
187 "*Keymap for Man mode.") |
3235 | 188 |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
189 (defvar Man-mode-hook nil |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
190 "*Normal hook run when Man mode is enabled.") |
3235 | 191 |
6358
250e69a75938
(Man-filter-list): Extend footer pattern for hpux.
Karl Heuer <kwzh@gnu.org>
parents:
6353
diff
changeset
|
192 (defvar Man-cooked-hook nil |
6362 | 193 "*Normal hook run after removing backspaces but before Man-mode processing.") |
6358
250e69a75938
(Man-filter-list): Extend footer pattern for hpux.
Karl Heuer <kwzh@gnu.org>
parents:
6353
diff
changeset
|
194 |
4980
50708e8b133b
(Man-section-regexp): Allow section names l, n, L, N.
Richard M. Stallman <rms@gnu.org>
parents:
4968
diff
changeset
|
195 (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]" |
3235 | 196 "*Regular expression describing a manpage section within parentheses.") |
197 | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
198 (defvar Man-heading-regexp "^ ?[A-Z]" |
3235 | 199 "*Regular expression describing a manpage heading entry.") |
200 | |
201 (defvar Man-see-also-regexp "SEE ALSO" | |
202 "*Regular expression for SEE ALSO heading (or your equivalent). | |
203 This regexp should not start with a `^' character.") | |
204 | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
205 (defvar Man-first-heading-regexp "^ ?NAME$\\|^ ?No manual entry for .*$" |
3235 | 206 "*Regular expression describing first heading on a manpage. |
207 This regular expression should start with a `^' character.") | |
208 | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
209 (defvar Man-reference-regexp |
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
210 "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*\\(([0-9][a-zA-Z+]*)\\)?" |
3235 | 211 "*Regular expression describing a reference in the SEE ALSO section.") |
212 | |
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
213 (defvar Man-switches "" |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
214 "*Switches passed to the man command, as a single string.") |
3235 | 215 |
5108
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
216 ;; Would someone like to provide a good test for being on Solaris? |
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
217 ;; We could give it its own value of system-type, but that has drawbacks; |
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
218 ;; it would require changes in lots of places that test system-type. |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
219 (defvar Man-specified-section-option |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
220 (if (string-match "-solaris[0-9.]*$" system-configuration) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
221 "-s" |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
222 "") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
223 "*Option that indicates a specified a manual section name.") |
5108
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
224 |
3235 | 225 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
226 ;; end user variables | |
227 | |
228 ;; other variables and keymap initializations | |
229 (make-variable-buffer-local 'Man-sections-alist) | |
230 (make-variable-buffer-local 'Man-refpages-alist) | |
231 (make-variable-buffer-local 'Man-page-list) | |
232 (make-variable-buffer-local 'Man-current-page) | |
233 (make-variable-buffer-local 'Man-page-mode-string) | |
6363
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
234 (make-variable-buffer-local 'Man-original-frame) |
3235 | 235 |
236 (setq-default Man-sections-alist nil) | |
237 (setq-default Man-refpages-alist nil) | |
238 (setq-default Man-page-list nil) | |
239 (setq-default Man-current-page 0) | |
240 (setq-default Man-page-mode-string "1 (of 1)") | |
241 | |
242 (if Man-mode-map | |
243 nil | |
244 (setq Man-mode-map (make-keymap)) | |
245 (suppress-keymap Man-mode-map) | |
246 (define-key Man-mode-map " " 'scroll-up) | |
247 (define-key Man-mode-map "\177" 'scroll-down) | |
248 (define-key Man-mode-map "n" 'Man-next-section) | |
249 (define-key Man-mode-map "p" 'Man-previous-section) | |
250 (define-key Man-mode-map "\en" 'Man-next-manpage) | |
251 (define-key Man-mode-map "\ep" 'Man-previous-manpage) | |
252 (define-key Man-mode-map "," 'beginning-of-buffer) | |
253 (define-key Man-mode-map "." 'end-of-buffer) | |
254 (define-key Man-mode-map "r" 'Man-follow-manual-reference) | |
255 (define-key Man-mode-map "t" 'toggle-truncate-lines) | |
256 (define-key Man-mode-map "g" 'Man-goto-section) | |
257 (define-key Man-mode-map "s" 'Man-goto-see-also-section) | |
258 (define-key Man-mode-map "q" 'Man-quit) | |
259 (define-key Man-mode-map "m" 'manual-entry) | |
260 (define-key Man-mode-map "?" 'describe-mode) | |
261 ) | |
262 | |
263 | |
264 ;; ====================================================================== | |
265 ;; utilities | |
266 | |
267 (defun Man-page-mode-string () | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
268 "Formats part of the mode line for Man mode." |
3235 | 269 (format "%d (of %d)" Man-current-page (length Man-page-list))) |
270 | |
271 (defun Man-delete-trailing-newline (str) | |
272 (if (string= (substring str (1- (length str))) "\n") | |
273 (substring str 0 (1- (length str))) | |
274 str)) | |
275 | |
276 (defun Man-build-man-command () | |
277 "Builds the entire background manpage and cleaning command." | |
6353
f00fc681daa4
(Man-build-man-command): Redirect desc 2 to /dev/null.
Richard M. Stallman <rms@gnu.org>
parents:
6292
diff
changeset
|
278 (let ((command (concat "man " Man-switches " %s 2>/dev/null")) |
3235 | 279 (flist Man-filter-list)) |
280 (while flist | |
281 (let ((pcom (car (car flist))) | |
282 (pargs (car (cdr (car flist))))) | |
283 (setq flist (cdr flist)) | |
284 (if (or (not (stringp pcom)) | |
285 (not (listp pargs))) | |
286 (error "malformed Man-filter-list.")) | |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
287 (setq command (concat command " | " pcom |
3235 | 288 (mapconcat '(lambda (phrase) phrase) |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
289 pargs " "))))) |
3235 | 290 command)) |
291 | |
292 (defun Man-downcase (man-args) | |
293 "Downcases section letters in MAN-ARGS." | |
294 (let ((newargs "") | |
295 (s 0) | |
296 mstart mend | |
297 (len (length man-args))) | |
298 (while (and (< s len) | |
299 (setq mstart (string-match Man-section-regexp man-args s))) | |
300 (setq mend (match-end 0) | |
301 newargs (concat newargs (substring man-args s mstart))) | |
302 (setq newargs (concat newargs (downcase | |
303 (substring man-args mstart mend))) | |
304 s mend)) | |
305 (concat newargs (substring man-args s len)))) | |
306 | |
307 (defun Man-translate-references (ref) | |
308 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style." | |
309 (if (string-match (concat "(" Man-section-regexp ")$") ref) | |
310 (let* ((word (progn (string-match "(" ref) | |
311 (substring ref 0 (1- (match-end 0))))) | |
312 (section-re (concat "(\\(" Man-section-regexp "\\))")) | |
313 (section (if (string-match section-re ref) | |
314 (substring ref (match-beginning 1) (match-end 1)) | |
315 "")) | |
316 (slist Man-section-translations-alist) | |
317 ) | |
318 (if Man-downcase-section-letters-p | |
319 (setq section (Man-downcase section))) | |
320 (while slist | |
321 (let ((s1 (car (car slist))) | |
322 (s2 (cdr (car slist)))) | |
323 (setq slist (cdr slist)) | |
324 (if Man-downcase-section-letters-p | |
325 (setq s1 (Man-downcase s1))) | |
326 (if (not (string= s1 section)) nil | |
327 (setq section (if Man-downcase-section-letters-p | |
328 (Man-downcase s2) | |
329 s2) | |
330 slist nil)))) | |
5108
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
331 (concat Man-specified-section-option section " " word)) |
3235 | 332 ref)) |
333 | |
334 (defun Man-linepos (&optional position col-p) | |
335 "Return the character position at various line/buffer positions. | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
336 Preserves the state of point, mark, etc. Optional arg POSITION can be one |
3235 | 337 of the following symbols: |
338 bol == beginning of line | |
339 boi == beginning of indentation | |
340 eol == end of line [default] | |
341 bob == beginning of buffer | |
342 eob == end of buffer | |
343 | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
344 Optional arg COL-P, if non-nil, means to return |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
345 the current column instead of character position." |
3235 | 346 (let ((tpnt (point)) |
347 rval) | |
348 (cond | |
349 ((eq position 'bol) (beginning-of-line)) | |
350 ((eq position 'boi) (back-to-indentation)) | |
351 ((eq position 'bob) (goto-char (point-min))) | |
352 ((eq position 'eob) (goto-char (point-max))) | |
353 (t (end-of-line))) | |
354 (setq rval (if col-p (current-column) (point))) | |
355 (goto-char tpnt) | |
356 rval)) | |
357 | |
358 | |
359 ;; ====================================================================== | |
360 ;; default man entry and get word under point | |
361 | |
362 (defun Man-default-man-args (manword) | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
363 "Build the default man args from MANWORD and buffer's major mode." |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
364 (let ((sections (cdr (assq major-mode Man-auto-section-alist)))) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
365 (cond |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
366 ((null sections) manword) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
367 ((consp sections) |
5572
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
368 (mapconcat (lambda (n) (concat Man-specified-section-option |
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
369 n " " manword)) |
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
370 sections " ")) |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
371 (t |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
372 (concat sections " " manword))))) |
3235 | 373 |
374 (defun Man-default-man-entry () | |
375 "Make a guess at a default manual entry. | |
376 This guess is based on the text surrounding the cursor, and the | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
377 default section number is selected from `Man-auto-section-alist'." |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
378 (let (default-title) |
3235 | 379 (save-excursion |
380 | |
381 ;; Default man entry title is any word the cursor is on, | |
382 ;; or if cursor not on a word, then nearest preceding | |
383 ;; word. | |
384 (and (not (looking-at "[a-zA-Z_]")) | |
385 (skip-chars-backward "^a-zA-Z_")) | |
386 (skip-chars-backward "(a-zA-Z_0-9") | |
387 (and (looking-at "(") (forward-char 1)) | |
388 (setq default-title | |
389 (buffer-substring | |
390 (point) | |
391 (progn (skip-chars-forward "a-zA-Z0-9_") (point)))) | |
392 | |
393 ;; If looking at something like ioctl(2) or brc(1M), include | |
394 ;; section number in default-entry | |
395 (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)") | |
396 (progn (skip-chars-forward "^0-9") | |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
397 (setq default-title |
5572
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
398 (concat Man-specified-section-option |
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
399 (buffer-substring |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
400 (point) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
401 (progn |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
402 (skip-chars-forward "0-9a-zA-Z") |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
403 (point))) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
404 " " |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
405 default-title))) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
406 (setq default-title (Man-default-man-args default-title))) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
407 default-title))) |
3235 | 408 |
409 | |
410 ;; ====================================================================== | |
411 ;; top level command and background process sentinel | |
412 | |
4444 | 413 ;;; This alias makes completion more predictable if ignoring case. |
414 ;;;###autoload | |
415 (defalias 'man 'manual-entry) | |
416 | |
3235 | 417 ;;;###autoload |
418 (defun manual-entry (arg) | |
419 "Get a Un*x manual page and put it in a buffer. | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
420 This command is the top-level command in the man package. It runs a Un*x |
3235 | 421 command to retrieve and clean a manpage in the background and places the |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
422 results in a Man mode (manpage browsing) buffer. See variable |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
423 `Man-notify' for what happens when the buffer is ready. |
6373
284634d109ee
(manual-entry): Document what the arg does.
Karl Heuer <kwzh@gnu.org>
parents:
6363
diff
changeset
|
424 Normally, if a buffer already exists for this man page, it will display |
284634d109ee
(manual-entry): Document what the arg does.
Karl Heuer <kwzh@gnu.org>
parents:
6363
diff
changeset
|
425 immediately; either a prefix argument or a nil value to `Man-reuse-okay-p' |
284634d109ee
(manual-entry): Document what the arg does.
Karl Heuer <kwzh@gnu.org>
parents:
6363
diff
changeset
|
426 overrides this and forces the man page to be regenerated." |
3235 | 427 (interactive "P") |
428 (let* ((default-entry (Man-default-man-entry)) | |
429 (man-args | |
430 (read-string (format "Manual-entry: %s" | |
431 (if (string= default-entry "") "" | |
432 (format "(default: %s) " | |
433 default-entry)))))) | |
434 (and (string= man-args "") | |
435 (if (string= default-entry "") | |
436 (error "No man args given.") | |
437 (setq man-args default-entry))) | |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
438 |
3644
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
439 ;; Recognize the subject(section) syntax. |
4002
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
440 (setq man-args (Man-translate-references man-args)) |
511feb3c2874
* man.el (Man-build-man-command): Don't leave a pipe symbol at the
Jim Blandy <jimb@redhat.com>
parents:
3909
diff
changeset
|
441 |
4968
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
442 ;; This is apparently already done correctly via Man-translate-references. |
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
443 ;; (if Man-downcase-section-letters-p |
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
444 ;; (setq man-args (Man-downcase man-args))) |
3235 | 445 (Man-getpage-in-background man-args (consp arg)) |
446 )) | |
447 | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
448 (defun Man-getpage-in-background (topic &optional override-reuse-p) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
449 "Uses TOPIC to build and fire off the manpage and cleaning command. |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
450 Optional OVERRIDE-REUSE-P, when non-nil, means to |
3235 | 451 start a background process even if a buffer already exists and |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
452 `Man-reuse-okay-p' is non-nil." |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
453 (let* ((man-args topic) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
454 (bufname (concat "*man " man-args "*")) |
3235 | 455 (buffer (get-buffer bufname))) |
456 (if (and Man-reuse-okay-p | |
457 (not override-reuse-p) | |
458 buffer) | |
459 (Man-notify-when-ready buffer) | |
6353
f00fc681daa4
(Man-build-man-command): Redirect desc 2 to /dev/null.
Richard M. Stallman <rms@gnu.org>
parents:
6292
diff
changeset
|
460 (require 'env) |
3235 | 461 (message "Invoking man %s in background..." man-args) |
462 (setq buffer (generate-new-buffer bufname)) | |
6363
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
463 (save-excursion |
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
464 (set-buffer buffer) |
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
465 (setq Man-original-frame (selected-frame))) |
4175
3e4fa4423f5a
(Man-getpage-in-background): Copy process-environment
Richard M. Stallman <rms@gnu.org>
parents:
4009
diff
changeset
|
466 (let ((process-environment (copy-sequence process-environment))) |
3713
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
467 ;; Prevent any attempt to use display terminal fanciness. |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
468 (setenv "TERM" "dumb") |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
469 (set-process-sentinel |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
470 (start-process "man" buffer "sh" "-c" |
3714
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
471 (format (Man-build-man-command) man-args)) |
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
472 'Man-bgproc-sentinel)) |
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
473 ))) |
3235 | 474 |
475 (defun Man-notify-when-ready (man-buffer) | |
476 "Notify the user when MAN-BUFFER is ready. | |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
477 See the variable `Man-notify' for the different notification behaviors." |
3235 | 478 (cond |
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
479 ((eq Man-notify 'newframe) |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
480 (set-buffer man-buffer) |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
481 (new-frame Man-frame-parameters)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
482 ((eq Man-notify 'bully) |
6363
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
483 (and (frame-live-p Man-original-frame) |
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
484 (select-frame Man-original-frame)) |
3235 | 485 (pop-to-buffer man-buffer) |
486 (delete-other-windows)) | |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
487 ((eq Man-notify 'aggressive) |
6363
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
488 (and (frame-live-p Man-original-frame) |
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
489 (select-frame Man-original-frame)) |
3235 | 490 (pop-to-buffer man-buffer)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
491 ((eq Man-notify 'friendly) |
6363
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
492 (and (frame-live-p Man-original-frame) |
e5d9ea7852bf
(Man-original-frame): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
6362
diff
changeset
|
493 (select-frame Man-original-frame)) |
3235 | 494 (display-buffer man-buffer 'not-this-window)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
495 ((eq Man-notify 'polite) |
3235 | 496 (beep) |
497 (message "Manual buffer %s is ready." (buffer-name man-buffer))) | |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
498 ((eq Man-notify 'quiet) |
3235 | 499 (message "Manual buffer %s is ready." (buffer-name man-buffer))) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
500 ((or (eq Man-notify 'meek) |
3235 | 501 t) |
502 (message "")) | |
503 )) | |
504 | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
505 (defun Man-set-fonts () |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
506 (goto-char (point-min)) |
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
507 (while (re-search-forward "\\(.\b\\)+" nil t) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
508 (let ((st (match-beginning 0)) (en (match-end 0))) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
509 (goto-char st) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
510 (if window-system |
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
511 (put-text-property st (if (= en (point-max)) en (1+ en)) 'face |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
512 (if (looking-at "_") 'underline 'bold))) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
513 (while (and (< (point) en) (looking-at ".\b")) |
4203
b42338a458a5
(Man-set-fonts): Don't look for another char after
Richard M. Stallman <rms@gnu.org>
parents:
4175
diff
changeset
|
514 (replace-match ""))))) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
515 |
3235 | 516 (defun Man-bgproc-sentinel (process msg) |
517 "Manpage background process sentinel." | |
518 (let ((Man-buffer (process-buffer process)) | |
519 (delete-buff nil) | |
520 (err-mess nil)) | |
521 (if (null (buffer-name Man-buffer)) ;; deleted buffer | |
522 (set-process-buffer process nil) | |
523 (save-excursion | |
524 (set-buffer Man-buffer) | |
525 (goto-char (point-min)) | |
526 (cond ((or (looking-at "No \\(manual \\)*entry for") | |
527 (looking-at "[^\n]*: nothing appropriate$")) | |
528 (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) | |
529 delete-buff t) | |
530 ) | |
531 ((not (and (eq (process-status process) 'exit) | |
532 (= (process-exit-status process) 0))) | |
533 (setq err-mess | |
534 (concat (buffer-name Man-buffer) | |
535 ": process " | |
536 (let ((eos (1- (length msg)))) | |
537 (if (= (aref msg eos) ?\n) | |
538 (substring msg 0 eos) msg)))) | |
539 (goto-char (point-max)) | |
540 (insert (format "\nprocess %s" msg)) | |
541 ))) | |
542 (if delete-buff | |
543 (kill-buffer Man-buffer) | |
544 (save-window-excursion | |
545 (save-excursion | |
546 (set-buffer Man-buffer) | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
547 (Man-set-fonts) |
6358
250e69a75938
(Man-filter-list): Extend footer pattern for hpux.
Karl Heuer <kwzh@gnu.org>
parents:
6353
diff
changeset
|
548 (run-hooks 'Man-cooked-hook) |
3235 | 549 (Man-mode) |
550 (set-buffer-modified-p nil))) | |
551 (Man-notify-when-ready Man-buffer)) | |
552 | |
553 (if err-mess | |
554 (error err-mess)) | |
555 ))) | |
556 | |
557 | |
558 ;; ====================================================================== | |
559 ;; set up manual mode in buffer and build alists | |
560 | |
561 (defun Man-mode () | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
562 "A mode for browsing Un*x manual pages. |
3235 | 563 |
564 The following man commands are available in the buffer. Try | |
565 \"\\[describe-key] <key> RET\" for more information: | |
566 | |
567 \\[manual-entry] Prompt to retrieve a new manpage. | |
568 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section. | |
569 \\[Man-next-manpage] Jump to next manpage in circular list. | |
570 \\[Man-previous-manpage] Jump to previous manpage in circular list. | |
571 \\[Man-next-section] Jump to next manpage section. | |
572 \\[Man-previous-section] Jump to previous manpage section. | |
573 \\[Man-goto-section] Go to a manpage section. | |
574 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. | |
575 \\[Man-quit] Deletes the manpage, its buffer, and window. | |
576 \\[describe-mode] Prints this help text. | |
577 | |
578 The following variables may be of some use. Try | |
579 \"\\[describe-variable] <variable-name> RET\" for more information: | |
580 | |
581 Man-notify What happens when manpage formatting is done. | |
582 Man-reuse-okay-p Okay to reuse already formatted buffer? | |
583 Man-downcase-section-letters-p Force section letters to lower case? | |
584 Man-circular-pages-p Multiple manpage list treated as circular? | |
585 Man-auto-section-alist List of major modes and their section numbers. | |
586 Man-section-translations-alist List of section numbers and their Un*x equiv. | |
587 Man-filter-list Background manpage filter command. | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
588 Man-mode-line-format Mode line format for Man mode buffers. |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
589 Man-mode-map Keymap bindings for Man mode buffers. |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
590 Man-mode-hook Normal hook run on entry to Man mode. |
3235 | 591 Man-section-regexp Regexp describing manpage section letters. |
592 Man-heading-regexp Regexp describing section headers. | |
593 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). | |
594 Man-first-heading-regexp Regexp for first heading on a manpage. | |
595 Man-reference-regexp Regexp matching a references in SEE ALSO. | |
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
596 Man-switches Background `man' command switches. |
3235 | 597 |
598 The following key bindings are currently in effect in the buffer: | |
599 \\{Man-mode-map}" | |
600 (interactive) | |
601 (setq major-mode 'Man-mode | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
602 mode-name "Man" |
3235 | 603 buffer-auto-save-file-name nil |
604 mode-line-format Man-mode-line-format | |
605 truncate-lines t | |
606 buffer-read-only t) | |
607 (buffer-disable-undo (current-buffer)) | |
608 (auto-fill-mode -1) | |
609 (use-local-map Man-mode-map) | |
610 (goto-char (point-min)) | |
611 (Man-build-page-list) | |
3619
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
612 (Man-goto-page 1) |
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
613 (run-hooks 'Man-mode-hook)) |
3235 | 614 |
615 (defun Man-build-section-alist () | |
616 "Build the association list of manpage sections." | |
617 (setq Man-sections-alist nil) | |
618 (goto-char (point-min)) | |
619 (while (re-search-forward Man-heading-regexp (point-max) t) | |
620 (aput 'Man-sections-alist | |
621 (buffer-substring (Man-linepos 'bol) (Man-linepos))) | |
622 (forward-line 1) | |
623 )) | |
624 | |
625 (defun Man-build-references-alist () | |
626 "Build the association list of references (in the SEE ALSO section)." | |
627 (setq Man-refpages-alist nil) | |
628 (save-excursion | |
629 (if (Man-find-section Man-see-also-regexp) | |
630 (let ((start (progn (forward-line 1) (point))) | |
631 (end (progn | |
632 (Man-next-section 1) | |
633 (point))) | |
634 hyphenated | |
635 (runningpoint -1)) | |
636 (narrow-to-region start end) | |
637 (goto-char (point-min)) | |
638 (back-to-indentation) | |
639 (while (and (not (eobp)) (/= (point) runningpoint)) | |
640 (setq runningpoint (point)) | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
641 (let* ((eow (re-search-forward Man-reference-regexp end t)) |
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
642 (word (buffer-substring (match-beginning 0) (match-end 0))) |
3235 | 643 (len (1- (length word)))) |
644 (if (not eow) nil | |
645 (if hyphenated | |
646 (setq word (concat hyphenated word) | |
647 hyphenated nil)) | |
648 (if (= (aref word len) ?-) | |
649 (setq hyphenated (substring word 0 len)) | |
650 (aput 'Man-refpages-alist word)))) | |
651 (skip-chars-forward " \t\n,")) | |
652 )))) | |
653 | |
654 (defun Man-build-page-list () | |
655 "Build the list of separate manpages in the buffer." | |
656 (setq Man-page-list nil) | |
657 (save-excursion | |
658 (let ((page-start (Man-linepos 'bob)) | |
659 (page-end (Man-linepos 'eob)) | |
660 (regexp Man-first-heading-regexp)) | |
661 (goto-char (point-min)) | |
662 (re-search-forward regexp (point-max) t) | |
663 (while (not (eobp)) | |
664 (if (re-search-forward regexp (point-max) t) | |
665 (progn | |
666 (setq page-end (Man-linepos 'bol)) | |
667 (end-of-line)) | |
668 (goto-char (point-max)) | |
669 (setq page-end (point))) | |
670 (setq Man-page-list (append Man-page-list | |
671 (list (cons page-start page-end))) | |
672 page-start page-end) | |
673 )))) | |
674 | |
675 | |
676 ;; ====================================================================== | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
677 ;; Man mode commands |
3235 | 678 |
679 (defun Man-next-section (n) | |
680 "Move point to Nth next section (default 1)." | |
681 (interactive "p") | |
682 (if (looking-at Man-heading-regexp) | |
683 (forward-line 1)) | |
684 (if (re-search-forward Man-heading-regexp (point-max) t n) | |
685 (beginning-of-line) | |
686 (goto-char (point-max)))) | |
687 | |
688 (defun Man-previous-section (n) | |
689 "Move point to Nth previous section (default 1)." | |
690 (interactive "p") | |
691 (if (looking-at Man-heading-regexp) | |
692 (forward-line -1)) | |
693 (if (re-search-backward Man-heading-regexp (point-min) t n) | |
694 (beginning-of-line) | |
695 (goto-char (point-min)))) | |
696 | |
697 (defun Man-find-section (section) | |
698 "Move point to SECTION if it exists, otherwise don't move point. | |
699 Returns t if section is found, nil otherwise." | |
700 (let ((curpos (point))) | |
701 (goto-char (point-min)) | |
4334
b39cd3621215
* man.el (Man-find-section): HP/UX man pages have section names
Jim Blandy <jimb@redhat.com>
parents:
4329
diff
changeset
|
702 (if (re-search-forward (concat "^\\s-?" section) (point-max) t) |
3235 | 703 (progn (beginning-of-line) t) |
704 (goto-char curpos) | |
705 nil) | |
706 )) | |
707 | |
708 (defun Man-goto-section () | |
709 "Query for section to move point to." | |
710 (interactive) | |
711 (aput 'Man-sections-alist | |
712 (let* ((default (aheadsym Man-sections-alist)) | |
713 (completion-ignore-case t) | |
714 chosen | |
715 (prompt (concat "Go to section: (default " default ") "))) | |
716 (setq chosen (completing-read prompt Man-sections-alist)) | |
717 (if (or (not chosen) | |
718 (string= chosen "")) | |
719 default | |
720 chosen))) | |
721 (Man-find-section (aheadsym Man-sections-alist))) | |
722 | |
723 (defun Man-goto-see-also-section () | |
724 "Move point the the \"SEE ALSO\" section. | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
725 Actually the section moved to is described by `Man-see-also-regexp'." |
3235 | 726 (interactive) |
727 (if (not (Man-find-section Man-see-also-regexp)) | |
728 (error (concat "No " Man-see-also-regexp | |
729 " section found in current manpage.")))) | |
730 | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
731 (defun Man-follow-manual-reference (arg reference) |
3235 | 732 "Get one of the manpages referred to in the \"SEE ALSO\" section. |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
733 Specify which reference to use; default is based on word at point. |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
734 Prefix argument ARG is passed to `Man-getpage-in-background'." |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
735 (interactive |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
736 (if (not Man-refpages-alist) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
737 (error "No references in current man page") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
738 (list current-prefix-arg |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
739 (let* ((default (or |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
740 (car (all-completions |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
741 (save-excursion |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
742 (skip-syntax-backward "w()") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
743 (skip-chars-forward " \t") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
744 (let ((word (current-word))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
745 ;; strip a trailing '-': |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
746 (if (string-match "-$" word) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
747 (substring word 0 (match-beginning 0)) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
748 word))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
749 Man-refpages-alist)) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
750 (aheadsym Man-refpages-alist))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
751 chosen |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
752 (prompt (concat "Refer to: (default " default ") "))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
753 (setq chosen (completing-read prompt Man-refpages-alist nil t)) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
754 (if (or (not chosen) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
755 (string= chosen "")) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
756 default |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
757 chosen))))) |
3235 | 758 (if (not Man-refpages-alist) |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
759 (error "No references found in current manpage") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
760 (aput 'Man-refpages-alist reference) |
3235 | 761 (Man-getpage-in-background |
762 (Man-translate-references (aheadsym Man-refpages-alist)) | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
763 arg))) |
3235 | 764 |
765 (defun Man-quit () | |
766 "Kill the buffer containing the manpage." | |
767 (interactive) | |
768 (let ((buff (current-buffer))) | |
769 (delete-windows-on buff) | |
770 (kill-buffer buff))) | |
771 | |
772 (defun Man-goto-page (page) | |
773 "Go to the manual page on page PAGE." | |
774 (interactive | |
775 (if (not Man-page-list) | |
776 (error "You're looking at the only manpage in the buffer.") | |
777 (format "nGo to manpage [1-%d]: " (length Man-page-list)))) | |
778 (if (or (< page 1) | |
779 (> page (length Man-page-list))) | |
780 (error "No manpage %d found" page)) | |
781 (let* ((page-range (nth (1- page) Man-page-list)) | |
782 (page-start (car page-range)) | |
783 (page-end (cdr page-range))) | |
784 (setq Man-current-page page | |
785 Man-page-mode-string (Man-page-mode-string)) | |
786 (widen) | |
787 (goto-char page-start) | |
788 (narrow-to-region page-start page-end) | |
789 (Man-build-section-alist) | |
3659
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
790 ;; Don't let bugs in Man-build-references-alist |
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
791 ;; interfere with ordinary use of this package. |
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
792 (condition-case nil |
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
793 (Man-build-references-alist) |
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
794 (error)) |
3235 | 795 (widen) |
796 (narrow-to-region page-start page-end) | |
797 (goto-char (point-min)))) | |
798 | |
799 | |
800 (defun Man-next-manpage () | |
801 "Find the next manpage entry in the buffer." | |
802 (interactive) | |
803 (if (= (length Man-page-list) 1) | |
804 (error "This is the only manpage in the buffer.")) | |
805 (if (< Man-current-page (length Man-page-list)) | |
806 (Man-goto-page (1+ Man-current-page)) | |
807 (if Man-circular-pages-p | |
808 (Man-goto-page 1) | |
809 (error "You're looking at the last manpage in the buffer.")))) | |
810 | |
811 (defun Man-previous-manpage () | |
812 "Find the previous manpage entry in the buffer." | |
813 (interactive) | |
814 (if (= (length Man-page-list) 1) | |
815 (error "This is the only manpage in the buffer.")) | |
816 (if (> Man-current-page 1) | |
817 (Man-goto-page (1- Man-current-page)) | |
818 (if Man-circular-pages-p | |
819 (Man-goto-page (length Man-page-list)) | |
820 (error "You're looking at the first manpage in the buffer.")))) | |
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
821 |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
822 (provide 'man) |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
823 |
3235 | 824 ;;; man.el ends here |