Mercurial > emacs
annotate lisp/man.el @ 3759:036367460955
* sysdep.c [ultrix] (init_sys_modes): Don't set LLITOUT; it
disables the meta key.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Wed, 16 Jun 1993 20:02:58 +0000 |
parents | a1edd269b2f4 |
children | 70551a213fae |
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 | |
65 ;; "man <section>, etc. | |
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 (provide 'man) | |
76 | |
77 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | |
78 ;; user variables | |
79 | |
80 (defvar Man-notify 'friendly | |
81 "*Selects the behavior when manpage is ready. | |
82 This variable may have one of the following values: | |
83 | |
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 | |
93 (defvar Man-reuse-okay-p t | |
94 "*Reuse a manpage buffer if possible. | |
95 When t, and a manpage buffer already exists with the same invocation, | |
96 man just indicates the manpage is ready according to the value of | |
97 Man-notify. When nil, it always fires off a background process, putting | |
98 the results in a uniquely named buffer.") | |
99 | |
100 (defvar Man-downcase-section-letters-p t | |
101 "*Letters in sections are converted to lower case. | |
102 Some Un*x man commands can't handle uppercase letters in sections, for | |
103 example \"man 2V chmod\", but they are often displayed in the manpage | |
104 with the upper case letter. When this variable is t, the section | |
105 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before | |
106 being sent to the man background process.") | |
107 | |
108 (defvar Man-circular-pages-p t | |
109 "*If t, the manpage list is treated as circular for traversal.") | |
110 | |
111 (defvar Man-auto-section-alist | |
112 '((c-mode . ("2" "3")) | |
113 (c++-mode . ("2" "3")) | |
114 (shell-mode . ("1" "8")) | |
115 (cmushell-mode . ("1" "8")) | |
116 (text-mode . "1") | |
117 ) | |
118 "*Association list of major modes and their default section numbers. | |
119 List is of the form: (MAJOR-MODE . [SECTION | (SECTION*)]). If current | |
120 major mode is not in list, then the default is to check for manpages | |
121 in all sections.") | |
122 | |
123 (defvar Man-section-translations-alist | |
124 '(("3C++" . "3") | |
125 ("1-UCB" . "")) | |
126 "*Association list of bogus sections to real section numbers. | |
127 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in | |
128 their references which Un*x man(1) does not recognize. This | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3307
diff
changeset
|
129 association list is used to translate those sections, when found, to |
3235 | 130 the associated section number.") |
131 | |
132 (defvar Man-filter-list | |
133 '(("sed " | |
134 ("-e 's/.\010//g'" | |
135 "-e '/[Nn]o such file or directory/d'" | |
136 "-e '/Reformatting page. Wait... done/d'" | |
137 "-e '/^\\([A-Z][A-Z.]*([0-9A-Za-z][-0-9A-Za-z+]*)\\).*\\1$/d'" | |
138 "-e '/^[ \\t]*Hewlett-Packard Company[ \\t]*- [0-9]* -.*$/d'" | |
139 "-e '/^[ \\t]*Hewlett-Packard[ \\t]*- [0-9]* -.*$/d'" | |
140 "-e '/^ *Page [0-9]*.*(printed [0-9\\/]*)$/d'" | |
141 "-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
|
142 "-e '/^[ \\t]*X Version 1[01].*Release [0-9]/d'" |
3235 | 143 "-e '/^Sun Microsystems.*Last change:/d'" |
144 "-e '/^Sun Release [0-9].*[0-9]$/d'" | |
145 "-e '/^\\n$/D'" | |
146 )) | |
147 ("awk '" | |
148 ("BEGIN { blankline=0; anonblank=0; }" | |
149 "/^$/ { if (anonblank==0) next; }" | |
150 "{ anonblank=1; }" | |
151 "/^$/ { blankline++; next; }" | |
152 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }" | |
153 "'" | |
154 )) | |
155 ) | |
156 "*Manpage cleaning filter command phrases. | |
157 This variable contains an association list of the following form: | |
158 | |
159 '((command-string (phrase-string*))*) | |
160 | |
161 Each phrase-string is concatenated onto the command-string to form a | |
162 command filter. The (standard) output (and standard error) of the Un*x | |
163 man command is piped through each command filter in the order the | |
164 commands appear in the association list. The final output is placed in | |
165 the manpage buffer.") | |
166 | |
167 (defvar Man-mode-line-format | |
168 '("" mode-line-modified | |
169 mode-line-buffer-identification " " | |
170 global-mode-string | |
171 Man-page-mode-string | |
172 " %[(" mode-name minor-mode-alist mode-line-process ")%]----" | |
173 (-3 . "%p") "-%-") | |
174 "*Mode line format for manual mode buffer.") | |
175 | |
176 (defvar Man-mode-map nil | |
177 "*Keymap for Man-mode.") | |
178 | |
179 (defvar Man-mode-hooks nil | |
180 "*Hooks for Man-mode.") | |
181 | |
182 (defvar Man-section-regexp "[0-9][a-zA-Z+]*" | |
183 "*Regular expression describing a manpage section within parentheses.") | |
184 | |
185 (defvar Man-heading-regexp "^[A-Z]" | |
186 "*Regular expression describing a manpage heading entry.") | |
187 | |
188 (defvar Man-see-also-regexp "SEE ALSO" | |
189 "*Regular expression for SEE ALSO heading (or your equivalent). | |
190 This regexp should not start with a `^' character.") | |
191 | |
192 (defvar Man-first-heading-regexp "^NAME$\\|^No manual entry for .*$" | |
193 "*Regular expression describing first heading on a manpage. | |
194 This regular expression should start with a `^' character.") | |
195 | |
196 (defvar Man-reference-regexp "[-a-zA-Z0-9_.]+\\(([0-9][a-zA-Z+]*)\\)?" | |
197 "*Regular expression describing a reference in the SEE ALSO section.") | |
198 | |
199 | |
200 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
201 ;; end user variables | |
202 | |
203 (defconst Man-version-number "1.1" | |
204 "man's version number.") | |
205 | |
206 | |
207 ;; other variables and keymap initializations | |
208 (make-variable-buffer-local 'Man-sections-alist) | |
209 (make-variable-buffer-local 'Man-refpages-alist) | |
210 (make-variable-buffer-local 'Man-page-list) | |
211 (make-variable-buffer-local 'Man-current-page) | |
212 (make-variable-buffer-local 'Man-page-mode-string) | |
213 | |
214 (setq-default Man-sections-alist nil) | |
215 (setq-default Man-refpages-alist nil) | |
216 (setq-default Man-page-list nil) | |
217 (setq-default Man-current-page 0) | |
218 (setq-default Man-page-mode-string "1 (of 1)") | |
219 | |
220 (if Man-mode-map | |
221 nil | |
222 (setq Man-mode-map (make-keymap)) | |
223 (suppress-keymap Man-mode-map) | |
224 (define-key Man-mode-map " " 'scroll-up) | |
225 (define-key Man-mode-map "\177" 'scroll-down) | |
226 (define-key Man-mode-map "n" 'Man-next-section) | |
227 (define-key Man-mode-map "p" 'Man-previous-section) | |
228 (define-key Man-mode-map "\en" 'Man-next-manpage) | |
229 (define-key Man-mode-map "\ep" 'Man-previous-manpage) | |
230 (define-key Man-mode-map "," 'beginning-of-buffer) | |
231 (define-key Man-mode-map "." 'end-of-buffer) | |
232 (define-key Man-mode-map "r" 'Man-follow-manual-reference) | |
233 (define-key Man-mode-map "t" 'toggle-truncate-lines) | |
234 (define-key Man-mode-map "g" 'Man-goto-section) | |
235 (define-key Man-mode-map "s" 'Man-goto-see-also-section) | |
236 (define-key Man-mode-map "q" 'Man-quit) | |
237 (define-key Man-mode-map "m" 'manual-entry) | |
238 (define-key Man-mode-map "v" 'Man-version) | |
239 (define-key Man-mode-map "?" 'describe-mode) | |
240 ) | |
241 | |
242 | |
243 ;; ====================================================================== | |
244 ;; utilities | |
245 | |
246 (defun Man-page-mode-string () | |
247 "Formats part of the mode line for manual mode." | |
248 (format "%d (of %d)" Man-current-page (length Man-page-list))) | |
249 | |
250 (defun Man-delete-trailing-newline (str) | |
251 (if (string= (substring str (1- (length str))) "\n") | |
252 (substring str 0 (1- (length str))) | |
253 str)) | |
254 | |
255 (defun Man-build-man-command () | |
256 "Builds the entire background manpage and cleaning command." | |
257 (let ((command "man %s 2>&1 | ") | |
258 (flist Man-filter-list)) | |
259 (while flist | |
260 (let ((pcom (car (car flist))) | |
261 (pargs (car (cdr (car flist))))) | |
262 (setq flist (cdr flist)) | |
263 (if (or (not (stringp pcom)) | |
264 (not (listp pargs))) | |
265 (error "malformed Man-filter-list.")) | |
266 (setq command (concat command pcom | |
267 (mapconcat '(lambda (phrase) phrase) | |
268 pargs " ")))) | |
269 (if flist | |
270 (setq command (concat command " | " )))) | |
271 command)) | |
272 | |
273 (defun Man-downcase (man-args) | |
274 "Downcases section letters in MAN-ARGS." | |
275 (let ((newargs "") | |
276 (s 0) | |
277 mstart mend | |
278 (len (length man-args))) | |
279 (while (and (< s len) | |
280 (setq mstart (string-match Man-section-regexp man-args s))) | |
281 (setq mend (match-end 0) | |
282 newargs (concat newargs (substring man-args s mstart))) | |
283 (setq newargs (concat newargs (downcase | |
284 (substring man-args mstart mend))) | |
285 s mend)) | |
286 (concat newargs (substring man-args s len)))) | |
287 | |
288 (defun Man-translate-references (ref) | |
289 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style." | |
290 (if (string-match (concat "(" Man-section-regexp ")$") ref) | |
291 (let* ((word (progn (string-match "(" ref) | |
292 (substring ref 0 (1- (match-end 0))))) | |
293 (section-re (concat "(\\(" Man-section-regexp "\\))")) | |
294 (section (if (string-match section-re ref) | |
295 (substring ref (match-beginning 1) (match-end 1)) | |
296 "")) | |
297 (slist Man-section-translations-alist) | |
298 ) | |
299 (if Man-downcase-section-letters-p | |
300 (setq section (Man-downcase section))) | |
301 (while slist | |
302 (let ((s1 (car (car slist))) | |
303 (s2 (cdr (car slist)))) | |
304 (setq slist (cdr slist)) | |
305 (if Man-downcase-section-letters-p | |
306 (setq s1 (Man-downcase s1))) | |
307 (if (not (string= s1 section)) nil | |
308 (setq section (if Man-downcase-section-letters-p | |
309 (Man-downcase s2) | |
310 s2) | |
311 slist nil)))) | |
312 (concat section " " word)) | |
313 ref)) | |
314 | |
315 (defun Man-linepos (&optional position col-p) | |
316 "Return the character position at various line/buffer positions. | |
317 Preserves the state of point, mark, etc. Optional POSITION can be one | |
318 of the following symbols: | |
319 bol == beginning of line | |
320 boi == beginning of indentation | |
321 eol == end of line [default] | |
322 bob == beginning of buffer | |
323 eob == end of buffer | |
324 | |
325 Optional COL-P non-nil returns current-column instead of character position." | |
326 (let ((tpnt (point)) | |
327 rval) | |
328 (cond | |
329 ((eq position 'bol) (beginning-of-line)) | |
330 ((eq position 'boi) (back-to-indentation)) | |
331 ((eq position 'bob) (goto-char (point-min))) | |
332 ((eq position 'eob) (goto-char (point-max))) | |
333 (t (end-of-line))) | |
334 (setq rval (if col-p (current-column) (point))) | |
335 (goto-char tpnt) | |
336 rval)) | |
337 | |
338 | |
339 ;; ====================================================================== | |
340 ;; default man entry and get word under point | |
341 | |
342 (defun Man-default-man-args (manword) | |
343 "Build the default man args from MANWORD and major-mode." | |
344 (let ((mode major-mode) | |
345 (slist Man-auto-section-alist)) | |
346 (while (and slist | |
347 (not (eq (car (car slist)) mode))) | |
348 (setq slist (cdr slist))) | |
349 (if (not slist) | |
350 manword | |
351 (let ((sections (cdr (car slist)))) | |
352 (if (not (listp sections)) | |
353 (concat sections " " manword) | |
354 (let ((manarg "")) | |
355 (while sections | |
356 (setq manarg (concat manarg " " (car sections) " " manword)) | |
357 (setq sections (cdr sections))) | |
358 manarg) | |
359 ))))) | |
360 | |
361 (defun Man-default-man-entry () | |
362 "Make a guess at a default manual entry. | |
363 This guess is based on the text surrounding the cursor, and the | |
364 default section number is selected from Man-auto-section-alist." | |
365 (let ((default-section nil) | |
366 default-title) | |
367 (save-excursion | |
368 | |
369 ;; Default man entry title is any word the cursor is on, | |
370 ;; or if cursor not on a word, then nearest preceding | |
371 ;; word. | |
372 (and (not (looking-at "[a-zA-Z_]")) | |
373 (skip-chars-backward "^a-zA-Z_")) | |
374 (skip-chars-backward "(a-zA-Z_0-9") | |
375 (and (looking-at "(") (forward-char 1)) | |
376 (setq default-title | |
377 (buffer-substring | |
378 (point) | |
379 (progn (skip-chars-forward "a-zA-Z0-9_") (point)))) | |
380 | |
381 ;; If looking at something like ioctl(2) or brc(1M), include | |
382 ;; section number in default-entry | |
383 (if (looking-at "[ \t]*([ \t]*[0-9][a-zA-Z]?[ \t]*)") | |
384 (progn (skip-chars-forward "^0-9") | |
385 (setq default-section | |
386 (buffer-substring | |
387 (point) | |
388 (progn | |
389 (skip-chars-forward "0-9a-zA-Z") | |
390 (point))))) | |
391 | |
392 ;; Otherwise, assume section number to be 2 if we're | |
393 ;; in C code | |
394 (and (eq major-mode 'c-mode) | |
395 (setq default-section "2"))) | |
396 (if default-section | |
397 (format "%s %s" default-section default-title) | |
398 default-title)))) | |
399 | |
400 | |
401 ;; ====================================================================== | |
402 ;; top level command and background process sentinel | |
403 | |
404 ;;;###autoload | |
405 (defun manual-entry (arg) | |
406 "Get a Un*x manual page and put it in a buffer. | |
407 This command is the top-level command in the man package. It runs a Un*x | |
408 command to retrieve and clean a manpage in the background and places the | |
409 results in a Man-mode (manpage browsing) buffer. See variable | |
410 Man-notify for what happens when the buffer is ready. | |
411 Universal argument ARG, is passed to Man-getpage-in-background." | |
412 (interactive "P") | |
413 (let* ((default-entry (Man-default-man-entry)) | |
414 (man-args | |
415 (read-string (format "Manual-entry: %s" | |
416 (if (string= default-entry "") "" | |
417 (format "(default: %s) " | |
418 default-entry)))))) | |
419 (and (string= man-args "") | |
420 (if (string= default-entry "") | |
421 (error "No man args given.") | |
422 (setq man-args default-entry))) | |
3644
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
423 ;; Recognize the subject(section) syntax. |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
424 (if (string-match "^[ \t]*\\([^( \t]+\\)[ \t]*(\\([^)]+\\))[ \t]*$" |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
425 man-args) |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
426 (setq man-args |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
427 (concat (substring man-args (match-beginning 2) (match-end 2)) |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
428 " " |
9e251319cdc8
* man.el (manual-entry): Recognize the subject(section) syntax.
Jim Blandy <jimb@redhat.com>
parents:
3619
diff
changeset
|
429 (substring man-args (match-beginning 1) (match-end 1))))) |
3235 | 430 (if Man-downcase-section-letters-p |
431 (setq man-args (Man-downcase man-args))) | |
432 (Man-getpage-in-background man-args (consp arg)) | |
433 )) | |
434 | |
435 (defun Man-getpage-in-background (man-args &optional override-reuse-p) | |
436 "Uses MAN-ARGS to build and fire off the manpage and cleaning command. | |
437 Optional OVERRIDE-REUSE-P, when supplied non-nil forces man to | |
438 start a background process even if a buffer already exists and | |
439 Man-reuse-okay-p is non-nil." | |
440 (let* ((bufname (concat "*man " man-args "*")) | |
441 (buffer (get-buffer bufname))) | |
442 (if (and Man-reuse-okay-p | |
443 (not override-reuse-p) | |
444 buffer) | |
445 (Man-notify-when-ready buffer) | |
446 (message "Invoking man %s in background..." man-args) | |
447 (setq buffer (generate-new-buffer bufname)) | |
3713
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
448 (let ((process-environment process-environment)) |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
449 ;; 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
|
450 (setenv "TERM" "dumb") |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
451 (set-process-sentinel |
c77a3da2d08d
(Man-getpage-in-background): Use TERM=dumb to prevent
Richard M. Stallman <rms@gnu.org>
parents:
3659
diff
changeset
|
452 (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
|
453 (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
|
454 'Man-bgproc-sentinel)) |
a1edd269b2f4
(Man-getpage-in-background): Move close paren.
Richard M. Stallman <rms@gnu.org>
parents:
3713
diff
changeset
|
455 ))) |
3235 | 456 |
457 (defun Man-notify-when-ready (man-buffer) | |
458 "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
|
459 See the variable `Man-notify' for the different notification behaviors." |
3235 | 460 (cond |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
461 ((eq Man-notify 'bully) |
3235 | 462 (pop-to-buffer man-buffer) |
463 (delete-other-windows)) | |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
464 ((eq Man-notify 'aggressive) |
3235 | 465 (pop-to-buffer man-buffer)) |
3307
1fc2bc44def7
(Man-notify-when-ready): Correct previous change.
Richard M. Stallman <rms@gnu.org>
parents:
3235
diff
changeset
|
466 ((eq Man-notify 'friendly) |
3235 | 467 (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
|
468 ((eq Man-notify 'polite) |
3235 | 469 (beep) |
470 (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
|
471 ((eq Man-notify 'quiet) |
3235 | 472 (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
|
473 ((or (eq Man-notify 'meek) |
3235 | 474 t) |
475 (message "")) | |
476 )) | |
477 | |
478 (defun Man-bgproc-sentinel (process msg) | |
479 "Manpage background process sentinel." | |
480 (let ((Man-buffer (process-buffer process)) | |
481 (delete-buff nil) | |
482 (err-mess nil)) | |
483 (if (null (buffer-name Man-buffer)) ;; deleted buffer | |
484 (set-process-buffer process nil) | |
485 (save-excursion | |
486 (set-buffer Man-buffer) | |
487 (goto-char (point-min)) | |
488 (cond ((or (looking-at "No \\(manual \\)*entry for") | |
489 (looking-at "[^\n]*: nothing appropriate$")) | |
490 (setq err-mess (buffer-substring (point) (Man-linepos 'eol)) | |
491 delete-buff t) | |
492 ) | |
493 ((not (and (eq (process-status process) 'exit) | |
494 (= (process-exit-status process) 0))) | |
495 (setq err-mess | |
496 (concat (buffer-name Man-buffer) | |
497 ": process " | |
498 (let ((eos (1- (length msg)))) | |
499 (if (= (aref msg eos) ?\n) | |
500 (substring msg 0 eos) msg)))) | |
501 (goto-char (point-max)) | |
502 (insert (format "\nprocess %s" msg)) | |
503 ))) | |
504 (if delete-buff | |
505 (kill-buffer Man-buffer) | |
506 (save-window-excursion | |
507 (save-excursion | |
508 (set-buffer Man-buffer) | |
509 (Man-mode) | |
510 (set-buffer-modified-p nil))) | |
511 (Man-notify-when-ready Man-buffer)) | |
512 | |
513 (if err-mess | |
514 (error err-mess)) | |
515 ))) | |
516 | |
517 | |
518 ;; ====================================================================== | |
519 ;; set up manual mode in buffer and build alists | |
520 | |
521 (defun Man-mode () | |
522 "SUPERMAN 1.1: A mode for browsing Un*x manual pages. | |
523 | |
524 The following man commands are available in the buffer. Try | |
525 \"\\[describe-key] <key> RET\" for more information: | |
526 | |
527 \\[manual-entry] Prompt to retrieve a new manpage. | |
528 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section. | |
529 \\[Man-next-manpage] Jump to next manpage in circular list. | |
530 \\[Man-previous-manpage] Jump to previous manpage in circular list. | |
531 \\[Man-next-section] Jump to next manpage section. | |
532 \\[Man-previous-section] Jump to previous manpage section. | |
533 \\[Man-goto-section] Go to a manpage section. | |
534 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section. | |
535 \\[Man-quit] Deletes the manpage, its buffer, and window. | |
536 \\[Man-version] Prints man's version number. | |
537 \\[describe-mode] Prints this help text. | |
538 | |
539 The following variables may be of some use. Try | |
540 \"\\[describe-variable] <variable-name> RET\" for more information: | |
541 | |
542 Man-notify What happens when manpage formatting is done. | |
543 Man-reuse-okay-p Okay to reuse already formatted buffer? | |
544 Man-downcase-section-letters-p Force section letters to lower case? | |
545 Man-circular-pages-p Multiple manpage list treated as circular? | |
546 Man-auto-section-alist List of major modes and their section numbers. | |
547 Man-section-translations-alist List of section numbers and their Un*x equiv. | |
548 Man-filter-list Background manpage filter command. | |
549 Man-mode-line-format Mode line format for Man-mode buffers. | |
550 Man-mode-map Keymap bindings for Man-mode buffers. | |
551 Man-mode-hooks Hooks for Man-mode. | |
552 Man-section-regexp Regexp describing manpage section letters. | |
553 Man-heading-regexp Regexp describing section headers. | |
554 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv). | |
555 Man-first-heading-regexp Regexp for first heading on a manpage. | |
556 Man-reference-regexp Regexp matching a references in SEE ALSO. | |
557 Man-version-number Superman version number. | |
558 | |
559 The following key bindings are currently in effect in the buffer: | |
560 \\{Man-mode-map}" | |
561 (interactive) | |
562 (setq major-mode 'Man-mode | |
563 mode-name "Manual" | |
564 buffer-auto-save-file-name nil | |
565 mode-line-format Man-mode-line-format | |
566 truncate-lines t | |
567 buffer-read-only t) | |
568 (buffer-disable-undo (current-buffer)) | |
569 (auto-fill-mode -1) | |
570 (use-local-map Man-mode-map) | |
571 (goto-char (point-min)) | |
572 (Man-build-page-list) | |
3619
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
573 (Man-goto-page 1) |
062dbb10173d
(Man-mode): Run Man-mode-hook.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
574 (run-hooks 'Man-mode-hook)) |
3235 | 575 |
576 (defun Man-build-section-alist () | |
577 "Build the association list of manpage sections." | |
578 (setq Man-sections-alist nil) | |
579 (goto-char (point-min)) | |
580 (while (re-search-forward Man-heading-regexp (point-max) t) | |
581 (aput 'Man-sections-alist | |
582 (buffer-substring (Man-linepos 'bol) (Man-linepos))) | |
583 (forward-line 1) | |
584 )) | |
585 | |
586 (defun Man-build-references-alist () | |
587 "Build the association list of references (in the SEE ALSO section)." | |
588 (setq Man-refpages-alist nil) | |
589 (save-excursion | |
590 (if (Man-find-section Man-see-also-regexp) | |
591 (let ((start (progn (forward-line 1) (point))) | |
592 (end (progn | |
593 (Man-next-section 1) | |
594 (point))) | |
595 hyphenated | |
596 (runningpoint -1)) | |
597 (narrow-to-region start end) | |
598 (goto-char (point-min)) | |
599 (back-to-indentation) | |
600 (while (and (not (eobp)) (/= (point) runningpoint)) | |
601 (setq runningpoint (point)) | |
602 (let* ((bow (point)) | |
603 (eow (re-search-forward Man-reference-regexp end t)) | |
604 (word (buffer-substring bow (match-end 0))) | |
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)) | |
664 (if (re-search-forward (concat "^" section) (point-max) t) | |
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. | |
687 Actually the section moved to is described by Man-see-also-regexp." | |
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. | |
695 Queries you for the page to retrieve. Of course it does this in the | |
696 background. Universal argument ARG is passed to Man-getpage-in-background." | |
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.")))) | |
769 | |
770 (defun Man-version (arg) | |
771 "Show man's version. | |
772 Universal argument (\\[universal-argument]) ARG inserts version | |
773 information in the current buffer instead of printing the message in | |
774 the echo area." | |
775 (interactive "P") | |
776 (if (consp arg) | |
777 (insert "Using Superman version " Man-version-number ".") | |
778 (message "Using Superman version %s." Man-version-number))) | |
779 | |
780 ;;; man.el ends here |