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