3235
|
1 ;;; man.el --- browse UNIX manual pages
|
|
2
|
38970
|
3 ;; Copyright (C) 1993, 1994, 1996, 1997, 2001 Free Software Foundation, Inc.
|
3235
|
4
|
38412
|
5 ;; Author: Barry A. Warsaw <bwarsaw@cen.com>
|
28102
|
6 ;; Maintainer: FSF
|
38412
|
7 ;; Keywords: help
|
|
8 ;; Adapted-By: ESR, pot
|
3235
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
14169
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
3235
|
26
|
|
27 ;;; Commentary:
|
|
28
|
8970
|
29 ;; This code provides a function, `man', with which you can browse
|
|
30 ;; UNIX manual pages. Formatting is done in background so that you
|
|
31 ;; can continue to use your Emacs while processing is going on.
|
3235
|
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
|
28102
|
37 ;; ========== Credits and History ==========
|
3235
|
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
|
14040
|
40 ;; these, but wanted everything in one single package, so I decided
|
8970
|
41 ;; to incorporate them into a single manual browsing mode. While
|
3235
|
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
|
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
|
8970
|
59 ;; Francesco Potorti` <pot@cnuce.cnr.it> cleaned it up thoroughly,
|
|
60 ;; making it faster, more robust and more tolerant of different
|
14040
|
61 ;; systems' man idiosyncrasies.
|
8970
|
62
|
3235
|
63 ;; ========== Features ==========
|
|
64 ;; + Runs "man" in the background and pipes the results through a
|
|
65 ;; series of sed and awk scripts so that all retrieving and cleaning
|
|
66 ;; is done in the background. The cleaning commands are configurable.
|
|
67 ;; + Syntax is the same as Un*x man
|
|
68 ;; + Functionality is the same as Un*x man, including "man -k" and
|
3909
|
69 ;; "man <section>", etc.
|
3235
|
70 ;; + Provides a manual browsing mode with keybindings for traversing
|
|
71 ;; the sections of a manpage, following references in the SEE ALSO
|
|
72 ;; section, and more.
|
|
73 ;; + Multiple manpages created with the same man command are put into
|
|
74 ;; a narrowed buffer circular list.
|
|
75
|
8970
|
76 ;; ============= TODO ===========
|
|
77 ;; - Add a command for printing.
|
|
78 ;; - The awk script deletes multiple blank lines. This behaviour does
|
|
79 ;; not allow to understand if there was indeed a blank line at the
|
|
80 ;; end or beginning of a page (after the header, or before the
|
|
81 ;; footer). A different algorithm should be used. It is easy to
|
|
82 ;; compute how many blank lines there are before and after the page
|
|
83 ;; headers, and after the page footer. But it is possible to compute
|
41698
|
84 ;; the number of blank lines before the page footer by heuristics
|
8970
|
85 ;; only. Is it worth doing?
|
9828
|
86 ;; - Allow a user option to mean that all the manpages should go in
|
|
87 ;; the same buffer, where they can be browsed with M-n and M-p.
|
8970
|
88 ;; - Allow completion on the manpage name when calling man. This
|
|
89 ;; requires a reliable list of places where manpages can be found. The
|
|
90 ;; drawback would be that if the list is not complete, the user might
|
|
91 ;; be led to believe that the manpages in the missing directories do
|
|
92 ;; not exist.
|
|
93
|
9354
|
94
|
3235
|
95 ;;; Code:
|
|
96
|
|
97 (require 'assoc)
|
|
98
|
|
99 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
9354
|
100 ;; empty defvars (keep the compiler quiet)
|
|
101
|
17436
|
102 (defgroup man nil
|
|
103 "Browse UNIX manual pages."
|
|
104 :prefix "Man-"
|
|
105 :group 'help)
|
|
106
|
|
107
|
9354
|
108 (defvar Man-notify)
|
|
109 (defvar Man-current-page)
|
|
110 (defvar Man-page-list)
|
17436
|
111 (defcustom Man-filter-list nil
|
14672
|
112 "*Manpage cleaning filter command phrases.
|
|
113 This variable contains a list of the following form:
|
|
114
|
|
115 '((command-string phrase-string*)*)
|
|
116
|
|
117 Each phrase-string is concatenated onto the command-string to form a
|
|
118 command filter. The (standard) output (and standard error) of the Un*x
|
|
119 man command is piped through each command filter in the order the
|
|
120 commands appear in the association list. The final output is placed in
|
17436
|
121 the manpage buffer."
|
|
122 :type '(repeat (list (string :tag "Command String")
|
|
123 (repeat :inline t
|
|
124 (string :tag "Phrase String"))))
|
|
125 :group 'man)
|
14672
|
126
|
9354
|
127 (defvar Man-original-frame)
|
|
128 (defvar Man-arguments)
|
|
129 (defvar Man-sections-alist)
|
|
130 (defvar Man-refpages-alist)
|
14672
|
131 (defvar Man-uses-untabify-flag t
|
28102
|
132 "Non-nil means use `untabify' instead of `Man-untabify-command'.")
|
9354
|
133 (defvar Man-page-mode-string)
|
14672
|
134 (defvar Man-sed-script nil
|
|
135 "Script for sed to nuke backspaces and ANSI codes from manpages.")
|
9354
|
136
|
|
137 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
3235
|
138 ;; user variables
|
|
139
|
17436
|
140 (defcustom Man-fontify-manpage-flag t
|
28102
|
141 "*Non-nil means make up the manpage with fonts."
|
17436
|
142 :type 'boolean
|
|
143 :group 'man)
|
9726
|
144
|
17436
|
145 (defcustom Man-overstrike-face 'bold
|
|
146 "*Face to use when fontifying overstrike."
|
|
147 :type 'face
|
|
148 :group 'man)
|
9726
|
149
|
17436
|
150 (defcustom Man-underline-face 'underline
|
|
151 "*Face to use when fontifying underlining."
|
|
152 :type 'face
|
|
153 :group 'man)
|
6676
|
154
|
8970
|
155 ;; Use the value of the obsolete user option Man-notify, if set.
|
17436
|
156 (defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
|
3235
|
157 "*Selects the behavior when manpage is ready.
|
8970
|
158 This variable may have one of the following values, where (sf) means
|
|
159 that the frames are switched, so the manpage is displayed in the frame
|
|
160 where the man command was called from:
|
3235
|
161
|
4915
|
162 newframe -- put the manpage in its own frame (see `Man-frame-parameters')
|
8970
|
163 pushy -- make the manpage the current buffer in the current window
|
|
164 bully -- make the manpage the current buffer and only window (sf)
|
|
165 aggressive -- make the manpage the current buffer in the other window (sf)
|
|
166 friendly -- display manpage in the other window but don't make current (sf)
|
|
167 polite -- don't display manpage, but prints message and beep when ready
|
3235
|
168 quiet -- like `polite', but don't beep
|
8970
|
169 meek -- make no indication that the manpage is ready
|
3235
|
170
|
17436
|
171 Any other value of `Man-notify-method' is equivalent to `meek'."
|
|
172 :type '(radio (const newframe) (const pushy) (const bully)
|
|
173 (const aggressive) (const friendly)
|
|
174 (const polite) (const quiet) (const meek))
|
|
175 :group 'man)
|
3235
|
176
|
17436
|
177 (defcustom Man-frame-parameters nil
|
|
178 "*Frame parameter list for creating a new frame for a manual page."
|
|
179 :type 'sexp
|
|
180 :group 'man)
|
4915
|
181
|
17436
|
182 (defcustom Man-downcase-section-letters-flag t
|
28102
|
183 "*Non-nil means letters in sections are converted to lower case.
|
3235
|
184 Some Un*x man commands can't handle uppercase letters in sections, for
|
|
185 example \"man 2V chmod\", but they are often displayed in the manpage
|
3909
|
186 with the upper case letter. When this variable is t, the section
|
3235
|
187 letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before
|
17436
|
188 being sent to the man background process."
|
|
189 :type 'boolean
|
|
190 :group 'man)
|
3235
|
191
|
17436
|
192 (defcustom Man-circular-pages-flag t
|
28102
|
193 "*Non-nil means the manpage list is treated as circular for traversal."
|
17436
|
194 :type 'boolean
|
|
195 :group 'man)
|
3235
|
196
|
17436
|
197 (defcustom Man-section-translations-alist
|
8970
|
198 (list
|
|
199 '("3C++" . "3")
|
|
200 ;; Some systems have a real 3x man section, so let's comment this.
|
|
201 ;; '("3X" . "3") ; Xlib man pages
|
|
202 '("3X11" . "3")
|
|
203 '("1-UCB" . ""))
|
3235
|
204 "*Association list of bogus sections to real section numbers.
|
|
205 Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
|
3909
|
206 their references which Un*x `man' does not recognize. This
|
3591
|
207 association list is used to translate those sections, when found, to
|
17436
|
208 the associated section number."
|
|
209 :type '(repeat (cons (string :tag "Bogus Section")
|
|
210 (string :tag "Real Section")))
|
|
211 :group 'man)
|
3235
|
212
|
9726
|
213 (defvar manual-program "man"
|
|
214 "The name of the program that produces man pages.")
|
|
215
|
8970
|
216 (defvar Man-untabify-command "pr"
|
9726
|
217 "Command used for untabifying.")
|
8970
|
218
|
|
219 (defvar Man-untabify-command-args (list "-t" "-e")
|
28102
|
220 "List of arguments to be passed to `Man-untabify-command' (which see).")
|
8970
|
221
|
|
222 (defvar Man-sed-command "sed"
|
9726
|
223 "Command used for processing sed scripts.")
|
8970
|
224
|
|
225 (defvar Man-awk-command "awk"
|
9726
|
226 "Command used for processing awk scripts.")
|
|
227
|
|
228 (defvar Man-mode-map nil
|
|
229 "Keymap for Man mode.")
|
|
230
|
|
231 (defvar Man-mode-hook nil
|
|
232 "Hook run when Man mode is enabled.")
|
|
233
|
|
234 (defvar Man-cooked-hook nil
|
28102
|
235 "Hook run after removing backspaces but before `Man-mode' processing.")
|
9726
|
236
|
|
237 (defvar Man-name-regexp "[-a-zA-Z0-9_][-a-zA-Z0-9_.]*"
|
|
238 "Regular expression describing the name of a manpage (without section).")
|
|
239
|
|
240 (defvar Man-section-regexp "[0-9][a-zA-Z+]*\\|[LNln]"
|
|
241 "Regular expression describing a manpage section within parentheses.")
|
|
242
|
|
243 (defvar Man-page-header-regexp
|
23644
|
244 (if (and (string-match "-solaris2\\." system-configuration)
|
|
245 (not (string-match "-solaris2\\.[123435]$" system-configuration)))
|
|
246 (concat "^[-A-Za-z0-9_].*[ \t]\\(" Man-name-regexp
|
|
247 "(\\(" Man-section-regexp "\\))\\)$")
|
|
248 (concat "^[ \t]*\\(" Man-name-regexp
|
|
249 "(\\(" Man-section-regexp "\\))\\).*\\1"))
|
9726
|
250 "Regular expression describing the heading of a page.")
|
|
251
|
|
252 (defvar Man-heading-regexp "^\\([A-Z][A-Z ]+\\)$"
|
|
253 "Regular expression describing a manpage heading entry.")
|
|
254
|
|
255 (defvar Man-see-also-regexp "SEE ALSO"
|
|
256 "Regular expression for SEE ALSO heading (or your equivalent).
|
|
257 This regexp should not start with a `^' character.")
|
|
258
|
|
259 (defvar Man-first-heading-regexp "^[ \t]*NAME$\\|^[ \t]*No manual entry fo.*$"
|
|
260 "Regular expression describing first heading on a manpage.
|
|
261 This regular expression should start with a `^' character.")
|
|
262
|
|
263 (defvar Man-reference-regexp
|
|
264 (concat "\\(" Man-name-regexp "\\)(\\(" Man-section-regexp "\\))")
|
36575
|
265 "Regular expression describing a reference to another manpage.")
|
|
266
|
|
267 ;; This includes the section as an optional part to catch hyphenated
|
|
268 ;; refernces to manpages.
|
|
269 (defvar Man-hyphenated-reference-regexp
|
|
270 (concat "\\(" Man-name-regexp "\\)\\((\\(" Man-section-regexp "\\))\\)?")
|
9726
|
271 "Regular expression describing a reference in the SEE ALSO section.")
|
|
272
|
|
273 (defvar Man-switches ""
|
38646
|
274 "Switches passed to the man command, as a single string.
|
|
275
|
|
276 If you want to be able to see all the manpages for a subject you type,
|
|
277 make -a one of the switches, if your `man' program supports it.")
|
9726
|
278
|
|
279 (defvar Man-specified-section-option
|
|
280 (if (string-match "-solaris[0-9.]*$" system-configuration)
|
|
281 "-s"
|
|
282 "")
|
|
283 "Option that indicates a specified a manual section name.")
|
|
284
|
|
285 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
286 ;; end user variables
|
|
287
|
|
288 ;; other variables and keymap initializations
|
|
289 (make-variable-buffer-local 'Man-sections-alist)
|
|
290 (make-variable-buffer-local 'Man-refpages-alist)
|
|
291 (make-variable-buffer-local 'Man-page-list)
|
|
292 (make-variable-buffer-local 'Man-current-page)
|
|
293 (make-variable-buffer-local 'Man-page-mode-string)
|
|
294 (make-variable-buffer-local 'Man-original-frame)
|
|
295 (make-variable-buffer-local 'Man-arguments)
|
|
296
|
|
297 (setq-default Man-sections-alist nil)
|
|
298 (setq-default Man-refpages-alist nil)
|
|
299 (setq-default Man-page-list nil)
|
|
300 (setq-default Man-current-page 0)
|
|
301 (setq-default Man-page-mode-string "1 of 1")
|
3235
|
302
|
8970
|
303 (defconst Man-sysv-sed-script "\
|
|
304 /\b/ { s/_\b//g
|
|
305 s/\b_//g
|
|
306 s/o\b+/o/g
|
9867
|
307 s/+\bo/o/g
|
8970
|
308 :ovstrk
|
|
309 s/\\(.\\)\b\\1/\\1/g
|
|
310 t ovstrk
|
|
311 }
|
|
312 /\e\\[[0-9][0-9]*m/ s///g"
|
|
313 "Script for sysV-like sed to nuke backspaces and ANSI codes from manpages.")
|
3235
|
314
|
8970
|
315 (defconst Man-berkeley-sed-script "\
|
|
316 /\b/ { s/_\b//g\\
|
|
317 s/\b_//g\\
|
|
318 s/o\b+/o/g\\
|
9867
|
319 s/+\bo/o/g\\
|
8970
|
320 :ovstrk\\
|
|
321 s/\\(.\\)\b\\1/\\1/g\\
|
|
322 t ovstrk\\
|
|
323 }\\
|
|
324 /\e\\[[0-9][0-9]*m/ s///g"
|
|
325 "Script for berkeley-like sed to nuke backspaces and ANSI codes from manpages.")
|
3235
|
326
|
17132
|
327 (defvar man-mode-syntax-table
|
|
328 (let ((table (copy-syntax-table (standard-syntax-table))))
|
|
329 (modify-syntax-entry ?. "w" table)
|
|
330 (modify-syntax-entry ?_ "w" table)
|
|
331 table)
|
|
332 "Syntax table used in Man mode buffers.")
|
|
333
|
3235
|
334 (if Man-mode-map
|
|
335 nil
|
|
336 (setq Man-mode-map (make-keymap))
|
|
337 (suppress-keymap Man-mode-map)
|
|
338 (define-key Man-mode-map " " 'scroll-up)
|
|
339 (define-key Man-mode-map "\177" 'scroll-down)
|
|
340 (define-key Man-mode-map "n" 'Man-next-section)
|
|
341 (define-key Man-mode-map "p" 'Man-previous-section)
|
|
342 (define-key Man-mode-map "\en" 'Man-next-manpage)
|
|
343 (define-key Man-mode-map "\ep" 'Man-previous-manpage)
|
8970
|
344 (define-key Man-mode-map ">" 'end-of-buffer)
|
|
345 (define-key Man-mode-map "<" 'beginning-of-buffer)
|
|
346 (define-key Man-mode-map "." 'beginning-of-buffer)
|
3235
|
347 (define-key Man-mode-map "r" 'Man-follow-manual-reference)
|
|
348 (define-key Man-mode-map "g" 'Man-goto-section)
|
|
349 (define-key Man-mode-map "s" 'Man-goto-see-also-section)
|
8970
|
350 (define-key Man-mode-map "k" 'Man-kill)
|
3235
|
351 (define-key Man-mode-map "q" 'Man-quit)
|
8970
|
352 (define-key Man-mode-map "m" 'man)
|
17129
|
353 (define-key Man-mode-map "\r" 'man-follow)
|
41698
|
354 (define-key Man-mode-map [mouse-2] 'man-follow-mouse)
|
3235
|
355 (define-key Man-mode-map "?" 'describe-mode)
|
|
356 )
|
|
357
|
|
358
|
|
359 ;; ======================================================================
|
|
360 ;; utilities
|
|
361
|
14672
|
362 (defun Man-init-defvars ()
|
29973
|
363 "Used for initialising variables based on display's color support.
|
28102
|
364 This is necessary if one wants to dump man.el with Emacs."
|
8970
|
365
|
20266
|
366 ;; Avoid possible error in call-process by using a directory that must exist.
|
|
367 (let ((default-directory "/"))
|
|
368 (setq Man-sed-script
|
|
369 (cond
|
|
370 (Man-fontify-manpage-flag
|
|
371 nil)
|
|
372 ((= 0 (call-process Man-sed-command nil nil nil Man-sysv-sed-script))
|
|
373 Man-sysv-sed-script)
|
|
374 ((= 0 (call-process Man-sed-command nil nil nil Man-berkeley-sed-script))
|
|
375 Man-berkeley-sed-script)
|
|
376 (t
|
|
377 nil))))
|
3235
|
378
|
14672
|
379 (setq Man-filter-list
|
23267
|
380 ;; Avoid trailing nil which confuses customize.
|
|
381 (apply 'list
|
8970
|
382 (cons
|
14672
|
383 Man-sed-command
|
|
384 (list
|
|
385 (if Man-sed-script
|
|
386 (concat "-e '" Man-sed-script "'")
|
|
387 "")
|
|
388 "-e '/^[\001-\032][\001-\032]*$/d'"
|
|
389 "-e '/\e[789]/s///g'"
|
|
390 "-e '/Reformatting page. Wait/d'"
|
|
391 "-e '/Reformatting entry. Wait/d'"
|
|
392 "-e '/^[ \t]*Hewlett-Packard[ \t]Company[ \t]*-[ \t][0-9]*[ \t]-/d'"
|
|
393 "-e '/^[ \t]*Hewlett-Packard[ \t]*-[ \t][0-9]*[ \t]-.*$/d'"
|
|
394 "-e '/^[ \t][ \t]*-[ \t][0-9]*[ \t]-[ \t]*Formatted:.*[0-9]$/d'"
|
|
395 "-e '/^[ \t]*Page[ \t][0-9]*.*(printed[ \t][0-9\\/]*)$/d'"
|
|
396 "-e '/^Printed[ \t][0-9].*[0-9]$/d'"
|
|
397 "-e '/^[ \t]*X[ \t]Version[ \t]1[01].*Release[ \t][0-9]/d'"
|
16974
|
398 "-e '/^[A-Za-z].*Last[ \t]change:/d'"
|
14672
|
399 "-e '/^Sun[ \t]Release[ \t][0-9].*[0-9]$/d'"
|
|
400 "-e '/[ \t]*Copyright [0-9]* UNIX System Laboratories, Inc.$/d'"
|
|
401 "-e '/^[ \t]*Rev\\..*Page [0-9][0-9]*$/d'"
|
|
402 ))
|
|
403 (cons
|
|
404 Man-awk-command
|
|
405 (list
|
|
406 "'\n"
|
|
407 "BEGIN { blankline=0; anonblank=0; }\n"
|
|
408 "/^$/ { if (anonblank==0) next; }\n"
|
|
409 "{ anonblank=1; }\n"
|
|
410 "/^$/ { blankline++; next; }\n"
|
|
411 "{ if (blankline>0) { print \"\"; blankline=0; } print $0; }\n"
|
|
412 "'"
|
|
413 ))
|
|
414 (if (not Man-uses-untabify-flag)
|
23267
|
415 ;; The outer list will be stripped off by apply.
|
|
416 (list (cons
|
|
417 Man-untabify-command
|
|
418 Man-untabify-command-args))
|
14672
|
419 )))
|
8970
|
420 )
|
|
421
|
|
422 (defsubst Man-make-page-mode-string ()
|
|
423 "Formats part of the mode line for Man mode."
|
|
424 (format "%s page %d of %d"
|
|
425 (or (nth 2 (nth (1- Man-current-page) Man-page-list))
|
|
426 "")
|
|
427 Man-current-page
|
|
428 (length Man-page-list)))
|
|
429
|
|
430 (defsubst Man-build-man-command ()
|
3235
|
431 "Builds the entire background manpage and cleaning command."
|
16973
|
432 (let ((command (concat manual-program " " Man-switches
|
|
433 ; Stock MS-DOS shells cannot redirect stderr;
|
|
434 ; `call-process' below sends it to /dev/null,
|
|
435 ; so we don't need `2>' even with DOS shells
|
|
436 ; which do support stderr redirection.
|
|
437 (if (not (fboundp 'start-process))
|
|
438 " %s"
|
24914
|
439 (concat " %s 2>" null-device))))
|
3235
|
440 (flist Man-filter-list))
|
8970
|
441 (while (and flist (car flist))
|
3235
|
442 (let ((pcom (car (car flist)))
|
8970
|
443 (pargs (cdr (car flist))))
|
|
444 (setq command
|
|
445 (concat command " | " pcom " "
|
29585
|
446 (mapconcat (lambda (phrase)
|
|
447 (if (not (stringp phrase))
|
|
448 (error "Malformed Man-filter-list"))
|
|
449 phrase)
|
8970
|
450 pargs " ")))
|
|
451 (setq flist (cdr flist))))
|
3235
|
452 command))
|
|
453
|
|
454 (defun Man-translate-references (ref)
|
8970
|
455 "Translates REF from \"chmod(2V)\" to \"2v chmod\" style.
|
|
456 Leave it as is if already in that style. Possibly downcase and
|
|
457 translate the section (see the Man-downcase-section-letters-flag
|
12809
|
458 and the Man-section-translations-alist variables)."
|
8970
|
459 (let ((name "")
|
|
460 (section "")
|
|
461 (slist Man-section-translations-alist))
|
|
462 (cond
|
|
463 ;; "chmod(2V)" case ?
|
12809
|
464 ((string-match (concat "^" Man-reference-regexp "$") ref)
|
41698
|
465 (setq name (match-string 1 ref)
|
|
466 section (match-string 2 ref)))
|
8970
|
467 ;; "2v chmod" case ?
|
12809
|
468 ((string-match (concat "^\\(" Man-section-regexp
|
8970
|
469 "\\) +\\(" Man-name-regexp "\\)$") ref)
|
41698
|
470 (setq name (match-string 2 ref)
|
|
471 section (match-string 1 ref))))
|
8970
|
472 (if (string= name "")
|
|
473 ref ; Return the reference as is
|
|
474 (if Man-downcase-section-letters-flag
|
|
475 (setq section (downcase section)))
|
|
476 (while slist
|
|
477 (let ((s1 (car (car slist)))
|
|
478 (s2 (cdr (car slist))))
|
|
479 (setq slist (cdr slist))
|
|
480 (if Man-downcase-section-letters-flag
|
|
481 (setq s1 (downcase s1)))
|
|
482 (if (not (string= s1 section)) nil
|
|
483 (setq section (if Man-downcase-section-letters-flag
|
|
484 (downcase s2)
|
|
485 s2)
|
|
486 slist nil))))
|
|
487 (concat Man-specified-section-option section " " name))))
|
3235
|
488
|
|
489
|
|
490 ;; ======================================================================
|
8970
|
491 ;; default man entry: get word under point
|
3235
|
492
|
8970
|
493 (defsubst Man-default-man-entry ()
|
3235
|
494 "Make a guess at a default manual entry.
|
35603
|
495 This guess is based on the text surrounding the cursor."
|
17132
|
496 (let (word)
|
3235
|
497 (save-excursion
|
8970
|
498 ;; Default man entry title is any word the cursor is on, or if
|
17132
|
499 ;; cursor not on a word, then nearest preceding word.
|
48012
|
500 (skip-chars-backward "-a-zA-Z0-9._+:")
|
|
501 (let ((start (point)))
|
|
502 (skip-chars-forward "-a-zA-Z0-9._+:")
|
|
503 (setq word (buffer-substring start (point))))
|
17132
|
504 (if (string-match "[._]+$" word)
|
|
505 (setq word (substring word 0 (match-beginning 0))))
|
8970
|
506 ;; If looking at something like ioctl(2) or brc(1M), include the
|
10642
0e6b71f2ebad
* man.el (Man-default-man-entry): Remove text properties from result.
Francesco Potortì <pot@gnu.org>
diff
changeset
|
507 ;; section number in the returned value. Remove text properties.
|
17132
|
508 (forward-word 1)
|
|
509 ;; Use `format' here to clear any text props from `word'.
|
|
510 (format "%s%s"
|
|
511 word
|
|
512 (if (looking-at
|
|
513 (concat "[ \t]*([ \t]*\\(" Man-section-regexp "\\)[ \t]*)"))
|
41698
|
514 (format "(%s)" (match-string 1))
|
17132
|
515 "")))))
|
8970
|
516
|
3235
|
517
|
|
518 ;; ======================================================================
|
8970
|
519 ;; Top level command and background process sentinel
|
3235
|
520
|
8970
|
521 ;; For compatibility with older versions.
|
4444
|
522 ;;;###autoload
|
8970
|
523 (defalias 'manual-entry 'man)
|
4444
|
524
|
3235
|
525 ;;;###autoload
|
9828
|
526 (defun man (man-args)
|
3235
|
527 "Get a Un*x manual page and put it in a buffer.
|
3909
|
528 This command is the top-level command in the man package. It runs a Un*x
|
3235
|
529 command to retrieve and clean a manpage in the background and places the
|
3909
|
530 results in a Man mode (manpage browsing) buffer. See variable
|
9003
|
531 `Man-notify-method' for what happens when the buffer is ready.
|
29838
|
532 If a buffer already exists for this man page, it will display immediately.
|
|
533
|
|
534 To specify a man page from a certain section, type SUBJECT(SECTION) or
|
38646
|
535 SECTION SUBJECT when prompted for a manual entry. To see manpages from
|
|
536 all sections related to a subject, put something appropriate into the
|
|
537 `Man-switches' variable, which see."
|
8970
|
538 (interactive
|
9828
|
539 (list (let* ((default-entry (Man-default-man-entry))
|
|
540 (input (read-string
|
|
541 (format "Manual entry%s: "
|
|
542 (if (string= default-entry "")
|
|
543 ""
|
41698
|
544 (format " (default %s)" default-entry)))
|
|
545 nil nil default-entry)))
|
9828
|
546 (if (string= input "")
|
41698
|
547 (error "No man args given")
|
9828
|
548 input))))
|
4002
|
549
|
8970
|
550 ;; Possibly translate the "subject(section)" syntax into the
|
|
551 ;; "section subject" syntax and possibly downcase the section.
|
|
552 (setq man-args (Man-translate-references man-args))
|
|
553
|
9828
|
554 (Man-getpage-in-background man-args))
|
8970
|
555
|
17129
|
556 ;;;###autoload
|
|
557 (defun man-follow (man-args)
|
|
558 "Get a Un*x manual page of the item under point and put it in a buffer."
|
|
559 (interactive (list (Man-default-man-entry)))
|
|
560 (if (or (not man-args)
|
|
561 (string= man-args ""))
|
|
562 (error "No item under point")
|
|
563 (man man-args)))
|
3235
|
564
|
41698
|
565 (defun man-follow-mouse (e)
|
|
566 "Get a Un*x manual page of the item under the mouse and put it in a buffer."
|
|
567 (interactive "e")
|
|
568 (save-excursion
|
|
569 (mouse-set-point e)
|
|
570 (call-interactively 'man-follow)))
|
|
571
|
9828
|
572 (defun Man-getpage-in-background (topic)
|
28102
|
573 "Use TOPIC to build and fire off the manpage and cleaning command."
|
5269
|
574 (let* ((man-args topic)
|
9354
|
575 (bufname (concat "*Man " man-args "*"))
|
3235
|
576 (buffer (get-buffer bufname)))
|
9828
|
577 (if buffer
|
3235
|
578 (Man-notify-when-ready buffer)
|
6353
|
579 (require 'env)
|
8970
|
580 (message "Invoking %s %s in the background" manual-program man-args)
|
3235
|
581 (setq buffer (generate-new-buffer bufname))
|
6363
|
582 (save-excursion
|
|
583 (set-buffer buffer)
|
8970
|
584 (setq Man-original-frame (selected-frame))
|
|
585 (setq Man-arguments man-args))
|
20266
|
586 (let ((process-environment (copy-sequence process-environment))
|
22217
|
587 ;; The following is so Awk script gets \n intact
|
|
588 ;; But don't prevent decoding of the outside.
|
|
589 (coding-system-for-write 'raw-text-unix)
|
30995
75f3cd16a9ab
(Man-getpage-in-background): Decode the process output by the system
Kenichi Handa <handa@m17n.org>
diff
changeset
|
590 ;; We must decode the output by a coding system that the
|
32495
|
591 ;; system's locale suggests in multibyte mode.
|
32396
|
592 (coding-system-for-read
|
|
593 (if default-enable-multibyte-characters
|
|
594 locale-coding-system 'raw-text-unix))
|
20266
|
595 ;; Avoid possible error by using a directory that always exists.
|
|
596 (default-directory "/"))
|
3713
|
597 ;; Prevent any attempt to use display terminal fanciness.
|
|
598 (setenv "TERM" "dumb")
|
47891
|
599 ;; In Debian Woody, at least, we get overlong lines under X
|
|
600 ;; unless COLUMNS or MANWIDTH is set. This isn't a problem on
|
|
601 ;; a tty. man(1) says:
|
|
602 ;; MANWIDTH
|
|
603 ;; If $MANWIDTH is set, its value is used as the line
|
|
604 ;; length for which manual pages should be formatted.
|
|
605 ;; If it is not set, manual pages will be formatted
|
|
606 ;; with a line length appropriate to the current ter-
|
|
607 ;; minal (using an ioctl(2) if available, the value of
|
|
608 ;; $COLUMNS, or falling back to 80 characters if nei-
|
|
609 ;; ther is available).
|
|
610 (if window-system
|
|
611 (unless (or (getenv "MANWIDTH") (getenv "COLUMNS"))
|
|
612 ;; This isn't strictly correct, since we don't know how
|
|
613 ;; the page will actually be displayed, but it seems
|
|
614 ;; reasonable.
|
|
615 (setenv "COLUMNS" (number-to-string (frame-width)))))
|
16973
|
616 (if (fboundp 'start-process)
|
|
617 (set-process-sentinel
|
|
618 (start-process manual-program buffer "sh" "-c"
|
|
619 (format (Man-build-man-command) man-args))
|
|
620 'Man-bgproc-sentinel)
|
|
621 (progn
|
|
622 (let ((exit-status
|
|
623 (call-process shell-file-name nil (list buffer nil) nil "-c"
|
|
624 (format (Man-build-man-command) man-args)))
|
|
625 (msg ""))
|
|
626 (or (and (numberp exit-status)
|
|
627 (= exit-status 0))
|
|
628 (and (numberp exit-status)
|
|
629 (setq msg
|
|
630 (format "exited abnormally with code %d"
|
|
631 exit-status)))
|
|
632 (setq msg exit-status))
|
|
633 (Man-bgproc-sentinel bufname msg))))))))
|
3235
|
634
|
|
635 (defun Man-notify-when-ready (man-buffer)
|
|
636 "Notify the user when MAN-BUFFER is ready.
|
9003
|
637 See the variable `Man-notify-method' for the different notification behaviors."
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
638 (let ((saved-frame (save-excursion
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
639 (set-buffer man-buffer)
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
640 Man-original-frame)))
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
641 (cond
|
9003
|
642 ((eq Man-notify-method 'newframe)
|
8970
|
643 ;; Since we run asynchronously, perhaps while Emacs is waiting
|
|
644 ;; for input, we must not leave a different buffer current. We
|
|
645 ;; can't rely on the editor command loop to reselect the
|
|
646 ;; selected window's buffer.
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
647 (save-excursion
|
21581
|
648 (let ((frame (make-frame Man-frame-parameters)))
|
|
649 (set-window-buffer (frame-selected-window frame) man-buffer)
|
29973
|
650 (set-window-dedicated-p (frame-selected-window frame) t)
|
|
651 (or (display-multi-frame-p frame)
|
|
652 (select-frame frame)))))
|
9003
|
653 ((eq Man-notify-method 'pushy)
|
8970
|
654 (switch-to-buffer man-buffer))
|
9003
|
655 ((eq Man-notify-method 'bully)
|
29973
|
656 (and (frame-live-p saved-frame)
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
657 (select-frame saved-frame))
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
658 (pop-to-buffer man-buffer)
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
659 (delete-other-windows))
|
9003
|
660 ((eq Man-notify-method 'aggressive)
|
29973
|
661 (and (frame-live-p saved-frame)
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
662 (select-frame saved-frame))
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
663 (pop-to-buffer man-buffer))
|
9003
|
664 ((eq Man-notify-method 'friendly)
|
29973
|
665 (and (frame-live-p saved-frame)
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
666 (select-frame saved-frame))
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
667 (display-buffer man-buffer 'not-this-window))
|
9003
|
668 ((eq Man-notify-method 'polite)
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
669 (beep)
|
8970
|
670 (message "Manual buffer %s is ready" (buffer-name man-buffer)))
|
9003
|
671 ((eq Man-notify-method 'quiet)
|
8970
|
672 (message "Manual buffer %s is ready" (buffer-name man-buffer)))
|
9003
|
673 ((or (eq Man-notify-method 'meek)
|
8697
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
674 t)
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
675 (message ""))
|
c75e435af62f
(Man-notify-when-ready): Get Man-original-frame from the proper buffer.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
676 )))
|
3235
|
677
|
20154
|
678 (defun Man-softhyphen-to-minus ()
|
47891
|
679 ;; \255 is SOFT HYPHEN in Latin-N. Versions of Debian man, at
|
25202
|
680 ;; least, emit it even when not in a Latin-N locale.
|
|
681 (unless (eq t (compare-strings "latin-" 0 nil
|
|
682 current-language-environment 0 6 t))
|
|
683 (goto-char (point-min))
|
|
684 (let ((str "\255"))
|
|
685 (if enable-multibyte-characters
|
|
686 (setq str (string-as-multibyte str)))
|
|
687 (while (search-forward str nil t) (replace-match "-")))))
|
20154
|
688
|
8970
|
689 (defun Man-fontify-manpage ()
|
|
690 "Convert overstriking and underlining to the correct fonts.
|
|
691 Same for the ANSI bold and normal escape sequences."
|
|
692 (interactive)
|
|
693 (message "Please wait: making up the %s man page..." Man-arguments)
|
|
694 (goto-char (point-min))
|
|
695 (while (search-forward "\e[1m" nil t)
|
|
696 (delete-backward-char 4)
|
|
697 (put-text-property (point)
|
|
698 (progn (if (search-forward "\e[0m" nil 'move)
|
|
699 (delete-backward-char 4))
|
|
700 (point))
|
9726
|
701 'face Man-overstrike-face))
|
29524
|
702 (if (< (buffer-size) (position-bytes (point-max)))
|
|
703 ;; Multibyte characters exist.
|
|
704 (progn
|
|
705 (goto-char (point-min))
|
|
706 (while (search-forward "__\b\b" nil t)
|
|
707 (backward-delete-char 4)
|
|
708 (put-text-property (point) (1+ (point)) 'face Man-underline-face))
|
|
709 (goto-char (point-min))
|
|
710 (while (search-forward "\b\b__" nil t)
|
29525
|
711 (backward-delete-char 4)
|
29524
|
712 (put-text-property (1- (point)) (point) 'face Man-underline-face))))
|
8970
|
713 (goto-char (point-min))
|
|
714 (while (search-forward "_\b" nil t)
|
|
715 (backward-delete-char 2)
|
9726
|
716 (put-text-property (point) (1+ (point)) 'face Man-underline-face))
|
8970
|
717 (goto-char (point-min))
|
|
718 (while (search-forward "\b_" nil t)
|
|
719 (backward-delete-char 2)
|
9726
|
720 (put-text-property (1- (point)) (point) 'face Man-underline-face))
|
8970
|
721 (goto-char (point-min))
|
29519
|
722 (while (re-search-forward "\\(.\\)\\(\b+\\1\\)+" nil t)
|
9210
|
723 (replace-match "\\1")
|
9726
|
724 (put-text-property (1- (point)) (point) 'face Man-overstrike-face))
|
9210
|
725 (goto-char (point-min))
|
9867
|
726 (while (re-search-forward "o\b\\+\\|\\+\bo" nil t)
|
|
727 (replace-match "o")
|
8970
|
728 (put-text-property (1- (point)) (point) 'face 'bold))
|
9210
|
729 (goto-char (point-min))
|
9620
|
730 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t)
|
9177
|
731 (replace-match "+")
|
|
732 (put-text-property (1- (point)) (point) 'face 'bold))
|
41698
|
733 (goto-char (point-min))
|
|
734 ;; Try to recognize common forms of cross references.
|
|
735 (while (re-search-forward "\\w+([0-9].?)" nil t)
|
|
736 (put-text-property (match-beginning 0) (match-end 0)
|
|
737 'mouse-face 'highlight))
|
20154
|
738 (Man-softhyphen-to-minus)
|
8970
|
739 (message "%s man page made up" Man-arguments))
|
|
740
|
|
741 (defun Man-cleanup-manpage ()
|
|
742 "Remove overstriking and underlining from the current buffer."
|
|
743 (interactive)
|
9620
|
744 (message "Please wait: cleaning up the %s man page..."
|
|
745 Man-arguments)
|
9675
|
746 (if (or (interactive-p) (not Man-sed-script))
|
9620
|
747 (progn
|
|
748 (goto-char (point-min))
|
|
749 (while (search-forward "_\b" nil t) (backward-delete-char 2))
|
|
750 (goto-char (point-min))
|
|
751 (while (search-forward "\b_" nil t) (backward-delete-char 2))
|
|
752 (goto-char (point-min))
|
|
753 (while (re-search-forward "\\(.\\)\\(\b\\1\\)+" nil t)
|
|
754 (replace-match "\\1"))
|
|
755 (goto-char (point-min))
|
|
756 (while (re-search-forward "\e\\[[0-9]+m" nil t) (replace-match ""))
|
|
757 (goto-char (point-min))
|
9867
|
758 (while (re-search-forward "o\b\\+\\|\\+\bo" nil t) (replace-match "o"))
|
9620
|
759 ))
|
8970
|
760 (goto-char (point-min))
|
9620
|
761 (while (re-search-forward "[-|]\\(\b[-|]\\)+" nil t) (replace-match "+"))
|
20154
|
762 (Man-softhyphen-to-minus)
|
8970
|
763 (message "%s man page cleaned up" Man-arguments))
|
3909
|
764
|
3235
|
765 (defun Man-bgproc-sentinel (process msg)
|
16973
|
766 "Manpage background process sentinel.
|
28102
|
767 When manpage command is run asynchronously, PROCESS is the process
|
16973
|
768 object for the manpage command; when manpage command is run
|
|
769 synchronously, PROCESS is the name of the buffer where the manpage
|
|
770 command is run. Second argument MSG is the exit message of the
|
|
771 manpage command."
|
|
772 (let ((Man-buffer (if (stringp process) (get-buffer process)
|
|
773 (process-buffer process)))
|
3235
|
774 (delete-buff nil)
|
8190
|
775 (err-mess nil))
|
8970
|
776
|
3235
|
777 (if (null (buffer-name Man-buffer)) ;; deleted buffer
|
16973
|
778 (or (stringp process)
|
|
779 (set-process-buffer process nil))
|
8970
|
780
|
|
781 (save-excursion
|
|
782 (set-buffer Man-buffer)
|
10040
|
783 (let ((case-fold-search nil))
|
|
784 (goto-char (point-min))
|
|
785 (cond ((or (looking-at "No \\(manual \\)*entry for")
|
|
786 (looking-at "[^\n]*: nothing appropriate$"))
|
|
787 (setq err-mess (buffer-substring (point)
|
|
788 (progn
|
|
789 (end-of-line) (point)))
|
|
790 delete-buff t))
|
16973
|
791 ((or (stringp process)
|
|
792 (not (and (eq (process-status process) 'exit)
|
|
793 (= (process-exit-status process) 0))))
|
|
794 (or (zerop (length msg))
|
|
795 (progn
|
|
796 (setq err-mess
|
|
797 (concat (buffer-name Man-buffer)
|
|
798 ": process "
|
|
799 (let ((eos (1- (length msg))))
|
|
800 (if (= (aref msg eos) ?\n)
|
|
801 (substring msg 0 eos) msg))))
|
|
802 (goto-char (point-max))
|
|
803 (insert (format "\nprocess %s" msg))))
|
|
804 ))
|
16509
|
805 (if delete-buff
|
|
806 (kill-buffer Man-buffer)
|
|
807 (if Man-fontify-manpage-flag
|
|
808 (Man-fontify-manpage)
|
|
809 (Man-cleanup-manpage))
|
|
810 (run-hooks 'Man-cooked-hook)
|
|
811 (Man-mode)
|
|
812 (set-buffer-modified-p nil)
|
16973
|
813 ))
|
10040
|
814 ;; Restore case-fold-search before calling
|
|
815 ;; Man-notify-when-ready because it may switch buffers.
|
3235
|
816
|
10040
|
817 (if (not delete-buff)
|
|
818 (Man-notify-when-ready Man-buffer))
|
8970
|
819
|
10040
|
820 (if err-mess
|
|
821 (error err-mess))
|
|
822 ))))
|
3235
|
823
|
|
824
|
|
825 ;; ======================================================================
|
|
826 ;; set up manual mode in buffer and build alists
|
|
827
|
|
828 (defun Man-mode ()
|
3909
|
829 "A mode for browsing Un*x manual pages.
|
3235
|
830
|
28102
|
831 The following man commands are available in the buffer. Try
|
3235
|
832 \"\\[describe-key] <key> RET\" for more information:
|
|
833
|
8970
|
834 \\[man] Prompt to retrieve a new manpage.
|
3235
|
835 \\[Man-follow-manual-reference] Retrieve reference in SEE ALSO section.
|
|
836 \\[Man-next-manpage] Jump to next manpage in circular list.
|
|
837 \\[Man-previous-manpage] Jump to previous manpage in circular list.
|
|
838 \\[Man-next-section] Jump to next manpage section.
|
|
839 \\[Man-previous-section] Jump to previous manpage section.
|
|
840 \\[Man-goto-section] Go to a manpage section.
|
|
841 \\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section.
|
8970
|
842 \\[Man-quit] Deletes the manpage window, bury its buffer.
|
|
843 \\[Man-kill] Deletes the manpage window, kill its buffer.
|
3235
|
844 \\[describe-mode] Prints this help text.
|
|
845
|
28102
|
846 The following variables may be of some use. Try
|
3235
|
847 \"\\[describe-variable] <variable-name> RET\" for more information:
|
|
848
|
28102
|
849 `Man-notify-method' What happens when manpage formatting is done.
|
|
850 `Man-downcase-section-letters-flag' Force section letters to lower case.
|
|
851 `Man-circular-pages-flag' Treat multiple manpage list as circular.
|
|
852 `Man-section-translations-alist' List of section numbers and their Un*x equiv.
|
|
853 `Man-filter-list' Background manpage filter command.
|
|
854 `Man-mode-map' Keymap bindings for Man mode buffers.
|
|
855 `Man-mode-hook' Normal hook run on entry to Man mode.
|
|
856 `Man-section-regexp' Regexp describing manpage section letters.
|
|
857 `Man-heading-regexp' Regexp describing section headers.
|
|
858 `Man-see-also-regexp' Regexp for SEE ALSO section (or your equiv).
|
|
859 `Man-first-heading-regexp' Regexp for first heading on a manpage.
|
|
860 `Man-reference-regexp' Regexp matching a references in SEE ALSO.
|
|
861 `Man-switches' Background `man' command switches.
|
3235
|
862
|
|
863 The following key bindings are currently in effect in the buffer:
|
|
864 \\{Man-mode-map}"
|
|
865 (interactive)
|
|
866 (setq major-mode 'Man-mode
|
3909
|
867 mode-name "Man"
|
3235
|
868 buffer-auto-save-file-name nil
|
38970
|
869 mode-line-buffer-identification
|
|
870 (list (default-value 'mode-line-buffer-identification)
|
|
871 " {" 'Man-page-mode-string "}")
|
3235
|
872 truncate-lines t
|
|
873 buffer-read-only t)
|
|
874 (buffer-disable-undo (current-buffer))
|
|
875 (auto-fill-mode -1)
|
|
876 (use-local-map Man-mode-map)
|
17132
|
877 (set-syntax-table man-mode-syntax-table)
|
3235
|
878 (Man-build-page-list)
|
8970
|
879 (Man-strip-page-headers)
|
|
880 (Man-unindent)
|
3619
|
881 (Man-goto-page 1)
|
|
882 (run-hooks 'Man-mode-hook))
|
3235
|
883
|
8970
|
884 (defsubst Man-build-section-alist ()
|
3235
|
885 "Build the association list of manpage sections."
|
|
886 (setq Man-sections-alist nil)
|
|
887 (goto-char (point-min))
|
7450
|
888 (let ((case-fold-search nil))
|
|
889 (while (re-search-forward Man-heading-regexp (point-max) t)
|
41710
6515e3108ceb
(Man-build-section-alist): Remove last Man-match-substring.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
890 (aput 'Man-sections-alist (match-string 1))
|
7450
|
891 (forward-line 1))))
|
3235
|
892
|
8970
|
893 (defsubst Man-build-references-alist ()
|
3235
|
894 "Build the association list of references (in the SEE ALSO section)."
|
|
895 (setq Man-refpages-alist nil)
|
|
896 (save-excursion
|
|
897 (if (Man-find-section Man-see-also-regexp)
|
|
898 (let ((start (progn (forward-line 1) (point)))
|
|
899 (end (progn
|
|
900 (Man-next-section 1)
|
|
901 (point)))
|
|
902 hyphenated
|
|
903 (runningpoint -1))
|
7450
|
904 (save-restriction
|
|
905 (narrow-to-region start end)
|
|
906 (goto-char (point-min))
|
|
907 (back-to-indentation)
|
|
908 (while (and (not (eobp)) (/= (point) runningpoint))
|
|
909 (setq runningpoint (point))
|
36575
|
910 (if (re-search-forward Man-hyphenated-reference-regexp end t)
|
41698
|
911 (let* ((word (match-string 0))
|
8970
|
912 (len (1- (length word))))
|
|
913 (if hyphenated
|
|
914 (setq word (concat hyphenated word)
|
36575
|
915 hyphenated nil
|
|
916 ;; Update len, in case a reference spans
|
|
917 ;; more than two lines (paranoia).
|
|
918 len (1- (length word))))
|
8970
|
919 (if (= (aref word len) ?-)
|
36575
|
920 (setq hyphenated (substring word 0 len)))
|
|
921 (if (string-match Man-reference-regexp word)
|
|
922 (aput 'Man-refpages-alist word))))
|
|
923 (skip-chars-forward " \t\n,"))))))
|
|
924 (setq Man-refpages-alist (nreverse Man-refpages-alist)))
|
3235
|
925
|
9354
|
926 (defun Man-build-page-list ()
|
3235
|
927 "Build the list of separate manpages in the buffer."
|
|
928 (setq Man-page-list nil)
|
8970
|
929 (let ((page-start (point-min))
|
|
930 (page-end (point-max))
|
|
931 (header ""))
|
|
932 (goto-char page-start)
|
|
933 ;; (switch-to-buffer (current-buffer))(debug)
|
|
934 (while (not (eobp))
|
|
935 (setq header
|
|
936 (if (looking-at Man-page-header-regexp)
|
41698
|
937 (match-string 1)
|
8970
|
938 nil))
|
|
939 ;; Go past both the current and the next Man-first-heading-regexp
|
|
940 (if (re-search-forward Man-first-heading-regexp nil 'move 2)
|
|
941 (let ((p (progn (beginning-of-line) (point))))
|
|
942 ;; We assume that the page header is delimited by blank
|
|
943 ;; lines and that it contains at most one blank line. So
|
|
944 ;; if we back by three blank lines we will be sure to be
|
|
945 ;; before the page header but not before the possible
|
|
946 ;; previous page header.
|
|
947 (search-backward "\n\n" nil t 3)
|
|
948 (if (re-search-forward Man-page-header-regexp p 'move)
|
|
949 (beginning-of-line))))
|
|
950 (setq page-end (point))
|
|
951 (setq Man-page-list (append Man-page-list
|
|
952 (list (list (copy-marker page-start)
|
|
953 (copy-marker page-end)
|
|
954 header))))
|
|
955 (setq page-start page-end)
|
|
956 )))
|
|
957
|
9354
|
958 (defun Man-strip-page-headers ()
|
8970
|
959 "Strip all the page headers but the first from the manpage."
|
|
960 (let ((buffer-read-only nil)
|
|
961 (case-fold-search nil)
|
|
962 (page-list Man-page-list)
|
|
963 (page ())
|
|
964 (header ""))
|
|
965 (while page-list
|
|
966 (setq page (car page-list))
|
|
967 (and (nth 2 page)
|
|
968 (goto-char (car page))
|
|
969 (re-search-forward Man-first-heading-regexp nil t)
|
|
970 (setq header (buffer-substring (car page) (match-beginning 0)))
|
|
971 ;; Since the awk script collapses all successive blank
|
|
972 ;; lines into one, and since we don't want to get rid of
|
|
973 ;; the fast awk script, one must choose between adding
|
|
974 ;; spare blank lines between pages when there were none and
|
|
975 ;; deleting blank lines at page boundaries when there were
|
|
976 ;; some. We choose the first, so we comment the following
|
|
977 ;; line.
|
|
978 ;; (setq header (concat "\n" header)))
|
|
979 (while (search-forward header (nth 1 page) t)
|
|
980 (replace-match "")))
|
|
981 (setq page-list (cdr page-list)))))
|
|
982
|
9354
|
983 (defun Man-unindent ()
|
8970
|
984 "Delete the leading spaces that indent the manpage."
|
|
985 (let ((buffer-read-only nil)
|
|
986 (case-fold-search nil)
|
|
987 (page-list Man-page-list))
|
|
988 (while page-list
|
|
989 (let ((page (car page-list))
|
|
990 (indent "")
|
|
991 (nindent 0))
|
|
992 (narrow-to-region (car page) (car (cdr page)))
|
|
993 (if Man-uses-untabify-flag
|
|
994 (untabify (point-min) (point-max)))
|
|
995 (if (catch 'unindent
|
|
996 (goto-char (point-min))
|
|
997 (if (not (re-search-forward Man-first-heading-regexp nil t))
|
|
998 (throw 'unindent nil))
|
|
999 (beginning-of-line)
|
|
1000 (setq indent (buffer-substring (point)
|
|
1001 (progn
|
|
1002 (skip-chars-forward " ")
|
|
1003 (point))))
|
|
1004 (setq nindent (length indent))
|
|
1005 (if (zerop nindent)
|
|
1006 (throw 'unindent nil))
|
|
1007 (setq indent (concat indent "\\|$"))
|
|
1008 (goto-char (point-min))
|
|
1009 (while (not (eobp))
|
|
1010 (if (looking-at indent)
|
|
1011 (forward-line 1)
|
|
1012 (throw 'unindent nil)))
|
|
1013 (goto-char (point-min)))
|
|
1014 (while (not (eobp))
|
|
1015 (or (eolp)
|
|
1016 (delete-char nindent))
|
|
1017 (forward-line 1)))
|
|
1018 (setq page-list (cdr page-list))
|
7450
|
1019 ))))
|
3235
|
1020
|
|
1021
|
|
1022 ;; ======================================================================
|
5269
|
1023 ;; Man mode commands
|
3235
|
1024
|
|
1025 (defun Man-next-section (n)
|
|
1026 "Move point to Nth next section (default 1)."
|
|
1027 (interactive "p")
|
7450
|
1028 (let ((case-fold-search nil))
|
|
1029 (if (looking-at Man-heading-regexp)
|
|
1030 (forward-line 1))
|
|
1031 (if (re-search-forward Man-heading-regexp (point-max) t n)
|
|
1032 (beginning-of-line)
|
|
1033 (goto-char (point-max)))))
|
3235
|
1034
|
|
1035 (defun Man-previous-section (n)
|
|
1036 "Move point to Nth previous section (default 1)."
|
|
1037 (interactive "p")
|
7450
|
1038 (let ((case-fold-search nil))
|
|
1039 (if (looking-at Man-heading-regexp)
|
|
1040 (forward-line -1))
|
|
1041 (if (re-search-backward Man-heading-regexp (point-min) t n)
|
|
1042 (beginning-of-line)
|
|
1043 (goto-char (point-min)))))
|
3235
|
1044
|
|
1045 (defun Man-find-section (section)
|
|
1046 "Move point to SECTION if it exists, otherwise don't move point.
|
|
1047 Returns t if section is found, nil otherwise."
|
7450
|
1048 (let ((curpos (point))
|
|
1049 (case-fold-search nil))
|
3235
|
1050 (goto-char (point-min))
|
8970
|
1051 (if (re-search-forward (concat "^" section) (point-max) t)
|
3235
|
1052 (progn (beginning-of-line) t)
|
|
1053 (goto-char curpos)
|
|
1054 nil)
|
|
1055 ))
|
|
1056
|
|
1057 (defun Man-goto-section ()
|
|
1058 "Query for section to move point to."
|
|
1059 (interactive)
|
|
1060 (aput 'Man-sections-alist
|
|
1061 (let* ((default (aheadsym Man-sections-alist))
|
|
1062 (completion-ignore-case t)
|
|
1063 chosen
|
|
1064 (prompt (concat "Go to section: (default " default ") ")))
|
|
1065 (setq chosen (completing-read prompt Man-sections-alist))
|
|
1066 (if (or (not chosen)
|
|
1067 (string= chosen ""))
|
|
1068 default
|
|
1069 chosen)))
|
|
1070 (Man-find-section (aheadsym Man-sections-alist)))
|
|
1071
|
|
1072 (defun Man-goto-see-also-section ()
|
42706
|
1073 "Move point to the \"SEE ALSO\" section.
|
3909
|
1074 Actually the section moved to is described by `Man-see-also-regexp'."
|
3235
|
1075 (interactive)
|
|
1076 (if (not (Man-find-section Man-see-also-regexp))
|
|
1077 (error (concat "No " Man-see-also-regexp
|
8970
|
1078 " section found in the current manpage"))))
|
3235
|
1079
|
36575
|
1080 (defun Man-possibly-hyphenated-word ()
|
|
1081 "Return a possibly hyphenated word at point.
|
|
1082 If the word starts at the first non-whitespace column, and the
|
|
1083 previous line ends with a hyphen, return the last word on the previous
|
|
1084 line instead. Thus, if a reference to \"tcgetpgrp(3V)\" is hyphenated
|
|
1085 as \"tcgetp-grp(3V)\", and point is at \"grp(3V)\", we return
|
|
1086 \"tcgetp-\" instead of \"grp\"."
|
|
1087 (save-excursion
|
|
1088 (skip-syntax-backward "w()")
|
|
1089 (skip-chars-forward " \t")
|
|
1090 (let ((beg (point))
|
|
1091 (word (current-word)))
|
|
1092 (when (eq beg (save-excursion
|
|
1093 (back-to-indentation)
|
|
1094 (point)))
|
|
1095 (end-of-line 0)
|
|
1096 (if (eq (char-before) ?-)
|
|
1097 (setq word (current-word))))
|
|
1098 word)))
|
|
1099
|
9838
|
1100 (defun Man-follow-manual-reference (reference)
|
3235
|
1101 "Get one of the manpages referred to in the \"SEE ALSO\" section.
|
28102
|
1102 Specify which REFERENCE to use; default is based on word at point."
|
5269
|
1103 (interactive
|
|
1104 (if (not Man-refpages-alist)
|
8970
|
1105 (error "There are no references in the current man page")
|
9838
|
1106 (list (let* ((default (or
|
36575
|
1107 (car (all-completions
|
|
1108 (let ((word (Man-possibly-hyphenated-word)))
|
|
1109 ;; strip a trailing '-':
|
|
1110 (if (string-match "-$" word)
|
|
1111 (substring word 0
|
|
1112 (match-beginning 0))
|
|
1113 word))
|
|
1114 Man-refpages-alist))
|
|
1115 (aheadsym Man-refpages-alist)))
|
5269
|
1116 chosen
|
|
1117 (prompt (concat "Refer to: (default " default ") ")))
|
|
1118 (setq chosen (completing-read prompt Man-refpages-alist nil t))
|
|
1119 (if (or (not chosen)
|
|
1120 (string= chosen ""))
|
|
1121 default
|
|
1122 chosen)))))
|
3235
|
1123 (if (not Man-refpages-alist)
|
8970
|
1124 (error "Can't find any references in the current manpage")
|
5269
|
1125 (aput 'Man-refpages-alist reference)
|
3235
|
1126 (Man-getpage-in-background
|
9838
|
1127 (Man-translate-references (aheadsym Man-refpages-alist)))))
|
3235
|
1128
|
8970
|
1129 (defun Man-kill ()
|
3235
|
1130 "Kill the buffer containing the manpage."
|
|
1131 (interactive)
|
22368
|
1132 (quit-window t))
|
8970
|
1133
|
|
1134 (defun Man-quit ()
|
|
1135 "Bury the buffer containing the manpage."
|
|
1136 (interactive)
|
22368
|
1137 (quit-window))
|
3235
|
1138
|
|
1139 (defun Man-goto-page (page)
|
|
1140 "Go to the manual page on page PAGE."
|
|
1141 (interactive
|
8970
|
1142 (if (not Man-page-list)
|
|
1143 (let ((args Man-arguments))
|
|
1144 (kill-buffer (current-buffer))
|
|
1145 (error "Can't find the %s manpage" args))
|
|
1146 (if (= (length Man-page-list) 1)
|
|
1147 (error "You're looking at the only manpage in the buffer")
|
|
1148 (list (read-minibuffer (format "Go to manpage [1-%d]: "
|
|
1149 (length Man-page-list)))))))
|
|
1150 (if (not Man-page-list)
|
|
1151 (let ((args Man-arguments))
|
|
1152 (kill-buffer (current-buffer))
|
|
1153 (error "Can't find the %s manpage" args)))
|
3235
|
1154 (if (or (< page 1)
|
|
1155 (> page (length Man-page-list)))
|
|
1156 (error "No manpage %d found" page))
|
|
1157 (let* ((page-range (nth (1- page) Man-page-list))
|
|
1158 (page-start (car page-range))
|
8970
|
1159 (page-end (car (cdr page-range))))
|
3235
|
1160 (setq Man-current-page page
|
8970
|
1161 Man-page-mode-string (Man-make-page-mode-string))
|
3235
|
1162 (widen)
|
|
1163 (goto-char page-start)
|
|
1164 (narrow-to-region page-start page-end)
|
|
1165 (Man-build-section-alist)
|
8970
|
1166 (Man-build-references-alist)
|
3235
|
1167 (goto-char (point-min))))
|
|
1168
|
|
1169
|
|
1170 (defun Man-next-manpage ()
|
|
1171 "Find the next manpage entry in the buffer."
|
|
1172 (interactive)
|
|
1173 (if (= (length Man-page-list) 1)
|
7499
|
1174 (error "This is the only manpage in the buffer"))
|
3235
|
1175 (if (< Man-current-page (length Man-page-list))
|
|
1176 (Man-goto-page (1+ Man-current-page))
|
8970
|
1177 (if Man-circular-pages-flag
|
3235
|
1178 (Man-goto-page 1)
|
7499
|
1179 (error "You're looking at the last manpage in the buffer"))))
|
3235
|
1180
|
|
1181 (defun Man-previous-manpage ()
|
|
1182 "Find the previous manpage entry in the buffer."
|
|
1183 (interactive)
|
|
1184 (if (= (length Man-page-list) 1)
|
7499
|
1185 (error "This is the only manpage in the buffer"))
|
3235
|
1186 (if (> Man-current-page 1)
|
|
1187 (Man-goto-page (1- Man-current-page))
|
8970
|
1188 (if Man-circular-pages-flag
|
3235
|
1189 (Man-goto-page (length Man-page-list))
|
7499
|
1190 (error "You're looking at the first manpage in the buffer"))))
|
3833
|
1191
|
14672
|
1192 ;; Init the man package variables, if not already done.
|
|
1193 (Man-init-defvars)
|
|
1194
|
28102
|
1195 (add-to-list 'debug-ignored-errors "^No manpage [0-9]* found$")
|
|
1196 (add-to-list 'debug-ignored-errors "^Can't find the .* manpage$")
|
|
1197
|
3833
|
1198 (provide 'man)
|
|
1199
|
3235
|
1200 ;;; man.el ends here
|