0
|
1 ;;; man.el --- browse UNIX manual pages
|
4
|
2
|
|
3 ;; Copyright (C) 1993, 1994, 1996 Free Software Foundation, Inc.
|
0
|
4
|
4
|
5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com>
|
|
6 ;; Keywords: help
|
|
7 ;; Adapted-By: ESR, pot
|
|
8
|
0
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
4
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
0
|
25
|
4
|
26 ;;; Synched up with: FSF 19.34.
|
0
|
27
|
4
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This code provides a function, `man', with which you can browse
|
|
31 ;; UNIX manual pages. Formatting is done in background so that you
|
|
32 ;; can continue to use your Emacs while processing is going on.
|
0
|
33 ;;
|
4
|
34 ;; The mode also supports hypertext-like following of manual page SEE
|
|
35 ;; ALSO references, and other features. See below or do `?' in a
|
|
36 ;; manual page buffer for details.
|
|
37
|
|
38 ;; ========== Credits and History ==========
|
|
39 ;; In mid 1991, several people posted some interesting improvements to
|
|
40 ;; man.el from the standard emacs 18.57 distribution. I liked many of
|
|
41 ;; these, but wanted everything in one single package, so I decided
|
|
42 ;; to incorporate them into a single manual browsing mode. While
|
|
43 ;; much of the code here has been rewritten, and some features added,
|
|
44 ;; these folks deserve lots of credit for providing the initial
|
|
45 ;; excellent packages on which this one is based.
|
|
46
|
|
47 ;; Nick Duffek <duffek@chaos.cs.brandeis.edu>, posted a very nice
|
|
48 ;; improvement which retrieved and cleaned the manpages in a
|
|
49 ;; background process, and which correctly deciphered such options as
|
|
50 ;; man -k.
|
|
51
|
|
52 ;; Eric Rose <erose@jessica.stanford.edu>, submitted manual.el which
|
|
53 ;; provided a very nice manual browsing mode.
|
|
54
|
|
55 ;; This package was available as `superman.el' from the LCD package
|
|
56 ;; for some time before it was accepted into Emacs 19. The entry
|
|
57 ;; point and some other names have been changed to make it a drop-in
|
|
58 ;; replacement for the old man.el package.
|
|
59
|
|
60 ;; Francesco Potorti` <pot@cnuce.cnr.it> cleaned it up thoroughly,
|
|
61 ;; making it faster, more robust and more tolerant of different
|
|
62 ;; systems' man idiosyncrasies.
|
|
63
|
|
64 ;; ========== Features ==========
|
|
65 ;; + Runs "man" in the background and pipes the results through a
|
|
66 ;; series of sed and awk scripts so that all retrieving and cleaning
|
|
67 ;; is done in the background. The cleaning commands are configurable.
|
|
68 ;; + Syntax is the same as Un*x man
|
|
69 ;; + Functionality is the same as Un*x man, including "man -k" and
|
|
70 ;; "man <section>", etc.
|
|
71 ;; + Provides a manual browsing mode with keybindings for traversing
|
|
72 ;; the sections of a manpage, following references in the SEE ALSO
|
|
73 ;; section, and more.
|
|
74 ;; + Multiple manpages created with the same man command are put into
|
|
75 ;; a narrowed buffer circular list.
|
0
|
76
|
4
|
77 ;; ============= TODO ===========
|
|
78 ;; - Add a command for printing.
|
|
79 ;; - The awk script deletes multiple blank lines. This behaviour does
|
|
80 ;; not allow to understand if there was indeed a blank line at the
|
|
81 ;; end or beginning of a page (after the header, or before the
|
|
82 ;; footer). A different algorithm should be used. It is easy to
|
|
83 ;; compute how many blank lines there are before and after the page
|
|
84 ;; headers, and after the page footer. But it is possible to compute
|
|
85 ;; the number of blank lines before the page footer by euristhics
|
|
86 ;; only. Is it worth doing?
|
|
87 ;; - Allow a user option to mean that all the manpages should go in
|
|
88 ;; the same buffer, where they can be browsed with M-n and M-p.
|
|
89 ;; - Allow completion on the manpage name when calling man. This
|
|
90 ;; requires a reliable list of places where manpages can be found. The
|
|
91 ;; drawback would be that if the list is not complete, the user might
|
|
92 ;; be led to believe that the manpages in the missing directories do
|
|
93 ;; not exist.
|
0
|
94
|
4
|
95
|
|
96 ;;; Code:
|
|
97
|
|
98 (require 'assoc)
|
|
99
|
|
100 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
101 ;; empty defvars (keep the compiler quiet)
|
0
|
102
|
4
|
103 (defvar Man-notify)
|
|
104 (defvar Man-current-page)
|
|
105 (defvar Man-page-list)
|
|
106 (defvar Man-filter-list nil
|
|
107 "*Manpage cleaning filter command phrases.
|
|
108 This variable contains a list of the following form:
|
|
109
|
|
110 '((command-string phrase-string*)*)
|
|
111
|
|
112 Each phrase-string is concatenated onto the command-string to form a
|
|
113 command filter. The (standard) output (and standard error) of the Un*x
|
|
114 man command is piped through each command filter in the order the
|
|
115 commands appear in the association list. The final output is placed in
|
|
116 the manpage buffer.")
|
0
|
117
|
4
|
118 (defvar Man-original-frame)
|
|
119 (defvar Man-arguments)
|
|
120 (defvar Man-sections-alist)
|
|
121 (defvar Man-refpages-alist)
|
|
122 (defvar Man-uses-untabify-flag t
|
|
123 "When non-nil use `untabify' instead of Man-untabify-command.")
|
|
124 (defvar Man-page-mode-string)
|
|
125 (defvar Man-sed-script nil
|
|
126 "Script for sed to nuke backspaces and ANSI codes from manpages.")
|
|
127
|
|
128 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
129 ;; user variables
|
|
130
|
|
131 (defvar Man-fontify-manpage-flag t
|
|
132 "*Make up the manpage with fonts.")
|
|
133
|
|
134 (defvar Man-overstrike-face 'bold
|
|
135 "*Face to use when fontifying overstrike.")
|
0
|
136
|
4
|
137 (defvar Man-underline-face 'underline
|
|
138 "*Face to use when fontifying underlining.")
|
|
139
|
|
140 ;; Use the value of the obsolete user option Man-notify, if set.
|
|
141 (defvar Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
|
|
142 "*Selects the behavior when manpage is ready.
|
|
143 This variable may have one of the following values, where (sf) means
|
|
144 that the frames are switched, so the manpage is displayed in the frame
|
|
145 where the man command was called from:
|
0
|
146
|
4
|
147 newframe -- put the manpage in its own frame (see `Man-frame-parameters')
|
|
148 pushy -- make the manpage the current buffer in the current window
|
|
149 bully -- make the manpage the current buffer and only window (sf)
|
|
150 aggressive -- make the manpage the current buffer in the other window (sf)
|
|
151 friendly -- display manpage in the other window but don't make current (sf)
|
|
152 polite -- don't display manpage, but prints message and beep when ready
|
|
153 quiet -- like `polite', but don't beep
|
|
154 meek -- make no indication that the manpage is ready
|
|
155
|
|
156 Any other value of `Man-notify-method' is equivalent to `meek'.")
|
|
157
|
|
158 (defvar Man-frame-parameters nil
|
|
159 "*Frame parameter list for creating a new frame for a manual page.")
|
0
|
160
|
4
|
161 (defvar Man-downcase-section-letters-flag t
|
|
162 "*Letters in sections are converted to lower case.
|
|
163 Some Un*x man commands can't handle uppercase letters in sections, for
|
|
164 example \"man 2V chmod\", but they are often displayed in the manpage
|
|
165 with the upper case letter. When this variable is t, the section
|
|
166 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before
|
|
167 being sent to the man background process.")
|
0
|
168
|
4
|
169 (defvar Man-circular-pages-flag t
|
|
170 "*If t, the manpage list is treated as circular for traversal.")
|
0
|
171
|
4
|
172 (defvar Man-section-translations-alist
|
|
173 (list
|
|
174 '("3C++" . "3")
|
|
175 ;; Some systems have a real 3x man section, so let's comment this.
|
|
176 ;; '("3X" . "3") ; Xlib man pages
|
|
177 '("3X11" . "3")
|
|
178 '("1-UCB" . ""))
|
|
179 "*Association list of bogus sections to real section numbers.
|
|
180 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
|
|
181 their references which Un*x `man' does not recognize. This
|
|
182 association list is used to translate those sections, when found, to
|
|
183 the associated section number.")
|
0
|
184
|
4
|
185 (defvar manual-program "man"
|
|
186 "The name of the program that produces man pages.")
|
0
|
187
|
4
|
188 (defvar Man-untabify-command "pr"
|
|
189 "Command used for untabifying.")
|
0
|
190
|
4
|
191 (defvar Man-untabify-command-args (list "-t" "-e")
|
|
192 "List of arguments to be passed to Man-untabify-command (which see).")
|
0
|
193
|
4
|
194 (defvar Man-sed-command "sed"
|
|
195 "Command used for processing sed scripts.")
|
0
|
196
|
4
|
197 (defvar Man-awk-command "awk"
|
|
198 "Command used for processing awk scripts.")
|
0
|
199
|
4
|
200 (defvar Man-mode-line-format
|
|
201 '("" mode-line-modified
|
|
202 mode-line-buffer-identification " "
|
|
203 global-mode-string
|
|
204 " " Man-page-mode-string
|
|
205 " %[(" mode-name mode-line-process minor-mode-alist ")%]----"
|
|
206 (-3 . "%p") "-%-")
|
|
207 "Mode line format for manual mode buffer.")
|
0
|
208
|
4
|
209 (defvar Man-mode-map nil
|
|
210 "Keymap for Man mode.")
|
|
211
|
|
212 (defvar Man-mode-hook nil
|
|
213 "Hook run when Man mode is enabled.")
|
0
|
214
|
4
|
215 (defvar Man-cooked-hook nil
|
|
216 "Hook run after removing backspaces but before Man-mode processing.")
|
|
217
|
|
218 (defvar Man-name-regexp "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*"
|
|
219 "Regular expression describing the name of a manpage (without section).")
|
0
|
220
|
4
|
221 (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]"
|
|
222 "Regular expression describing a manpage section within parentheses.")
|
0
|
223
|
4
|
224 (defvar Man-page-header-regexp
|
|
225 (concat "^[ \t]*\\(" Man-name-regexp
|
|
226 "(\\(" Man-section-regexp "\\))\\).*\\1")
|
|
227 "Regular expression describing the heading of a page.")
|
0
|
228
|
4
|
229 (defvar Man-heading-regexp "^\\([A-Z][A-Z ]+\\)$"
|
|
230 "Regular expression describing a manpage heading entry.")
|
|
231
|
|
232 (defvar Man-see-also-regexp "SEE ALSO"
|
|
233 "Regular expression for SEE ALSO heading (or your equivalent).
|
|
234 This regexp should not start with a `^' character.")
|
0
|
235
|
4
|
236 (defvar Man-first-heading-regexp "^[ \t]*NAME$\\|^[ \t]*No manual entry fo.*$"
|
|
237 "Regular expression describing first heading on a manpage.
|
|
238 This regular expression should start with a `^' character.")
|
|
239
|
|
240 (defvar Man-reference-regexp
|
|
241 (concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))")
|
|
242 "Regular expression describing a reference in the SEE ALSO section.")
|
0
|
243
|
4
|
244 (defvar Man-switches ""
|
|
245 "Switches passed to the man command, as a single string.")
|
0
|
246
|
4
|
247 (defvar Man-specified-section-option
|
|
248 (if (string-match "-solaris[0-9.]*$" system-configuration)
|
|
249 "-s"
|
|
250 "")
|
|
251 "Option that indicates a specified a manual section name.")
|
0
|
252
|
4
|
253 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
254 ;; end user variables
|
|
255
|
|
256 ;; other variables and keymap initializations
|
|
257 (make-variable-buffer-local 'Man-sections-alist)
|
|
258 (make-variable-buffer-local 'Man-refpages-alist)
|
|
259 (make-variable-buffer-local 'Man-page-list)
|
|
260 (make-variable-buffer-local 'Man-current-page)
|
|
261 (make-variable-buffer-local 'Man-page-mode-string)
|
|
262 (make-variable-buffer-local 'Man-original-frame)
|
|
263 (make-variable-buffer-local 'Man-arguments)
|
0
|
264
|
4
|
265 (setq-default Man-sections-alist nil)
|
|
266 (setq-default Man-refpages-alist nil)
|
|
267 (setq-default Man-page-list nil)
|
|
268 (setq-default Man-current-page 0)
|
|
269 (setq-default Man-page-mode-string "1 of 1")
|
0
|
270
|
4
|
271 (defconst Man-sysv-sed-script "\
|
|
272 /\b/ { s/_\b//g
|
|
273 s/\b_//g
|
|
274 s/o\b+/o/g
|
|
275 s/+\bo/o/g
|
|
276 :ovstrk
|
|
277 s/\\(.\\)\b\\1/\\1/g
|
|
278 t ovstrk
|
|
279 }
|
|
280 /\e\\[[0-9][0-9]*m/ s///g"
|
|
281 "Script for sysV-like sed to nuke backspaces and ANSI codes from manpages.")
|
0
|
282
|
4
|
283 (defconst Man-berkeley-sed-script "\
|
|
284 /\b/ { s/_\b//g\\
|
|
285 s/\b_//g\\
|
|
286 s/o\b+/o/g\\
|
|
287 s/+\bo/o/g\\
|
|
288 :ovstrk\\
|
|
289 s/\\(.\\)\b\\1/\\1/g\\
|
|
290 t ovstrk\\
|
|
291 }\\
|
|
292 /\e\\[[0-9][0-9]*m/ s///g"
|
|
293 "Script for berkeley-like sed to nuke backspaces and ANSI codes from manpages.")
|
0
|
294
|
4
|
295 (if Man-mode-map
|
|
296 nil
|
|
297 (setq Man-mode-map (make-keymap))
|
|
298 (suppress-keymap Man-mode-map)
|
|
299 (define-key Man-mode-map " " 'scroll-up)
|
|
300 (define-key Man-mode-map "\177" 'scroll-down)
|
|
301 (define-key Man-mode-map "n" 'Man-next-section)
|
|
302 (define-key Man-mode-map "p" 'Man-previous-section)
|
|
303 (define-key Man-mode-map "\en" 'Man-next-manpage)
|
|
304 (define-key Man-mode-map "\ep" 'Man-previous-manpage)
|
|
305 (define-key Man-mode-map ">" 'end-of-buffer)
|
|
306 (define-key Man-mode-map "<" 'beginning-of-buffer)
|
|
307 (define-key Man-mode-map "." 'beginning-of-buffer)
|
|
308 (define-key Man-mode-map "r" 'Man-follow-manual-reference)
|
|
309 (define-key Man-mode-map "g" 'Man-goto-section)
|
|
310 (define-key Man-mode-map "s" 'Man-goto-see-also-section)
|
|
311 (define-key Man-mode-map "k" 'Man-kill)
|
|
312 (define-key Man-mode-map "q" 'Man-quit)
|
|
313 (define-key Man-mode-map "m" 'man)
|
|
314 (define-key Man-mode-map "?" 'describe-mode)
|
|
315 )
|
0
|
316
|
4
|
317
|
|
318 ;; ======================================================================
|
|
319 ;; utilities
|
|
320
|
|
321 (defun Man-init-defvars ()
|
|
322 "Used for initialising variables based on the value of window-system.
|
|
323 This is necessary if one wants to dump man.el with emacs."
|
0
|
324
|
4
|
325 ;; The following is necessary until fonts are implemented on
|
|
326 ;; terminals.
|
|
327 (setq Man-fontify-manpage-flag (and Man-fontify-manpage-flag
|
|
328 window-system))
|
0
|
329
|
4
|
330 (setq Man-sed-script
|
|
331 (cond
|
|
332 (Man-fontify-manpage-flag
|
|
333 nil)
|
|
334 ((= 0 (call-process Man-sed-command nil nil nil Man-sysv-sed-script))
|
|
335 Man-sysv-sed-script)
|
|
336 ((= 0 (call-process Man-sed-command nil nil nil Man-berkeley-sed-script))
|
|
337 Man-berkeley-sed-script)
|
|
338 (t
|
|
339 nil)))
|
0
|
340
|
4
|
341 (setq Man-filter-list
|
|
342 (list
|
|
343 (cons
|
|
344 Man-sed-command
|
|
345 (list
|
|
346 (if Man-sed-script
|
|
347 (concat "-e '" Man-sed-script "'")
|
|
348 "")
|
|
349 "-e '/^[\001-\032][\001-\032]*$/d'"
|
|
350 "-e '/\e[789]/s///g'"
|
|
351 "-e '/Reformatting page. Wait/d'"
|
|
352 "-e '/Reformatting entry. Wait/d'"
|
|
353 "-e '/^[ \t]*Hewlett-Packard[ \t]Company[ \t]*-[ \t][0-9]*[ \t]-/d'"
|
|
354 "-e '/^[ \t]*Hewlett-Packard[ \t]*-[ \t][0-9]*[ \t]-.*$/d'"
|
|
355 "-e '/^[ \t][ \t]*-[ \t][0-9]*[ \t]-[ \t]*Formatted:.*[0-9]$/d'"
|
|
356 "-e '/^[ \t]*Page[ \t][0-9]*.*(printed[ \t][0-9\\/]*)$/d'"
|
|
357 "-e '/^Printed[ \t][0-9].*[0-9]$/d'"
|
|
358 "-e '/^[ \t]*X[ \t]Version[ \t]1[01].*Release[ \t][0-9]/d'"
|
|
359 "-e '/^[A-za-z].*Last[ \t]change:/d'"
|
|
360 "-e '/^Sun[ \t]Release[ \t][0-9].*[0-9]$/d'"
|
|
361 "-e '/[ \t]*Copyright [0-9]* UNIX System Laboratories, Inc.$/d'"
|
|
362 "-e '/^[ \t]*Rev\\..*Page [0-9][0-9]*$/d'"
|
|
363 ))
|
|
364 (cons
|
|
365 Man-awk-command
|
|
366 (list
|
|
367 "'\n"
|
|
368 "BEGIN { blankline=0; anonblank=0; }\n"
|
|
369 "/^$/ { if (anonblank==0) next; }\n"
|
|
370 "{ anonblank=1; }\n"
|
|
371 "/^$/ { blankline++; next; }\n"
|
|
372 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n"
|
|
373 "'"
|
|
374 ))
|
|
375 (if (not Man-uses-untabify-flag)
|
|
376 (cons
|
|
377 Man-untabify-command
|
|
378 Man-untabify-command-args)
|
|
379 )))
|
|
380 )
|
|
381
|
|
382 (defsubst Man-match-substring (&optional n string)
|
|
383 "Return the substring matched by the last search.
|
|
384 Optional arg N means return the substring matched by the Nth paren
|
|
385 grouping. Optional second arg STRING means return a substring from
|
|
386 that string instead of from the current buffer."
|
|
387 (if (null n) (setq n 0))
|
|
388 (if string
|
|
389 (substring string (match-beginning n) (match-end n))
|
|
390 (buffer-substring (match-beginning n) (match-end n))))
|
|
391
|
|
392 (defsubst Man-make-page-mode-string ()
|
|
393 "Formats part of the mode line for Man mode."
|
|
394 (format "%s page %d of %d"
|
|
395 (or (nth 2 (nth (1- Man-current-page) Man-page-list))
|
|
396 "")
|
|
397 Man-current-page
|
|
398 (length Man-page-list)))
|
|
399
|
|
400 (defsubst Man-build-man-command ()
|
|
401 "Builds the entire background manpage and cleaning command."
|
|
402 (let ((command (concat manual-program " " Man-switches " %s 2>/dev/null"))
|
|
403 (flist Man-filter-list))
|
|
404 (while (and flist (car flist))
|
|
405 (let ((pcom (car (car flist)))
|
|
406 (pargs (cdr (car flist))))
|
|
407 (setq command
|
|
408 (concat command " | " pcom " "
|
|
409 (mapconcat '(lambda (phrase)
|
|
410 (if (not (stringp phrase))
|
|
411 (error "Malformed Man-filter-list"))
|
|
412 phrase)
|
|
413 pargs " ")))
|
|
414 (setq flist (cdr flist))))
|
|
415 command))
|
0
|
416
|
4
|
417 (defun Man-translate-references (ref)
|
|
418 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style.
|
|
419 Leave it as is if already in that style. Possibly downcase and
|
|
420 translate the section (see the Man-downcase-section-letters-flag
|
|
421 and the Man-section-translations-alist variables)."
|
|
422 (let ((name "")
|
|
423 (section "")
|
|
424 (slist Man-section-translations-alist))
|
|
425 (cond
|
|
426 ;; "chmod(2V)" case ?
|
|
427 ((string-match (concat "^" Man-reference-regexp "$") ref)
|
|
428 (setq name (Man-match-substring 1 ref)
|
|
429 section (Man-match-substring 2 ref)))
|
|
430 ;; "2v chmod" case ?
|
|
431 ((string-match (concat "^\\(" Man-section-regexp
|
|
432 "\\) +\\(" Man-name-regexp "\\)$") ref)
|
|
433 (setq name (Man-match-substring 2 ref)
|
|
434 section (Man-match-substring 1 ref))))
|
|
435 (if (string= name "")
|
|
436 ref ; Return the reference as is
|
|
437 (if Man-downcase-section-letters-flag
|
|
438 (setq section (downcase section)))
|
|
439 (while slist
|
|
440 (let ((s1 (car (car slist)))
|
|
441 (s2 (cdr (car slist))))
|
|
442 (setq slist (cdr slist))
|
|
443 (if Man-downcase-section-letters-flag
|
|
444 (setq s1 (downcase s1)))
|
|
445 (if (not (string= s1 section)) nil
|
|
446 (setq section (if Man-downcase-section-letters-flag
|
|
447 (downcase s2)
|
|
448 s2)
|
|
449 slist nil))))
|
|
450 (concat Man-specified-section-option section " " name))))
|
0
|
451
|
4
|
452
|
|
453 ;; ======================================================================
|
|
454 ;; default man entry: get word under point
|
|
455
|
|
456 (defsubst Man-default-man-entry ()
|
|
457 "Make a guess at a default manual entry.
|
|
458 This guess is based on the text surrounding the cursor, and the
|
|
459 default section number is selected from `Man-auto-section-alist'."
|
|
460 (let (default-title)
|
|
461 (save-excursion
|
|
462
|
|
463 ;; Default man entry title is any word the cursor is on, or if
|
|
464 ;; cursor not on a word, then nearest preceding word. Cannot
|
|
465 ;; use the current-word function because it skips the dots.
|
|
466 (if (not (looking-at "[-a-zA-Z_.]"))
|
|
467 (skip-chars-backward "^a-zA-Z"))
|
|
468 (skip-chars-backward "-(a-zA-Z_0-9_.")
|
|
469 (if (looking-at "(") (forward-char 1))
|
|
470 (setq default-title
|
|
471 (buffer-substring
|
|
472 (point)
|
|
473 (progn (skip-chars-forward "-a-zA-Z0-9_.") (point))))
|
|
474
|
|
475 ;; If looking at something like ioctl(2) or brc(1M), include the
|
|
476 ;; section number in the returned value. Remove text properties.
|
|
477 (let ((result (concat
|
|
478 default-title
|
|
479 (if (looking-at
|
|
480 (concat "[ \t]*([ \t]*\\("
|
|
481 Man-section-regexp "\\)[ \t]*)"))
|
|
482 (format "(%s)" (Man-match-substring 1))))))
|
|
483 (set-text-properties 0 (length result) nil result)
|
|
484 result))))
|
|
485
|
|
486
|
|
487 ;; ======================================================================
|
|
488 ;; Top level command and background process sentinel
|
|
489
|
|
490 ;; For compatibility with older versions.
|
|
491 ;;;###autoload
|
|
492 (defalias 'manual-entry 'man)
|
0
|
493
|
|
494 ;;;###autoload
|
4
|
495 (defun man (man-args)
|
|
496 "Get a Un*x manual page and put it in a buffer.
|
|
497 This command is the top-level command in the man package. It runs a Un*x
|
|
498 command to retrieve and clean a manpage in the background and places the
|
|
499 results in a Man mode (manpage browsing) buffer. See variable
|
|
500 `Man-notify-method' for what happens when the buffer is ready.
|
|
501 If a buffer already exists for this man page, it will display immediately."
|
0
|
502 (interactive
|
4
|
503 (list (let* ((default-entry (Man-default-man-entry))
|
|
504 (input (read-string
|
|
505 (format "Manual entry%s: "
|
|
506 (if (string= default-entry "")
|
|
507 ""
|
|
508 (format " (default %s)" default-entry))))))
|
|
509 (if (string= input "")
|
|
510 (if (string= default-entry "")
|
|
511 (error "No man args given")
|
|
512 default-entry)
|
|
513 input))))
|
0
|
514
|
4
|
515 ;; Possibly translate the "subject(section)" syntax into the
|
|
516 ;; "section subject" syntax and possibly downcase the section.
|
|
517 (setq man-args (Man-translate-references man-args))
|
0
|
518
|
4
|
519 (Man-getpage-in-background man-args))
|
0
|
520
|
|
521
|
4
|
522 (defun Man-getpage-in-background (topic)
|
|
523 "Uses TOPIC to build and fire off the manpage and cleaning command."
|
|
524 (let* ((man-args topic)
|
|
525 (bufname (concat "*Man " man-args "*"))
|
|
526 (buffer (get-buffer bufname)))
|
|
527 (if buffer
|
|
528 (Man-notify-when-ready buffer)
|
|
529 (require 'env)
|
|
530 (message "Invoking %s %s in the background" manual-program man-args)
|
|
531 (setq buffer (generate-new-buffer bufname))
|
|
532 (save-excursion
|
|
533 (set-buffer buffer)
|
|
534 (setq Man-original-frame (selected-frame))
|
|
535 (setq Man-arguments man-args))
|
|
536 (let ((process-environment (copy-sequence process-environment)))
|
|
537 ;; Prevent any attempt to use display terminal fanciness.
|
|
538 (setenv "TERM" "dumb")
|
|
539 (set-process-sentinel
|
|
540 (start-process manual-program buffer "sh" "-c"
|
|
541 (format (Man-build-man-command) man-args))
|
|
542 'Man-bgproc-sentinel)))))
|
0
|
543
|
4
|
544 (defun Man-notify-when-ready (man-buffer)
|
|
545 "Notify the user when MAN-BUFFER is ready.
|
|
546 See the variable `Man-notify-method' for the different notification behaviors."
|
|
547 (let ((saved-frame (save-excursion
|
|
548 (set-buffer man-buffer)
|
|
549 Man-original-frame)))
|
|
550 (cond
|
|
551 ((eq Man-notify-method 'newframe)
|
|
552 ;; Since we run asynchronously, perhaps while Emacs is waiting
|
|
553 ;; for input, we must not leave a different buffer current. We
|
|
554 ;; can't rely on the editor command loop to reselect the
|
|
555 ;; selected window's buffer.
|
|
556 (save-excursion
|
|
557 (set-buffer man-buffer)
|
|
558 (make-frame Man-frame-parameters)))
|
|
559 ((eq Man-notify-method 'pushy)
|
|
560 (switch-to-buffer man-buffer))
|
|
561 ((eq Man-notify-method 'bully)
|
|
562 (and window-system
|
|
563 (frame-live-p saved-frame)
|
|
564 (select-frame saved-frame))
|
|
565 (pop-to-buffer man-buffer)
|
|
566 (delete-other-windows))
|
|
567 ((eq Man-notify-method 'aggressive)
|
|
568 (and window-system
|
|
569 (frame-live-p saved-frame)
|
|
570 (select-frame saved-frame))
|
|
571 (pop-to-buffer man-buffer))
|
|
572 ((eq Man-notify-method 'friendly)
|
|
573 (and window-system
|
|
574 (frame-live-p saved-frame)
|
|
575 (select-frame saved-frame))
|
|
576 (display-buffer man-buffer 'not-this-window))
|
|
577 ((eq Man-notify-method 'polite)
|
|
578 (beep)
|
|
579 (message "Manual buffer %s is ready" (buffer-name man-buffer)))
|
|
580 ((eq Man-notify-method 'quiet)
|
|
581 (message "Manual buffer %s is ready" (buffer-name man-buffer)))
|
|
582 ((or (eq Man-notify-method 'meek)
|
|
583 t)
|
|
584 (message ""))
|
|
585 )))
|
0
|
586
|
4
|
587 (defun Man-fontify-manpage ()
|
|
588 "Convert overstriking and underlining to the correct fonts.
|
|
589 Same for the ANSI bold and normal escape sequences."
|
0
|
590 (interactive)
|
4
|
591 (message "Please wait: making up the %s man page..." Man-arguments)
|
|
592 (goto-char (point-min))
|
|
593 (while (search-forward "\e[1m" nil t)
|
|
594 (delete-backward-char 4)
|
|
595 (put-text-property (point)
|
|
596 (progn (if (search-forward "\e[0m" nil 'move)
|
|
597 (delete-backward-char 4))
|
|
598 (point))
|
|
599 'face Man-overstrike-face))
|
|
600 (goto-char (point-min))
|
|
601 (while (search-forward "_\b" nil t)
|
|
602 (backward-delete-char 2)
|
|
603 (put-text-property (point) (1+ (point)) 'face Man-underline-face))
|
|
604 (goto-char (point-min))
|
|
605 (while (search-forward "\b_" nil t)
|
|
606 (backward-delete-char 2)
|
|
607 (put-text-property (1- (point)) (point) 'face Man-underline-face))
|
|
608 (goto-char (point-min))
|
|
609 (while (re-search-forward "\\(.\\)\\(\b\\1\\)+" nil t)
|
|
610 (replace-match "\\1")
|
|
611 (put-text-property (1- (point)) (point) 'face Man-overstrike-face))
|
|
612 (goto-char (point-min))
|
|
613 (while (re-search-forward "o\b\\+\\|\\+\bo" nil t)
|
|
614 (replace-match "o")
|
|
615 (put-text-property (1- (point)) (point) 'face 'bold))
|
|
616 (goto-char (point-min))
|
|
617 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t)
|
|
618 (replace-match "+")
|
|
619 (put-text-property (1- (point)) (point) 'face 'bold))
|
|
620 ;; \255 is some kind of dash in Latin-1.
|
|
621 (goto-char (point-min))
|
|
622 (while (search-forward "\255" nil t) (replace-match "-"))
|
|
623 (message "%s man page made up" Man-arguments))
|
0
|
624
|
4
|
625 (defun Man-cleanup-manpage ()
|
|
626 "Remove overstriking and underlining from the current buffer."
|
|
627 (interactive)
|
|
628 (message "Please wait: cleaning up the %s man page..."
|
|
629 Man-arguments)
|
|
630 (if (or (interactive-p) (not Man-sed-script))
|
|
631 (progn
|
|
632 (goto-char (point-min))
|
|
633 (while (search-forward "_\b" nil t) (backward-delete-char 2))
|
|
634 (goto-char (point-min))
|
|
635 (while (search-forward "\b_" nil t) (backward-delete-char 2))
|
|
636 (goto-char (point-min))
|
|
637 (while (re-search-forward "\\(.\\)\\(\b\\1\\)+" nil t)
|
|
638 (replace-match "\\1"))
|
|
639 (goto-char (point-min))
|
|
640 (while (re-search-forward "\e\\[[0-9]+m" nil t) (replace-match ""))
|
|
641 (goto-char (point-min))
|
|
642 (while (re-search-forward "o\b\\+\\|\\+\bo" nil t) (replace-match "o"))
|
|
643 ))
|
|
644 (goto-char (point-min))
|
|
645 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) (replace-match "+"))
|
|
646 ;; \255 is some kind of dash in Latin-1.
|
|
647 (goto-char (point-min))
|
|
648 (while (search-forward "\255" nil t) (replace-match "-"))
|
|
649 (message "%s man page cleaned up" Man-arguments))
|
|
650
|
|
651 (defun Man-bgproc-sentinel (process msg)
|
|
652 "Manpage background process sentinel."
|
|
653 (let ((Man-buffer (process-buffer process))
|
|
654 (delete-buff nil)
|
|
655 (err-mess nil))
|
|
656
|
|
657 (if (null (buffer-name Man-buffer)) ;; deleted buffer
|
|
658 (set-process-buffer process nil)
|
0
|
659
|
4
|
660 (save-excursion
|
|
661 (set-buffer Man-buffer)
|
|
662 (let ((case-fold-search nil))
|
|
663 (goto-char (point-min))
|
|
664 (cond ((or (looking-at "No \\(manual \\)*entry for")
|
|
665 (looking-at "[^\n]*: nothing appropriate$"))
|
|
666 (setq err-mess (buffer-substring (point)
|
|
667 (progn
|
|
668 (end-of-line) (point)))
|
|
669 delete-buff t))
|
|
670 ((not (and (eq (process-status process) 'exit)
|
|
671 (= (process-exit-status process) 0)))
|
|
672 (setq err-mess
|
|
673 (concat (buffer-name Man-buffer)
|
|
674 ": process "
|
|
675 (let ((eos (1- (length msg))))
|
|
676 (if (= (aref msg eos) ?\n)
|
|
677 (substring msg 0 eos) msg))))
|
|
678 (goto-char (point-max))
|
|
679 (insert (format "\nprocess %s" msg))
|
|
680 ))
|
|
681 (if delete-buff
|
|
682 (kill-buffer Man-buffer)
|
|
683 (if Man-fontify-manpage-flag
|
|
684 (Man-fontify-manpage)
|
|
685 (Man-cleanup-manpage))
|
|
686 (run-hooks 'Man-cooked-hook)
|
|
687 (Man-mode)
|
|
688 (set-buffer-modified-p nil)
|
|
689 ))
|
|
690 ;; Restore case-fold-search before calling
|
|
691 ;; Man-notify-when-ready because it may switch buffers.
|
0
|
692
|
4
|
693 (if (not delete-buff)
|
|
694 (Man-notify-when-ready Man-buffer))
|
0
|
695
|
4
|
696 (if err-mess
|
|
697 (error err-mess))
|
|
698 ))))
|
|
699
|
|
700
|
|
701 ;; ======================================================================
|
|
702 ;; set up manual mode in buffer and build alists
|
|
703
|
|
704 (defun Man-mode ()
|
|
705 "A mode for browsing Un*x manual pages.
|
|
706
|
|
707 The following man commands are available in the buffer. Try
|
|
708 \"\\[describe-key] <key> RET\" for more information:
|
|
709
|
|
710 \\[man] Prompt to retrieve a new manpage.
|
|
711 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section.
|
|
712 \\[Man-next-manpage] Jump to next manpage in circular list.
|
|
713 \\[Man-previous-manpage] Jump to previous manpage in circular list.
|
|
714 \\[Man-next-section] Jump to next manpage section.
|
|
715 \\[Man-previous-section] Jump to previous manpage section.
|
|
716 \\[Man-goto-section] Go to a manpage section.
|
|
717 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section.
|
|
718 \\[Man-quit] Deletes the manpage window, bury its buffer.
|
|
719 \\[Man-kill] Deletes the manpage window, kill its buffer.
|
|
720 \\[describe-mode] Prints this help text.
|
|
721
|
|
722 The following variables may be of some use. Try
|
|
723 \"\\[describe-variable] <variable-name> RET\" for more information:
|
0
|
724
|
4
|
725 Man-notify-method What happens when manpage formatting is done.
|
|
726 Man-downcase-section-letters-flag Force section letters to lower case.
|
|
727 Man-circular-pages-flag Treat multiple manpage list as circular.
|
|
728 Man-auto-section-alist List of major modes and their section numbers.
|
|
729 Man-section-translations-alist List of section numbers and their Un*x equiv.
|
|
730 Man-filter-list Background manpage filter command.
|
|
731 Man-mode-line-format Mode line format for Man mode buffers.
|
|
732 Man-mode-map Keymap bindings for Man mode buffers.
|
|
733 Man-mode-hook Normal hook run on entry to Man mode.
|
|
734 Man-section-regexp Regexp describing manpage section letters.
|
|
735 Man-heading-regexp Regexp describing section headers.
|
|
736 Man-see-also-regexp Regexp for SEE ALSO section (or your equiv).
|
|
737 Man-first-heading-regexp Regexp for first heading on a manpage.
|
|
738 Man-reference-regexp Regexp matching a references in SEE ALSO.
|
|
739 Man-switches Background `man' command switches.
|
0
|
740
|
4
|
741 The following key bindings are currently in effect in the buffer:
|
|
742 \\{Man-mode-map}"
|
|
743 (interactive)
|
|
744 (setq major-mode 'Man-mode
|
|
745 mode-name "Man"
|
|
746 buffer-auto-save-file-name nil
|
|
747 mode-line-format Man-mode-line-format
|
|
748 truncate-lines t
|
|
749 buffer-read-only t)
|
|
750 (buffer-disable-undo (current-buffer))
|
|
751 (auto-fill-mode -1)
|
|
752 (use-local-map Man-mode-map)
|
|
753 (Man-build-page-list)
|
|
754 (Man-strip-page-headers)
|
|
755 (Man-unindent)
|
|
756 (Man-goto-page 1)
|
|
757 (run-hooks 'Man-mode-hook))
|
0
|
758
|
4
|
759 (defsubst Man-build-section-alist ()
|
|
760 "Build the association list of manpage sections."
|
|
761 (setq Man-sections-alist nil)
|
|
762 (goto-char (point-min))
|
|
763 (let ((case-fold-search nil))
|
|
764 (while (re-search-forward Man-heading-regexp (point-max) t)
|
|
765 (aput 'Man-sections-alist (Man-match-substring 1))
|
|
766 (forward-line 1))))
|
0
|
767
|
4
|
768 (defsubst Man-build-references-alist ()
|
|
769 "Build the association list of references (in the SEE ALSO section)."
|
|
770 (setq Man-refpages-alist nil)
|
|
771 (save-excursion
|
|
772 (if (Man-find-section Man-see-also-regexp)
|
|
773 (let ((start (progn (forward-line 1) (point)))
|
|
774 (end (progn
|
|
775 (Man-next-section 1)
|
|
776 (point)))
|
|
777 hyphenated
|
|
778 (runningpoint -1))
|
|
779 (save-restriction
|
|
780 (narrow-to-region start end)
|
|
781 (goto-char (point-min))
|
|
782 (back-to-indentation)
|
|
783 (while (and (not (eobp)) (/= (point) runningpoint))
|
|
784 (setq runningpoint (point))
|
|
785 (if (re-search-forward Man-reference-regexp end t)
|
|
786 (let* ((word (Man-match-substring 0))
|
|
787 (len (1- (length word))))
|
|
788 (if hyphenated
|
|
789 (setq word (concat hyphenated word)
|
|
790 hyphenated nil))
|
|
791 (if (= (aref word len) ?-)
|
|
792 (setq hyphenated (substring word 0 len))
|
|
793 (aput 'Man-refpages-alist word))))
|
|
794 (skip-chars-forward " \t\n,")))))))
|
|
795
|
|
796 (defun Man-build-page-list ()
|
|
797 "Build the list of separate manpages in the buffer."
|
|
798 (setq Man-page-list nil)
|
|
799 (let ((page-start (point-min))
|
|
800 (page-end (point-max))
|
|
801 (header ""))
|
|
802 (goto-char page-start)
|
|
803 ;; (switch-to-buffer (current-buffer))(debug)
|
|
804 (while (not (eobp))
|
|
805 (setq header
|
|
806 (if (looking-at Man-page-header-regexp)
|
|
807 (Man-match-substring 1)
|
|
808 nil))
|
|
809 ;; Go past both the current and the next Man-first-heading-regexp
|
|
810 (if (re-search-forward Man-first-heading-regexp nil 'move 2)
|
|
811 (let ((p (progn (beginning-of-line) (point))))
|
|
812 ;; We assume that the page header is delimited by blank
|
|
813 ;; lines and that it contains at most one blank line. So
|
|
814 ;; if we back by three blank lines we will be sure to be
|
|
815 ;; before the page header but not before the possible
|
|
816 ;; previous page header.
|
|
817 (search-backward "\n\n" nil t 3)
|
|
818 (if (re-search-forward Man-page-header-regexp p 'move)
|
|
819 (beginning-of-line))))
|
|
820 (setq page-end (point))
|
|
821 (setq Man-page-list (append Man-page-list
|
|
822 (list (list (copy-marker page-start)
|
|
823 (copy-marker page-end)
|
|
824 header))))
|
|
825 (setq page-start page-end)
|
|
826 )))
|
0
|
827
|
4
|
828 (defun Man-strip-page-headers ()
|
|
829 "Strip all the page headers but the first from the manpage."
|
|
830 (let ((buffer-read-only nil)
|
|
831 (case-fold-search nil)
|
|
832 (page-list Man-page-list)
|
|
833 (page ())
|
|
834 (header ""))
|
|
835 (while page-list
|
|
836 (setq page (car page-list))
|
|
837 (and (nth 2 page)
|
|
838 (goto-char (car page))
|
|
839 (re-search-forward Man-first-heading-regexp nil t)
|
|
840 (setq header (buffer-substring (car page) (match-beginning 0)))
|
|
841 ;; Since the awk script collapses all successive blank
|
|
842 ;; lines into one, and since we don't want to get rid of
|
|
843 ;; the fast awk script, one must choose between adding
|
|
844 ;; spare blank lines between pages when there were none and
|
|
845 ;; deleting blank lines at page boundaries when there were
|
|
846 ;; some. We choose the first, so we comment the following
|
|
847 ;; line.
|
|
848 ;; (setq header (concat "\n" header)))
|
|
849 (while (search-forward header (nth 1 page) t)
|
|
850 (replace-match "")))
|
|
851 (setq page-list (cdr page-list)))))
|
|
852
|
|
853 (defun Man-unindent ()
|
|
854 "Delete the leading spaces that indent the manpage."
|
|
855 (let ((buffer-read-only nil)
|
|
856 (case-fold-search nil)
|
|
857 (page-list Man-page-list))
|
|
858 (while page-list
|
|
859 (let ((page (car page-list))
|
|
860 (indent "")
|
|
861 (nindent 0))
|
|
862 (narrow-to-region (car page) (car (cdr page)))
|
|
863 (if Man-uses-untabify-flag
|
|
864 (untabify (point-min) (point-max)))
|
|
865 (if (catch 'unindent
|
|
866 (goto-char (point-min))
|
|
867 (if (not (re-search-forward Man-first-heading-regexp nil t))
|
|
868 (throw 'unindent nil))
|
|
869 (beginning-of-line)
|
|
870 (setq indent (buffer-substring (point)
|
|
871 (progn
|
|
872 (skip-chars-forward " ")
|
|
873 (point))))
|
|
874 (setq nindent (length indent))
|
|
875 (if (zerop nindent)
|
|
876 (throw 'unindent nil))
|
|
877 (setq indent (concat indent "\\|$"))
|
|
878 (goto-char (point-min))
|
|
879 (while (not (eobp))
|
|
880 (if (looking-at indent)
|
|
881 (forward-line 1)
|
|
882 (throw 'unindent nil)))
|
|
883 (goto-char (point-min)))
|
|
884 (while (not (eobp))
|
|
885 (or (eolp)
|
|
886 (delete-char nindent))
|
|
887 (forward-line 1)))
|
|
888 (setq page-list (cdr page-list))
|
|
889 ))))
|
|
890
|
|
891
|
|
892 ;; ======================================================================
|
|
893 ;; Man mode commands
|
0
|
894
|
4
|
895 (defun Man-next-section (n)
|
|
896 "Move point to Nth next section (default 1)."
|
|
897 (interactive "p")
|
|
898 (let ((case-fold-search nil))
|
|
899 (if (looking-at Man-heading-regexp)
|
|
900 (forward-line 1))
|
|
901 (if (re-search-forward Man-heading-regexp (point-max) t n)
|
|
902 (beginning-of-line)
|
|
903 (goto-char (point-max)))))
|
|
904
|
|
905 (defun Man-previous-section (n)
|
|
906 "Move point to Nth previous section (default 1)."
|
|
907 (interactive "p")
|
|
908 (let ((case-fold-search nil))
|
|
909 (if (looking-at Man-heading-regexp)
|
|
910 (forward-line -1))
|
|
911 (if (re-search-backward Man-heading-regexp (point-min) t n)
|
|
912 (beginning-of-line)
|
|
913 (goto-char (point-min)))))
|
|
914
|
|
915 (defun Man-find-section (section)
|
|
916 "Move point to SECTION if it exists, otherwise don't move point.
|
|
917 Returns t if section is found, nil otherwise."
|
|
918 (let ((curpos (point))
|
|
919 (case-fold-search nil))
|
|
920 (goto-char (point-min))
|
|
921 (if (re-search-forward (concat "^" section) (point-max) t)
|
|
922 (progn (beginning-of-line) t)
|
|
923 (goto-char curpos)
|
|
924 nil)
|
|
925 ))
|
|
926
|
|
927 (defun Man-goto-section ()
|
|
928 "Query for section to move point to."
|
|
929 (interactive)
|
|
930 (aput 'Man-sections-alist
|
|
931 (let* ((default (aheadsym Man-sections-alist))
|
|
932 (completion-ignore-case t)
|
|
933 chosen
|
|
934 (prompt (concat "Go to section: (default " default ") ")))
|
|
935 (setq chosen (completing-read prompt Man-sections-alist))
|
|
936 (if (or (not chosen)
|
|
937 (string= chosen ""))
|
|
938 default
|
|
939 chosen)))
|
|
940 (Man-find-section (aheadsym Man-sections-alist)))
|
|
941
|
|
942 (defun Man-goto-see-also-section ()
|
|
943 "Move point the the \"SEE ALSO\" section.
|
|
944 Actually the section moved to is described by `Man-see-also-regexp'."
|
|
945 (interactive)
|
|
946 (if (not (Man-find-section Man-see-also-regexp))
|
|
947 (error (concat "No " Man-see-also-regexp
|
|
948 " section found in the current manpage"))))
|
0
|
949
|
4
|
950 (defun Man-follow-manual-reference (reference)
|
|
951 "Get one of the manpages referred to in the \"SEE ALSO\" section.
|
|
952 Specify which reference to use; default is based on word at point."
|
|
953 (interactive
|
|
954 (if (not Man-refpages-alist)
|
|
955 (error "There are no references in the current man page")
|
|
956 (list (let* ((default (or
|
|
957 (car (all-completions
|
|
958 (save-excursion
|
|
959 (skip-syntax-backward "w()")
|
|
960 (skip-chars-forward " \t")
|
|
961 (let ((word (current-word)))
|
|
962 ;; strip a trailing '-':
|
|
963 (if (string-match "-$" word)
|
|
964 (substring word 0
|
|
965 (match-beginning 0))
|
|
966 word)))
|
|
967 Man-refpages-alist))
|
|
968 (aheadsym Man-refpages-alist)))
|
|
969 chosen
|
|
970 (prompt (concat "Refer to: (default " default ") ")))
|
|
971 (setq chosen (completing-read prompt Man-refpages-alist nil t))
|
|
972 (if (or (not chosen)
|
|
973 (string= chosen ""))
|
|
974 default
|
|
975 chosen)))))
|
|
976 (if (not Man-refpages-alist)
|
|
977 (error "Can't find any references in the current manpage")
|
|
978 (aput 'Man-refpages-alist reference)
|
|
979 (Man-getpage-in-background
|
|
980 (Man-translate-references (aheadsym Man-refpages-alist)))))
|
|
981
|
|
982 (defun Man-kill ()
|
|
983 "Kill the buffer containing the manpage."
|
|
984 (interactive)
|
|
985 (let ((buff (current-buffer)))
|
|
986 (delete-windows-on buff)
|
|
987 (kill-buffer buff))
|
|
988 (if (and window-system
|
|
989 (or (eq Man-notify-method 'newframe)
|
|
990 (and pop-up-frames
|
|
991 (eq Man-notify-method 'bully))))
|
|
992 (delete-frame)))
|
|
993
|
|
994 (defun Man-quit ()
|
|
995 "Bury the buffer containing the manpage."
|
|
996 (interactive)
|
|
997 (let ((buff (current-buffer)))
|
|
998 (delete-windows-on buff)
|
|
999 (bury-buffer buff))
|
|
1000 (if (and window-system
|
|
1001 (or (eq Man-notify-method 'newframe)
|
|
1002 (and pop-up-frames
|
|
1003 (eq Man-notify-method 'bully))))
|
|
1004 (delete-frame)))
|
|
1005
|
|
1006 (defun Man-goto-page (page)
|
|
1007 "Go to the manual page on page PAGE."
|
|
1008 (interactive
|
|
1009 (if (not Man-page-list)
|
|
1010 (let ((args Man-arguments))
|
|
1011 (kill-buffer (current-buffer))
|
|
1012 (error "Can't find the %s manpage" args))
|
|
1013 (if (= (length Man-page-list) 1)
|
|
1014 (error "You're looking at the only manpage in the buffer")
|
|
1015 (list (read-minibuffer (format "Go to manpage [1-%d]: "
|
|
1016 (length Man-page-list)))))))
|
|
1017 (if (not Man-page-list)
|
|
1018 (let ((args Man-arguments))
|
|
1019 (kill-buffer (current-buffer))
|
|
1020 (error "Can't find the %s manpage" args)))
|
|
1021 (if (or (< page 1)
|
|
1022 (> page (length Man-page-list)))
|
|
1023 (error "No manpage %d found" page))
|
|
1024 (let* ((page-range (nth (1- page) Man-page-list))
|
|
1025 (page-start (car page-range))
|
|
1026 (page-end (car (cdr page-range))))
|
|
1027 (setq Man-current-page page
|
|
1028 Man-page-mode-string (Man-make-page-mode-string))
|
|
1029 (widen)
|
|
1030 (goto-char page-start)
|
|
1031 (narrow-to-region page-start page-end)
|
|
1032 (Man-build-section-alist)
|
|
1033 (Man-build-references-alist)
|
|
1034 (goto-char (point-min))))
|
0
|
1035
|
|
1036
|
4
|
1037 (defun Man-next-manpage ()
|
|
1038 "Find the next manpage entry in the buffer."
|
|
1039 (interactive)
|
|
1040 (if (= (length Man-page-list) 1)
|
|
1041 (error "This is the only manpage in the buffer"))
|
|
1042 (if (< Man-current-page (length Man-page-list))
|
|
1043 (Man-goto-page (1+ Man-current-page))
|
|
1044 (if Man-circular-pages-flag
|
|
1045 (Man-goto-page 1)
|
|
1046 (error "You're looking at the last manpage in the buffer"))))
|
0
|
1047
|
4
|
1048 (defun Man-previous-manpage ()
|
|
1049 "Find the previous manpage entry in the buffer."
|
|
1050 (interactive)
|
|
1051 (if (= (length Man-page-list) 1)
|
|
1052 (error "This is the only manpage in the buffer"))
|
|
1053 (if (> Man-current-page 1)
|
|
1054 (Man-goto-page (1- Man-current-page))
|
|
1055 (if Man-circular-pages-flag
|
|
1056 (Man-goto-page (length Man-page-list))
|
|
1057 (error "You're looking at the first manpage in the buffer"))))
|
|
1058
|
|
1059 ;; Init the man package variables, if not already done.
|
|
1060 (Man-init-defvars)
|
0
|
1061
|
4
|
1062 (provide 'man)
|
0
|
1063
|
4
|
1064 ;;; man.el ends here
|