Resolve cvs commit conflict. (Fix buggy calls to error.)
[bpt/emacs.git] / lisp / man.el
CommitLineData
665a7c3b 1;;; man.el --- browse UNIX manual pages -*- coding: iso-8859-1 -*-
55535639 2
0d30b337 3;; Copyright (C) 1993, 1994, 1996, 1997, 2001, 2002, 2003,
d7a0267c 4;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
55535639
PJ
5
6;; Author: Barry A. Warsaw <bwarsaw@cen.com>
7;; Maintainer: FSF
8;; Keywords: help
9;; Adapted-By: ESR, pot
10
11;; This file is part of GNU Emacs.
12
13;; GNU Emacs is free software; you can redistribute it and/or modify
14;; it under the terms of the GNU General Public License as published by
b4aa6026 15;; the Free Software Foundation; either version 3, or (at your option)
55535639
PJ
16;; any later version.
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
24;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
25;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26;; Boston, MA 02110-1301, USA.
55535639
PJ
27
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.
33;;
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
a88459cd 40;; man.el from the standard Emacs 18.57 distribution. I liked many of
55535639
PJ
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
4cb071a4 67;; is done in the background. The cleaning commands are configurable.
55535639
PJ
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.
76
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
72397ff1 85;; the number of blank lines before the page footer by heuristics
55535639
PJ
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.
94
95\f
96;;; Code:
97
079c2d00 98(eval-when-compile (require 'cl))
55535639 99(require 'assoc)
4edd9faf 100(require 'button)
55535639
PJ
101
102;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
103;; empty defvars (keep the compiler quiet)
104
105(defgroup man nil
106 "Browse UNIX manual pages."
107 :prefix "Man-"
108 :group 'help)
109
110
111(defvar Man-notify)
55535639
PJ
112(defcustom Man-filter-list nil
113 "*Manpage cleaning filter command phrases.
114This variable contains a list of the following form:
115
116'((command-string phrase-string*)*)
117
118Each phrase-string is concatenated onto the command-string to form a
119command filter. The (standard) output (and standard error) of the Un*x
120man command is piped through each command filter in the order the
121commands appear in the association list. The final output is placed in
122the manpage buffer."
123 :type '(repeat (list (string :tag "Command String")
124 (repeat :inline t
125 (string :tag "Phrase String"))))
126 :group 'man)
127
55535639
PJ
128(defvar Man-uses-untabify-flag t
129 "Non-nil means use `untabify' instead of `Man-untabify-command'.")
55535639
PJ
130(defvar Man-sed-script nil
131 "Script for sed to nuke backspaces and ANSI codes from manpages.")
132
133;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
134;; user variables
135
136(defcustom Man-fontify-manpage-flag t
a88459cd 137 "Non-nil means make up the manpage with fonts."
55535639
PJ
138 :type 'boolean
139 :group 'man)
140
141(defcustom Man-overstrike-face 'bold
a88459cd 142 "Face to use when fontifying overstrike."
55535639
PJ
143 :type 'face
144 :group 'man)
145
146(defcustom Man-underline-face 'underline
a88459cd 147 "Face to use when fontifying underlining."
55535639
PJ
148 :type 'face
149 :group 'man)
150
8d2a4f61 151(defcustom Man-reverse-face 'highlight
a88459cd 152 "Face to use when fontifying reverse video."
079c2d00
SM
153 :type 'face
154 :group 'man)
155
55535639
PJ
156;; Use the value of the obsolete user option Man-notify, if set.
157(defcustom Man-notify-method (if (boundp 'Man-notify) Man-notify 'friendly)
a88459cd 158 "Selects the behavior when manpage is ready.
55535639
PJ
159This variable may have one of the following values, where (sf) means
160that the frames are switched, so the manpage is displayed in the frame
161where the man command was called from:
162
163newframe -- put the manpage in its own frame (see `Man-frame-parameters')
164pushy -- make the manpage the current buffer in the current window
165bully -- make the manpage the current buffer and only window (sf)
166aggressive -- make the manpage the current buffer in the other window (sf)
167friendly -- display manpage in the other window but don't make current (sf)
168polite -- don't display manpage, but prints message and beep when ready
169quiet -- like `polite', but don't beep
170meek -- make no indication that the manpage is ready
171
172Any other value of `Man-notify-method' is equivalent to `meek'."
173 :type '(radio (const newframe) (const pushy) (const bully)
174 (const aggressive) (const friendly)
175 (const polite) (const quiet) (const meek))
176 :group 'man)
177
aec2bd36 178(defcustom Man-width nil
a88459cd 179 "Number of columns for which manual pages should be formatted.
aec2bd36
JL
180If nil, the width of the window selected at the moment of man
181invocation is used. If non-nil, the width of the frame selected
182at the moment of man invocation is used. The value also can be a
183positive integer."
184 :type '(choice (const :tag "Window width" nil)
185 (const :tag "Frame width" t)
186 (integer :tag "Specific width" :value 65))
187 :group 'man)
188
55535639 189(defcustom Man-frame-parameters nil
a88459cd 190 "Frame parameter list for creating a new frame for a manual page."
55535639
PJ
191 :type 'sexp
192 :group 'man)
193
194(defcustom Man-downcase-section-letters-flag t
a88459cd 195 "Non-nil means letters in sections are converted to lower case.
55535639
PJ
196Some Un*x man commands can't handle uppercase letters in sections, for
197example \"man 2V chmod\", but they are often displayed in the manpage
198with the upper case letter. When this variable is t, the section
199letter (e.g., \"2V\") is converted to lowercase (e.g., \"2v\") before
200being sent to the man background process."
201 :type 'boolean
202 :group 'man)
203
204(defcustom Man-circular-pages-flag t
a88459cd 205 "Non-nil means the manpage list is treated as circular for traversal."
55535639
PJ
206 :type 'boolean
207 :group 'man)
208
209(defcustom Man-section-translations-alist
210 (list
211 '("3C++" . "3")
212 ;; Some systems have a real 3x man section, so let's comment this.
213 ;; '("3X" . "3") ; Xlib man pages
214 '("3X11" . "3")
215 '("1-UCB" . ""))
a88459cd 216 "Association list of bogus sections to real section numbers.
55535639
PJ
217Some manpages (e.g. the Sun C++ 2.1 manpages) have section numbers in
218their references which Un*x `man' does not recognize. This
219association list is used to translate those sections, when found, to
220the associated section number."
221 :type '(repeat (cons (string :tag "Bogus Section")
222 (string :tag "Real Section")))
223 :group 'man)
224
4edd9faf
JB
225(defcustom Man-header-file-path
226 '("/usr/include" "/usr/local/include")
227 "C Header file search path used in Man."
228 :type '(repeat string)
229 :group 'man)
230
55535639
PJ
231(defvar manual-program "man"
232 "The name of the program that produces man pages.")
233
234(defvar Man-untabify-command "pr"
235 "Command used for untabifying.")
236
237(defvar Man-untabify-command-args (list "-t" "-e")
238 "List of arguments to be passed to `Man-untabify-command' (which see).")
239
240(defvar Man-sed-command "sed"
241 "Command used for processing sed scripts.")
242
243(defvar Man-awk-command "awk"
244 "Command used for processing awk scripts.")
245
55535639
PJ
246(defvar Man-mode-hook nil
247 "Hook run when Man mode is enabled.")
248
249(defvar Man-cooked-hook nil
250 "Hook run after removing backspaces but before `Man-mode' processing.")
251
5f43c63c 252