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