Mercurial > emacs
annotate lisp/man.el @ 5955:459bb5807c0b
(face-try-color-list): Don't rely on errors from using
a color that the server can't really support.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 15 Feb 1994 22:38:00 +0000 |
parents | f1e5e8a324a5 |
children | a52a879c385c |
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'" |
145 "-e '/Reformatting page. Wait... done/d'" | |
146 "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" | |
147 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" | |
148 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" | |
149 "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'" | |
150 "-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
|
151 "-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
|
152 "-e '/^[A-za-z].*Last change:/d'" |
3235 | 153 "-e '/^Sun Release [0-9].*[0-9]$/d'" |
154 "-e '/^\\n$/D'" | |
155 )) | |
4329
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
156 ("awk '\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
157 ("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
|
158 "/^$/ { 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
|
159 "{ anonblank=1; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
160 "/^$/ { blankline++; next; }\n" |
dfabe5b99500
(Man-filter-list): Insert \n newlines in awk script.
Richard M. Stallman <rms@gnu.org>
parents:
4203
diff
changeset
|
161 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n" |
3235 | 162 "'" |
163 )) | |
164 ) | |
165 "*Manpage cleaning filter command phrases. | |
166 This variable contains an association list of the following form: | |
167 | |
168 '((command-string (phrase-string*))*) | |
169 | |
170 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
|
171 command filter. The (standard) output (and standard error) of the Un*x |
3235 | 172 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
|
173 commands appear in the association list. The final output is placed in |
3235 | 174 the manpage buffer.") |
175 | |
176 (defvar Man-mode-line-format | |
177 '("" mode-line-modified | |
178 mode-line-buffer-identification " " | |
179 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
|
180 " " Man-page-mode-string |
3235 | 181 " %[(" mode-name minor-mode-alist mode-line-process ")%]----" |
182 (-3 . "%p") "-%-") | |
183 "*Mode line format for manual mode buffer.") | |
184 | |
185 (defvar Man-mode-map nil | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
186 "*Keymap for Man mode.") |
3235 | 187 |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
188 (defvar Man-mode-hook nil |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
189 "*Normal hook run when Man mode is enabled.") |
3235 | 190 |
4980
50708e8b133b
(Man-section-regexp): Allow section names l, n, L, N.
Richard M. Stallman <rms@gnu.org>
parents:
4968
diff
changeset
|
191 (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]" |
3235 | 192 "*Regular expression describing a manpage section within parentheses.") |
193 | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
194 (defvar Man-heading-regexp "^ ?[A-Z]" |
3235 | 195 "*Regular expression describing a manpage heading entry.") |
196 | |
197 (defvar Man-see-also-regexp "SEE ALSO" | |
198 "*Regular expression for SEE ALSO heading (or your equivalent). | |
199 This regexp should not start with a `^' character.") | |
200 | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
201 (defvar Man-first-heading-regexp "^ ?NAME$\\|^ ?No manual entry for .*$" |
3235 | 202 "*Regular expression describing first heading on a manpage. |
203 This regular expression should 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-reference-regexp |
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
206 "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*\\(([0-9][a-zA-Z+]*)\\)?" |
3235 | 207 "*Regular expression describing a reference in the SEE ALSO section.") |
208 | |
3833
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
209 (defvar Man-switches "" |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
210 "*Switches passed to the man command, as a single string.") |
3235 | 211 |
5108
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
212 ;; 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
|
213 ;; 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
|
214 ;; 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
|
215 (defvar Man-specified-section-option |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
216 (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
|
217 "-s" |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
218 "") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
219 "*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
|
220 |
3235 | 221 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
222 ;; end user variables | |
223 | |
224 ;; other variables and keymap initializations | |
225 (make-variable-buffer-local 'Man-sections-alist) | |
226 (make-variable-buffer-local 'Man-refpages-alist) | |
227 (make-variable-buffer-local 'Man-page-list) | |
228 (make-variable-buffer-local 'Man-current-page) | |
229 (make-variable-buffer-local 'Man-page-mode-string) | |
230 | |
231 (setq-default Man-sections-alist nil) | |
232 (setq-default Man-refpages-alist nil) | |
233 (setq-default Man-page-list nil) | |
234 (setq-default Man-current-page 0) | |
235 (setq-default Man-page-mode-string "1 (of 1)") | |
236 | |
237 (if Man-mode-map | |
238 nil | |
239 (setq Man-mode-map (make-keymap)) | |
240 (suppress-keymap Man-mode-map) | |
241 (define-key Man-mode-map " " 'scroll-up) | |
242 (define-key Man-mode-map "\177" 'scroll-down) | |
243 (define-key Man-mode-map "n" 'Man-next-section) | |
244 (define-key Man-mode-map "p" 'Man-previous-section) | |
245 (define-key Man-mode-map "\en" 'Man-next-manpage) | |
246 (define-key Man-mode-map "\ep" 'Man-previous-manpage) | |
247 (define-key Man-mode-map "," 'beginning-of-buffer) | |
248 (define-key Man-mode-map "." 'end-of-buffer) | |
249 (define-key Man-mode-map "r" 'Man-follow-manual-reference) | |
250 (define-key Man-mode-map "t" 'toggle-truncate-lines) | |
251 (define-key Man-mode-map "g" 'Man-goto-section) | |
252 (define-key Man-mode-map "s" 'Man-goto-see-also-section) | |
253 (define-key Man-mode-map "q" 'Man-quit) | |
254 (define-key Man-mode-map "m" 'manual-entry) | |
255 (define-key Man-mode-map "?" 'describe-mode) | |
256 ) | |
257 | |
258 | |
259 ;; ====================================================================== | |
260 ;; utilities | |
261 | |
262 (defun Man-page-mode-string () | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
263 "Formats part of the mode line for Man mode." |
3235 | 264 (format "%d (of %d)" Man-current-page (length Man-page-list))) |
265 | |
266 (defun Man-delete-trailing-newline (str) | |
267 (if (string= (substring str (1- (length str))) "\n") | |
268 (substring str 0 (1- (length str))) | |
269 str)) | |
270 | |
271 (defun Man-build-man-command () | |
272 "Builds the entire background manpage and cleaning command." | |
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
|
273 (let ((command (concat "man " Man-switches " %s 2>&1")) |
3235 | 274 (flist Man-filter-list)) |
275 (while flist | |
276 (let ((pcom (car (car flist))) | |
277 (pargs (car (cdr (car flist))))) | |
278 (setq flist (cdr flist)) | |
279 (if (or (not (stringp pcom)) | |
280 (not (listp pargs))) | |
281 (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
|
282 (setq command (concat command " | " pcom |
3235 | 283 (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
|
284 pargs " "))))) |
3235 | 285 command)) |
286 | |
287 (defun Man-downcase (man-args) | |
288 "Downcases section letters in MAN-ARGS." | |
289 (let ((newargs "") | |
290 (s 0) | |
291 mstart mend | |
292 (len (length man-args))) | |
293 (while (and (< s len) | |
294 (setq mstart (string-match Man-section-regexp man-args s))) | |
295 (setq mend (match-end 0) | |
296 newargs (concat newargs (substring man-args s mstart))) | |
297 (setq newargs (concat newargs (downcase | |
298 (substring man-args mstart mend))) | |
299 s mend)) | |
300 (concat newargs (substring man-args s len)))) | |
301 | |
302 (defun Man-translate-references (ref) | |
303 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style." | |
304 (if (string-match (concat "(" Man-section-regexp ")$") ref) | |
305 (let* ((word (progn (string-match "(" ref) | |
306 (substring ref 0 (1- (match-end 0))))) | |
307 (section-re (concat "(\\(" Man-section-regexp "\\))")) | |
308 (section (if (string-match section-re ref) | |
309 (substring ref (match-beginning 1) (match-end 1)) | |
310 "")) | |
311 (slist Man-section-translations-alist) | |
312 ) | |
313 (if Man-downcase-section-letters-p | |
314 (setq section (Man-downcase section))) | |
315 (while slist | |
316 (let ((s1 (car (car slist))) | |
317 (s2 (cdr (car slist)))) | |
318 (setq slist (cdr slist)) | |
319 (if Man-downcase-section-letters-p | |
320 (setq s1 (Man-downcase s1))) | |
321 (if (not (string= s1 section)) nil | |
322 (setq section (if Man-downcase-section-letters-p | |
323 (Man-downcase s2) | |
324 s2) | |
325 slist nil)))) | |
5108
8c482171bb10
(Man-specified-section-option): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4980
diff
changeset
|
326 (concat Man-specified-section-option section " " word)) |
3235 | 327 ref)) |
328 | |
329 (defun Man-linepos (&optional position col-p) | |
330 "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
|
331 Preserves the state of point, mark, etc. Optional arg POSITION can be one |
3235 | 332 of the following symbols: |
333 bol == beginning of line | |
334 boi == beginning of indentation | |
335 eol == end of line [default] | |
336 bob == beginning of buffer | |
337 eob == end of buffer | |
338 | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
339 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
|
340 the current column instead of character position." |
3235 | 341 (let ((tpnt (point)) |
342 rval) | |
343 (cond | |
344 ((eq position 'bol) (beginning-of-line)) | |
345 ((eq position 'boi) (back-to-indentation)) | |
346 ((eq position 'bob) (goto-char (point-min))) | |
347 ((eq position 'eob) (goto-char (point-max))) | |
348 (t (end-of-line))) | |
349 (setq rval (if col-p (current-column) (point))) | |
350 (goto-char tpnt) | |
351 rval)) | |
352 | |
353 | |
354 ;; ====================================================================== | |
355 ;; default man entry and get word under point | |
356 | |
357 (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
|
358 "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
|
359 (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
|
360 (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
|
361 ((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
|
362 ((consp sections) |
5572
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
363 (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
|
364 n " " manword)) |
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
365 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
|
366 (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
|
367 (concat sections " " manword))))) |
3235 | 368 |
369 (defun Man-default-man-entry () | |
370 "Make a guess at a default manual entry. | |
371 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
|
372 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
|
373 (let (default-title) |
3235 | 374 (save-excursion |
375 | |
376 ;; Default man entry title is any word the cursor is on, | |
377 ;; or if cursor not on a word, then nearest preceding | |
378 ;; word. | |
379 (and (not (looking-at "[a-zA-Z_]")) | |
380 (skip-chars-backward "^a-zA-Z_")) | |
381 (skip-chars-backward "(a-zA-Z_0-9") | |
382 (and (looking-at "(") (forward-char 1)) | |
383 (setq default-title | |
384 (buffer-substring | |
385 (point) | |
386 (progn (skip-chars-forward "a-zA-Z0-9_") (point)))) | |
387 | |
388 ;; If looking at something like ioctl(2) or brc(1M), include | |
389 ;; section number in default-entry | |
390 (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)") | |
391 (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
|
392 (setq default-title |
5572
f1e5e8a324a5
(Man-default-man-args): Use Man-specified-section-option.
Richard M. Stallman <rms@gnu.org>
parents:
5269
diff
changeset
|
393 (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
|
394 (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
|
395 (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
|
396 (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
|
397 (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
|
398 (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
|
399 " " |
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 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
|
401 (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
|
402 default-title))) |
3235 | 403 |
404 | |
405 ;; ====================================================================== | |
406 ;; top level command and background process sentinel | |
407 | |
4444 | 408 ;;; This alias makes completion more predictable if ignoring case. |
409 ;;;###autoload | |
410 (defalias 'man 'manual-entry) | |
411 | |
3235 | 412 ;;;###autoload |
413 (defun manual-entry (arg) | |
414 "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
|
415 This command is the top-level command in the man package. It runs a Un*x |
3235 | 416 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
|
417 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
|
418 `Man-notify' for what happens when the buffer is ready. |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
419 Universal argument ARG, is passed to `Man-getpage-in-background'." |
3235 | 420 (interactive "P") |
421 (let* ((default-entry (Man-default-man-entry)) | |
422 (man-args | |
423 (read-string (format "Manual-entry: %s" | |
424 (if (string= default-entry "") "" | |
425 (format "(default: %s) " | |
426 default-entry)))))) | |
427 (and (string= man-args "") | |
428 (if (string= default-entry "") | |
429 (error "No man args given.") | |
430 (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
|
431 |
3644
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
432 ;; 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
|
433 (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
|
434 |
4968
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
435 ;; 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
|
436 ;; (if Man-downcase-section-letters-p |
1607732e7712
(Man-filter-list): Include anything starting with
Richard M. Stallman <rms@gnu.org>
parents:
4915
diff
changeset
|
437 ;; (setq man-args (Man-downcase man-args))) |
3235 | 438 (Man-getpage-in-background man-args (consp arg)) |
439 )) | |
440 | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
441 (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
|
442 "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
|
443 Optional OVERRIDE-REUSE-P, when non-nil, means to |
3235 | 444 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
|
445 `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
|
446 (let* ((man-args topic) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
447 (bufname (concat "*man " man-args "*")) |
3235 | 448 (buffer (get-buffer bufname))) |
449 (if (and Man-reuse-okay-p | |
450 (not override-reuse-p) | |
451 buffer) | |
452 (Man-notify-when-ready buffer) | |
453 (message "Invoking man %s in background..." man-args) | |
454 (setq buffer (generate-new-buffer bufname)) | |
4175
3e4fa4423f5a
(Man-getpage-in-background): Copy process-environment
Richard M. Stallman <rms@gnu.org>
parents:
4009
diff
changeset
|
455 (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
|
456 ;; 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
|
457 (setenv "TERM" "dumb") |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
458 (set-process-sentinel |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
459 (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
|
460 (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
|
461 'Man-bgproc-sentinel)) |
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
462 ))) |
3235 | 463 |
464 (defun Man-notify-when-ready (man-buffer) | |
465 "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
|
466 See the variable `Man-notify' for the different notification behaviors." |
3235 | 467 (cond |
4915
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
468 ((eq Man-notify 'newframe) |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
469 (set-buffer man-buffer) |
c0523a78e6a5
(Man-frame-parameters): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
4444
diff
changeset
|
470 (new-frame Man-frame-parameters)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
471 ((eq Man-notify 'bully) |
3235 | 472 (pop-to-buffer man-buffer) |
473 (delete-other-windows)) | |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
474 ((eq Man-notify 'aggressive) |
3235 | 475 (pop-to-buffer man-buffer)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
476 ((eq Man-notify 'friendly) |
3235 | 477 (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
|
478 ((eq Man-notify 'polite) |
3235 | 479 (beep) |
480 (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
|
481 ((eq Man-notify 'quiet) |
3235 | 482 (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
|
483 ((or (eq Man-notify 'meek) |
3235 | 484 t) |
485 (message "")) | |
486 )) | |
487 | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
488 (defun Man-set-fonts () |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
489 (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
|
490 (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
|
491 (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
|
492 (goto-char st) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
493 (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
|
494 (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
|
495 (if (looking-at "_") 'underline 'bold))) |
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
496 (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
|
497 (replace-match ""))))) |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
498 |
3235 | 499 (defun Man-bgproc-sentinel (process msg) |
500 "Manpage background process sentinel." | |
501 (let ((Man-buffer (process-buffer process)) | |
502 (delete-buff nil) | |
503 (err-mess nil)) | |
504 (if (null (buffer-name Man-buffer)) ;; deleted buffer | |
505 (set-process-buffer process nil) | |
506 (save-excursion | |
507 (set-buffer Man-buffer) | |
508 (goto-char (point-min)) | |
509 (cond ((or (looking-at "No \\(manual \\)*entry for") | |
510 (looking-at "[^\n]*: nothing appropriate$")) | |
511 (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) | |
512 delete-buff t) | |
513 ) | |
514 ((not (and (eq (process-status process) 'exit) | |
515 (= (process-exit-status process) 0))) | |
516 (setq err-mess | |
517 (concat (buffer-name Man-buffer) | |
518 ": process " | |
519 (let ((eos (1- (length msg)))) | |
520 (if (= (aref msg eos) ?\n) | |
521 (substring msg 0 eos) msg)))) | |
522 (goto-char (point-max)) | |
523 (insert (format "\nprocess %s" msg)) | |
524 ))) | |
525 (if delete-buff | |
526 (kill-buffer Man-buffer) | |
527 (save-window-excursion | |
528 (save-excursion | |
529 (set-buffer Man-buffer) | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
530 (Man-set-fonts) |
3235 | 531 (Man-mode) |
532 (set-buffer-modified-p nil))) | |
533 (Man-notify-when-ready Man-buffer)) | |
534 | |
535 (if err-mess | |
536 (error err-mess)) | |
537 ))) | |
538 | |
539 | |
540 ;; ====================================================================== | |
541 ;; set up manual mode in buffer and build alists | |
542 | |
543 (defun Man-mode () | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
544 "A mode for browsing Un*x manual pages. |
3235 | 545 |
546 The following man commands are available in the buffer. Try | |
547 \"\\[describe-key] <key> RET\" for more information: | |
548 | |
549 \\[manual-entry] Prompt to retrieve a new manpage. | |
550 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section. | |
551 \\[Man-next-manpage] Jump to next manpage in circular list. | |
552 \\[Man-previous-manpage] Jump to previous manpage in circular list. | |
553 \\[Man-next-section] Jump to next manpage section. | |
554 \\[Man-previous-section] Jump to previous manpage section. | |
555 \\[Man-goto-section] Go to a manpage section. | |
556 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. | |
557 \\[Man-quit] Deletes the manpage, its buffer, and window. | |
558 \\[describe-mode] Prints this help text. | |
559 | |
560 The following variables may be of some use. Try | |
561 \"\\[describe-variable] <variable-name> RET\" for more information: | |
562 | |
563 Man-notify What happens when manpage formatting is done. | |
564 Man-reuse-okay-p Okay to reuse already formatted buffer? | |
565 Man-downcase-section-letters-p Force section letters to lower case? | |
566 Man-circular-pages-p Multiple manpage list treated as circular? | |
567 Man-auto-section-alist List of major modes and their section numbers. | |
568 Man-section-translations-alist List of section numbers and their Un*x equiv. | |
569 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
|
570 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
|
571 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
|
572 Man-mode-hook Normal hook run on entry to Man mode. |
3235 | 573 Man-section-regexp Regexp describing manpage section letters. |
574 Man-heading-regexp Regexp describing section headers. | |
575 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). | |
576 Man-first-heading-regexp Regexp for first heading on a manpage. | |
577 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
|
578 Man-switches Background `man' command switches. |
3235 | 579 |
580 The following key bindings are currently in effect in the buffer: | |
581 \\{Man-mode-map}" | |
582 (interactive) | |
583 (setq major-mode 'Man-mode | |
3909
192e7aa8389a
(Man-auto-section-alist): Default value nil.
Richard M. Stallman <rms@gnu.org>
parents:
3833
diff
changeset
|
584 mode-name "Man" |
3235 | 585 buffer-auto-save-file-name nil |
586 mode-line-format Man-mode-line-format | |
587 truncate-lines t | |
588 buffer-read-only t) | |
589 (buffer-disable-undo (current-buffer)) | |
590 (auto-fill-mode -1) | |
591 (use-local-map Man-mode-map) | |
592 (goto-char (point-min)) | |
593 (Man-build-page-list) | |
3619
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
594 (Man-goto-page 1) |
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
595 (run-hooks 'Man-mode-hook)) |
3235 | 596 |
597 (defun Man-build-section-alist () | |
598 "Build the association list of manpage sections." | |
599 (setq Man-sections-alist nil) | |
600 (goto-char (point-min)) | |
601 (while (re-search-forward Man-heading-regexp (point-max) t) | |
602 (aput 'Man-sections-alist | |
603 (buffer-substring (Man-linepos 'bol) (Man-linepos))) | |
604 (forward-line 1) | |
605 )) | |
606 | |
607 (defun Man-build-references-alist () | |
608 "Build the association list of references (in the SEE ALSO section)." | |
609 (setq Man-refpages-alist nil) | |
610 (save-excursion | |
611 (if (Man-find-section Man-see-also-regexp) | |
612 (let ((start (progn (forward-line 1) (point))) | |
613 (end (progn | |
614 (Man-next-section 1) | |
615 (point))) | |
616 hyphenated | |
617 (runningpoint -1)) | |
618 (narrow-to-region start end) | |
619 (goto-char (point-min)) | |
620 (back-to-indentation) | |
621 (while (and (not (eobp)) (/= (point) runningpoint)) | |
622 (setq runningpoint (point)) | |
4377
09cb5e07f8a3
(Man-build-references-alist): When setting word,
Richard M. Stallman <rms@gnu.org>
parents:
4334
diff
changeset
|
623 (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
|
624 (word (buffer-substring (match-beginning 0) (match-end 0))) |
3235 | 625 (len (1- (length word)))) |
626 (if (not eow) nil | |
627 (if hyphenated | |
628 (setq word (concat hyphenated word) | |
629 hyphenated nil)) | |
630 (if (= (aref word len) ?-) | |
631 (setq hyphenated (substring word 0 len)) | |
632 (aput 'Man-refpages-alist word)))) | |
633 (skip-chars-forward " \t\n,")) | |
634 )))) | |
635 | |
636 (defun Man-build-page-list () | |
637 "Build the list of separate manpages in the buffer." | |
638 (setq Man-page-list nil) | |
639 (save-excursion | |
640 (let ((page-start (Man-linepos 'bob)) | |
641 (page-end (Man-linepos 'eob)) | |
642 (regexp Man-first-heading-regexp)) | |
643 (goto-char (point-min)) | |
644 (re-search-forward regexp (point-max) t) | |
645 (while (not (eobp)) | |
646 (if (re-search-forward regexp (point-max) t) | |
647 (progn | |
648 (setq page-end (Man-linepos 'bol)) | |
649 (end-of-line)) | |
650 (goto-char (point-max)) | |
651 (setq page-end (point))) | |
652 (setq Man-page-list (append Man-page-list | |
653 (list (cons page-start page-end))) | |
654 page-start page-end) | |
655 )))) | |
656 | |
657 | |
658 ;; ====================================================================== | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
659 ;; Man mode commands |
3235 | 660 |
661 (defun Man-next-section (n) | |
662 "Move point to Nth next section (default 1)." | |
663 (interactive "p") | |
664 (if (looking-at Man-heading-regexp) | |
665 (forward-line 1)) | |
666 (if (re-search-forward Man-heading-regexp (point-max) t n) | |
667 (beginning-of-line) | |
668 (goto-char (point-max)))) | |
669 | |
670 (defun Man-previous-section (n) | |
671 "Move point to Nth previous section (default 1)." | |
672 (interactive "p") | |
673 (if (looking-at Man-heading-regexp) | |
674 (forward-line -1)) | |
675 (if (re-search-backward Man-heading-regexp (point-min) t n) | |
676 (beginning-of-line) | |
677 (goto-char (point-min)))) | |
678 | |
679 (defun Man-find-section (section) | |
680 "Move point to SECTION if it exists, otherwise don't move point. | |
681 Returns t if section is found, nil otherwise." | |
682 (let ((curpos (point))) | |
683 (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
|
684 (if (re-search-forward (concat "^\\s-?" section) (point-max) t) |
3235 | 685 (progn (beginning-of-line) t) |
686 (goto-char curpos) | |
687 nil) | |
688 )) | |
689 | |
690 (defun Man-goto-section () | |
691 "Query for section to move point to." | |
692 (interactive) | |
693 (aput 'Man-sections-alist | |
694 (let* ((default (aheadsym Man-sections-alist)) | |
695 (completion-ignore-case t) | |
696 chosen | |
697 (prompt (concat "Go to section: (default " default ") "))) | |
698 (setq chosen (completing-read prompt Man-sections-alist)) | |
699 (if (or (not chosen) | |
700 (string= chosen "")) | |
701 default | |
702 chosen))) | |
703 (Man-find-section (aheadsym Man-sections-alist))) | |
704 | |
705 (defun Man-goto-see-also-section () | |
706 "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
|
707 Actually the section moved to is described by `Man-see-also-regexp'." |
3235 | 708 (interactive) |
709 (if (not (Man-find-section Man-see-also-regexp)) | |
710 (error (concat "No " Man-see-also-regexp | |
711 " section found in current manpage.")))) | |
712 | |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
713 (defun Man-follow-manual-reference (arg reference) |
3235 | 714 "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
|
715 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
|
716 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
|
717 (interactive |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
718 (if (not Man-refpages-alist) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
719 (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
|
720 (list current-prefix-arg |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
721 (let* ((default (or |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
722 (car (all-completions |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
723 (save-excursion |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
724 (skip-syntax-backward "w()") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
725 (skip-chars-forward " \t") |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
726 (let ((word (current-word))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
727 ;; strip a trailing '-': |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
728 (if (string-match "-$" word) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
729 (substring word 0 (match-beginning 0)) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
730 word))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
731 Man-refpages-alist)) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
732 (aheadsym Man-refpages-alist))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
733 chosen |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
734 (prompt (concat "Refer to: (default " default ") "))) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
735 (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
|
736 (if (or (not chosen) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
737 (string= chosen "")) |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
738 default |
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
739 chosen))))) |
3235 | 740 (if (not Man-refpages-alist) |
5269
c6588bd7dd93
(Man-specified-section-option): Test system-configuration.
Richard M. Stallman <rms@gnu.org>
parents:
5108
diff
changeset
|
741 (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
|
742 (aput 'Man-refpages-alist reference) |
3235 | 743 (Man-getpage-in-background |
744 (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
|
745 arg))) |
3235 | 746 |
747 (defun Man-quit () | |
748 "Kill the buffer containing the manpage." | |
749 (interactive) | |
750 (let ((buff (current-buffer))) | |
751 (delete-windows-on buff) | |
752 (kill-buffer buff))) | |
753 | |
754 (defun Man-goto-page (page) | |
755 "Go to the manual page on page PAGE." | |
756 (interactive | |
757 (if (not Man-page-list) | |
758 (error "You're looking at the only manpage in the buffer.") | |
759 (format "nGo to manpage [1-%d]: " (length Man-page-list)))) | |
760 (if (or (< page 1) | |
761 (> page (length Man-page-list))) | |
762 (error "No manpage %d found" page)) | |
763 (let* ((page-range (nth (1- page) Man-page-list)) | |
764 (page-start (car page-range)) | |
765 (page-end (cdr page-range))) | |
766 (setq Man-current-page page | |
767 Man-page-mode-string (Man-page-mode-string)) | |
768 (widen) | |
769 (goto-char page-start) | |
770 (narrow-to-region page-start page-end) | |
771 (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
|
772 ;; 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
|
773 ;; 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
|
774 (condition-case nil |
296caa999ccf
(Man-filter-list): Add an element for X man pages.
Richard M. Stallman <rms@gnu.org>
parents:
3644
diff
changeset
|
775 (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
|
776 (error)) |
3235 | 777 (widen) |
778 (narrow-to-region page-start page-end) | |
779 (goto-char (point-min)))) | |
780 | |
781 | |
782 (defun Man-next-manpage () | |
783 "Find the next manpage entry in the buffer." | |
784 (interactive) | |
785 (if (= (length Man-page-list) 1) | |
786 (error "This is the only manpage in the buffer.")) | |
787 (if (< Man-current-page (length Man-page-list)) | |
788 (Man-goto-page (1+ Man-current-page)) | |
789 (if Man-circular-pages-p | |
790 (Man-goto-page 1) | |
791 (error "You're looking at the last manpage in the buffer.")))) | |
792 | |
793 (defun Man-previous-manpage () | |
794 "Find the previous manpage entry in the buffer." | |
795 (interactive) | |
796 (if (= (length Man-page-list) 1) | |
797 (error "This is the only manpage in the buffer.")) | |
798 (if (> Man-current-page 1) | |
799 (Man-goto-page (1- Man-current-page)) | |
800 (if Man-circular-pages-p | |
801 (Man-goto-page (length Man-page-list)) | |
802 (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
|
803 |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
804 (provide 'man) |
70551a213fae
* man.el (Man-switches): New variable.
Jim Blandy <jimb@redhat.com>
parents:
3714
diff
changeset
|
805 |
3235 | 806 ;;; man.el ends here |