annotate lisp/packages/man.el @ 193:f53b5ca2e663 r20-3b23

Import from CVS: tag r20-3b23
author cvs
date Mon, 13 Aug 2007 09:58:30 +0200
parents 489f57a838ef
children a2f645c6b9f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; man.el --- browse UNIX manual pages
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2 ;; Keywords: help
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
4 ;; Copyright (C) 1985, 1993, 1994, 1996, 1997 Free Software Foundation, Inc.
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
5 ;;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
22 ;; This file defines "manual-entry", and the remaining definitions all
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
23 ;; begin with "Manual-". This makes the autocompletion on "M-x man" work.
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
24 ;;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
25 ;; Eviscerated 26-Jun-96 by Jamie Zawinski <jwz@netscape.com>.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
26 ;; All that stuff about looking at $MANPATH and building up lists of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
27 ;; directories was bullshit. Now we just invoke "man" and format the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
28 ;; output, end of story.
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
29 ;;
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
30 ;; [ older changelog entries removed, since they're all about code that
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
31 ;; I've deleted. ]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
33 (defgroup man nil
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
34 "Browse Unix manual pages"
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
35 :group 'help)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
36
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
37 (defcustom Manual-program "man" "\
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
38 *Name of the program to invoke in order to format the source man pages."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
39 :type 'string
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
40 :group 'man)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
41
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
42 (defcustom Manual-buffer-view-mode t "\
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
43 *Whether manual buffers should be placed in view-mode.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
44 nil means leave the buffer in fundamental-mode in another window.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
45 t means use `view-buffer' to display the man page in the current window.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
46 Any other value means use `view-buffer-other-window'."
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
47 :type '(radio (const :tag "Fundamental-mode other window" nil)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
48 (const :tag "View-mode current window" t)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
49 (sexp :format "%t\n" :tag "View-mode other window" other))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
50 :group 'man)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
51
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
52 (defcustom Manual-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
53 "Function or functions run on entry to Manual-mode."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
54 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
55 :group 'man)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
57 (defvar Manual-page-history nil "\
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
58 A list of names of previously visited man page buffers.")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
59
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
60 (defvar Manual-page-minibuffer-history nil "\
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
61 Minibuffer completion history for `manual-entry'.")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
62
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
63 ;; New variables.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
64
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
65 (defcustom Manual-snip-subchapter
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
66 (not (string-match "solaris" system-configuration))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
67 "*Should man look in chapter 3 for ctime(3c)?
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
68 This is relavent for Solaris and, perhaps, other systems which have
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
69 `man -s 3' not find things in chapter 3c, or other such sub-chapters"
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
70 :type 'boolean
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
71 :group 'man)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
72
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
73 (defcustom Manual-buffers-have-stars nil
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
74 "*When T, manual page buffers are always named like *man*.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
75 Otherwise, they are not if `buffers-menu-submenus-for-groups-p' is T,
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
76 so that Manual-mode buffers will have their own submenu."
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
77 :type 'boolean
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
78 :group 'man)
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
79
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
80 (defcustom Manual-buffers-have-prefix t
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
81 "*When non-nil, manual page buffers are named with a prefix of `man '.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
82 Otherwise, their titles do not have this prefix."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
83 :type 'boolean
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
84 :group 'man)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
85
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
86 ;;Here is information on RosettaMan, from Neal.Becker@comsat.com (Neal Becker):
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
87
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
88 ;;RosettaMan is a filter for UNIX manual pages. It takes as input man
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
89 ;;pages formatted for a variety of UNIX flavors (not [tn]roff source)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
90 ;;and produces as output a variety of file formats. Currently
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
91 ;;RosettaMan accepts man pages as formatted by the following flavors of
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
92 ;;UNIX: Hewlett-Packard HP-UX, AT&T System V, SunOS, Sun Solaris, OSF/1,
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
93 ;;DEC Ultrix, SGI IRIX, Linux, SCO; and produces output for the following
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
94 ;;formats: printable ASCII only (stripping page headers and footers),
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
95 ;;section and subsection headers only, TkMan, [tn]roff, Ensemble, RTF,
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
96 ;;SGML (soon--I finally found a DTD), HTML, MIME, LaTeX, LaTeX 2e, Perl 5's pod.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
97
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
98 ;;RosettaMan improves on other man page filters in several ways: (1) its
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
99 ;;analysis recognizes the structural pieces of man pages, enabling high
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
100 ;;quality output, (2) its modular structure permits easy augmentation of
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
101 ;;output formats, (3) it accepts man pages formatted with the varient
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
102 ;;macros of many different flavors of UNIX, and (4) it doesn't require
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
103 ;;modification or cooperation with any other program.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
104
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
105 ;;RosettaMan is a rewrite of TkMan's man page filter, called bs2tk. (If
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
106 ;;you haven't heard about TkMan, a hypertext man page browser, you
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
107 ;;should grab it via anonymous ftp from ftp.cs.berkeley.edu:
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
108 ;;/ucb/people/phelps/tkman.tar.Z.) Whereas bs2tk generated output only for
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
109 ;;TkMan, RosettaMan generalizes the process so that the analysis can be
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
110 ;;leveraged to new output formats. A single analysis engine recognizes
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
111 ;;section heads, subsection heads, body text, lists, references to other
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
112 ;;man pages, boldface, italics, bold italics, special characters (like
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
113 ;;bullets), tables (to a degree) and strips out page headers and
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
114 ;;footers. The engine sends signals to the selected output functions so
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
115 ;;that an enhancement in the engine improves the quality of output of
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
116 ;;all of them. Output format functions are easy to add, and thus far
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
117 ;;average about about 75 lines of C code each.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
118
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
119
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
120
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
121 ;;*** NOTES ON CURRENT VERSION ***
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
122
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
123 ;;Help! I'm looking for people to help with the following projects.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
124 ;;\(1) Better RTF output format. The current one works, but could be
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
125 ;;made better. (2) Roff macros that produce text that is easily
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
126 ;;parsable. RosettaMan handles a great variety, but some things, like
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
127 ;;H-P's tables, are intractable. If you write an output format or
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
128 ;;otherwise improve RosettaMan, please send in your code so that I may
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
129 ;;share the wealth in future releases.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
130
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
131 ;;This version can try to identify tables (turn this on with the -T
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
132 ;;switch) by looking for lines with a large amount of interword spacing,
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
133 ;;reasoning that this is space between columns of a table. This
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
134 ;;heuristic doesn't always work and sometimes misidentifies ordinary
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
135 ;;text as tables. In general I think it is impossible to perfectly
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
136 ;;identify tables from nroff formatted text. However, I do think the
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
137 ;;heuristics can be tuned, so if you have a collection of manual pages
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
138 ;;with unrecognized tables, send me the lot, in formatted form (i.e.,
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
139 ;;after formatting with nroff -man), and uuencode them to preserve the
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
140 ;;control characters. Better, if you can think of heuristics that
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
141 ;;distinguish tables from ordinary text, I'd like to hear them.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
142
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
143 ;;Notes for HTML consumers: This filter does real (heuristic)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
144 ;;parsing--no <PRE>! Man page references are turned into hypertext links.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
145
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
146 (defcustom Manual-use-rosetta-man (not (null (locate-file "rman" exec-path))) "\
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
147 If non-nil, use RosettaMan (rman) to filter man pages.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
148 This makes man-page cleanup virtually instantaneous, instead of
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
149 potentially taking a long time."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
150 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
151 :group 'man)
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
152
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
153 (defface man-italic '((t (:italic t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
154 "Manual italics face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
155 :group 'man)
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 8
diff changeset
156
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
157 (defface man-bold '((t (:bold t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
158 "Manual bold face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
159 :group 'man)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
161 (defface man-heading '((t (:bold t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
162 "Manual headings face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
163 :group 'man)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
165 (defface man-xref '((t (:underline t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
166 "Manual xrefs face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
167 :group 'man)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
168
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
169
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
170 (defvar Manual-mode-map
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
171 (let ((m (make-sparse-keymap)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
172 (set-keymap-name m 'Manual-mode-map)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
173 (define-key m "l" 'Manual-last-page)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
174 (define-key m 'button2 'Manual-follow-xref)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
175 (define-key m 'button3 'Manual-popup-menu)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
176 m))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;;###autoload
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
179 (defun manual-entry (topic &optional arg silent)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
180 "Display the Unix manual entry (or entries) for TOPIC."
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
181 (interactive
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
182 (list (let* ((fmh "-A-Za-z0-9_.:")
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
183 (default (save-excursion
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
184 (buffer-substring
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
185 (progn
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
186 (re-search-backward "\\sw" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
187 (skip-chars-backward fmh) (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
188 (progn (skip-chars-forward fmh) (point)))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
189 (thing (read-string
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
190 (if (equal default "") "Manual entry: "
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
191 (concat "Manual entry: (default " default ") "))
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
192 nil 'Manual-page-minibuffer-history)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
193 (if (equal thing "") default thing))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
194 (prefix-numeric-value current-prefix-arg)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
195 (or arg (setq arg 1))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
196 (let (section apropos-mode)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
197 (let ((case-fold-search nil))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
198 (if (and (null section)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
199 (string-match "\\`[ \t]*\\([^( \t]+\\)[ \t]*(\\(.+\\))[ \t]*\\'"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
200 topic))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
201 (setq section (match-string 2 topic)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
202 topic (match-string 1 topic))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
203 (if (string-match "\\`[ \t]*-k[ \t]+\\([^ \t]+\\)\\'" topic)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
204 (setq section "-k"
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
205 topic (match-string 1 topic)))))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
206
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
207 (when Manual-snip-subchapter
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
208 ;; jwz: turn section "3x11" and "3n" into "3".
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
209 (if (and section (string-match "\\`\\([0-9]+\\)[^0-9]" section))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
210 (setq section (match-string 1 section))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
211
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
212 (if (equal section "-k")
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
213 (setq apropos-mode t))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
214
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
215 (let ((bufname (flet
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
216 ((maybe-star ()
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
217 (if (or Manual-buffers-have-stars
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
218 (not buffers-menu-submenus-for-groups-p))
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
219 "*"
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
220 "")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
221 (if apropos-mode
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
222 (concat (maybe-star) "man apropos " topic (maybe-star))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
223 (concat (maybe-star)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
224 (if Manual-buffers-have-prefix
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
225 "man ")
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
226 topic
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
227 (if section (concat "(" section ")") "")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
228 (maybe-star)))))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
229 (temp-buffer-show-function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
230 (cond ((eq 't Manual-buffer-view-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
231 'view-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
232 ((eq 'nil Manual-buffer-view-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
233 temp-buffer-show-function)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
234 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
235 'view-buffer-other-window))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
236
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
237 (cond ((get-buffer bufname)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
238 ;; reselect an old man page buffer if it exists already.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
239 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
240 (set-buffer (get-buffer bufname))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
241 (Manual-mode))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
242 (if temp-buffer-show-function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
243 (funcall temp-buffer-show-function (get-buffer bufname))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
244 (display-buffer bufname)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
245 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
246 (with-output-to-temp-buffer bufname
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
247 (buffer-disable-undo standard-output)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
248 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
249 (set-buffer standard-output)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
250 (setq buffer-read-only nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
251 (erase-buffer)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
252
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
253 (let ((args (list topic))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
254 args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
255 (if section
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
256 (setq args
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
257 (if (eq system-type 'usg-unix-v)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
258 (cons "-s" (cons section args))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
259 (cons section args))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
260 (setq args-string
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
261 (mapconcat 'identity (cons Manual-program args) " "))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
262 (if (string-match "\\`\\([^ \t/]*/\\)+" args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
263 (setq args-string
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
264 (substring args-string (match-end 0))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
265
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
266 (message "%s (running...)" args-string)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 144
diff changeset
267 (apply 'call-process Manual-program nil '(t nil) nil args)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
268
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
269 (if (< (buffer-size) 200)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
270 (progn
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
271 (kill-buffer (current-buffer))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 149
diff changeset
272 (error "%s not found" args-string)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
273
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
274 (message "%s (cleaning...)" args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
275 (Manual-nuke-nroff-bs apropos-mode)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
276 (message "%s (done.)" args-string))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
277 (set-buffer-modified-p nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
278 (Manual-mode)))))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
279 (let ((page (if section
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
280 (concat topic "(" section ")")
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
281 topic)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
282 (setq Manual-page-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
283 (cons (buffer-name)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
284 (delete (buffer-name) Manual-page-history))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
285 Manual-page-minibuffer-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
286 (cons page (delete page Manual-page-minibuffer-history))))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
287
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
288 (message nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
289 t)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
290
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
291 (defun Manual-mode ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
292 (kill-all-local-variables)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
293 (setq buffer-read-only t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
294 (use-local-map Manual-mode-map)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
295 (setq major-mode 'Manual-mode
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
296 mode-name "Manual")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
297 ;; man pages with long lines are buggy!
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
298 ;; This looks slightly better if they only
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
299 ;; overran by a couple of chars.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
300 (setq truncate-lines t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
301 ;; turn off horizontal scrollbars in this buffer
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
302 (when (featurep 'scrollbar)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
303 (set-specifier scrollbar-height (cons (current-buffer) 0)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
304 (make-local-hook 'kill-buffer-hook)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
305 (add-hook 'kill-buffer-hook #'(lambda ()
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
306 (setq Manual-page-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
307 (delete (buffer-name)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
308 Manual-page-history)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
309 nil t)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
310 (run-hooks 'Manual-mode-hook))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
311
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
312 (defun Manual-last-page ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
313 (interactive)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
314 (if Manual-page-history
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
315 (let ((page (pop Manual-page-history)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
316 (if page
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
317 (progn
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
318 (get-buffer page)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
319 (cons Manual-page-history page)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
320 (switch-to-buffer page))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
321 (error "No manual page buffers found. Use `M-x manual-entry'")))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
322
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
323
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
324 (defmacro Manual-delete-char (n)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
325 ;; in v19, delete-char is compiled as a function call, but delete-region
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
326 ;; is byte-coded, so it's much faster. (We were spending 40% of our time
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
327 ;; in delete-char alone.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
328 (list 'delete-region '(point) (list '+ '(point) n)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
329
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
330 ;; Hint: BS stands form more things than "back space"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
331 (defun Manual-nuke-nroff-bs (&optional apropos-mode)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
332 (interactive "*")
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
333 (if Manual-use-rosetta-man
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
334 (call-process-region (point-min) (point-max) "rman" t t nil)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
335 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
336 ;; turn underlining into italics
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
337 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
338 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
339 (while (search-forward "_\b" nil t)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
340 ;; searching for underscore-backspace and then comparing the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
341 ;; following chars until the sequence ends turns out to be much
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
342 ;; faster than searching for a regexp which matches the whole
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
343 ;; sequence.
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
344 (let ((s (match-beginning 0)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
345 (goto-char s)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
346 (while (and (= (following-char) ?_)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
347 (= (char-after (1+ (point))) ?\b))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
348 (Manual-delete-char 2)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
349 (forward-char 1))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
350 (set-extent-face (make-extent s (point)) 'man-italic)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
351 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
352 ;; turn overstriking into bold
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
353 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
354 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
355 (while (re-search-forward "\\([^\n]\\)\\(\b\\1\\)" nil t)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
356 ;; Surprisingly, searching for the above regexp is faster than searching
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
357 ;; for a backspace and then comparing the preceding and following chars,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
358 ;; I presume because there are many false matches, meaning more funcalls
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
359 ;; to re-search-forward.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
360 (let ((s (match-beginning 0)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
361 (goto-char s)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
362 ;; Some systems (SGI) overstrike multiple times, eg, "M\bM\bM\bM".
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
363 (while (looking-at "\\([^\n]\\)\\(\b\\1\\)+")
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
364 (delete-region (+ (point) 1) (match-end 0))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
365 (forward-char 1))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
366 (set-extent-face (make-extent s (point)) 'man-bold)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
367 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
368 ;; hack bullets: o^H+ --> +
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
369 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
370 (while (search-forward "\b" nil t)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
371 (Manual-delete-char -2))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
372
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
373 (if (> (buffer-size) 100) ; minor kludge
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
374 (Manual-nuke-nroff-bs-footers))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
375 ) ;; not Manual-use-rosetta-man
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
376 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
377 ;; turn subsection header lines into bold
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
378 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
379 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
380 (if apropos-mode
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
381 (while (re-search-forward "[a-zA-Z0-9] ([0-9]" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
382 (forward-char -2)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
383 (delete-backward-char 1))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
384
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
385 ;; (while (re-search-forward "^[^ \t\n]" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
386 ;; (set-extent-face (make-extent (match-beginning 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
387 ;; (progn (end-of-line) (point)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
388 ;; 'man-heading))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
389
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
390 ;; boldface the first line
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
391 (if (looking-at "[^ \t\n].*$")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
392 (set-extent-face (make-extent (match-beginning 0) (match-end 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
393 'man-bold))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
394
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
395 ;; boldface subsequent title lines
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
396 ;; Regexp to match section headers changed to match a non-indented
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
397 ;; line preceded by a blank line and followed by an indented line.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
398 ;; This seems to work ok for manual pages but gives better results
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
399 ;; with other nroff'd files
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
400 (while (re-search-forward "\n\n\\([^ \t\n].*\\)\n[ \t]+[^ \t\n]" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
401 (goto-char (match-end 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
402 (set-extent-face (make-extent (match-beginning 1) (match-end 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
403 'man-heading)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
404 (forward-line 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
405 )
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
406
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
407 (if Manual-use-rosetta-man
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
408 nil
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
409 ;; Zap ESC7, ESC8, and ESC9
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
410 ;; This is for Sun man pages like "man 1 csh"
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
411 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
412 (while (re-search-forward "\e[789]" nil t)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
413 (replace-match "")))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
414
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
415 ;; Nuke blanks lines at start.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
416 ;; (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
417 ;; (skip-chars-forward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
418 ;; (delete-region (point-min) (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
419
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
420 (Manual-mouseify-xrefs)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
421 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
422
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
423 (fset 'nuke-nroff-bs 'Manual-nuke-nroff-bs) ; use old name
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
424
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
425
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
426 (defun Manual-nuke-nroff-bs-footers ()
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
427 "For info see comments in packages/man.el"
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
428 ;; Nuke headers and footers.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
429 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
430 ;; nroff assumes pages are 66 lines high. We assume that, and that the
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
431 ;; first and last line on each page is expendible. There is no way to
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
432 ;; tell the difference between a page break in the middle of a paragraph
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
433 ;; and a page break between paragraphs (the amount of extra whitespace
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
434 ;; that nroff inserts is the same in both cases) so this might strip out
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
435 ;; a blank line were one should remain. I think that's better than
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
436 ;; leaving in a blank line where there shouldn't be one. (Need I say
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
437 ;; it: FMH.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
438 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
439 ;; Note that if nroff spits out error messages, pages will be more than
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
440 ;; 66 lines high, and we'll lose badly. That's ok because standard
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
441 ;; nroff doesn't do any diagnostics, and the "gnroff" wrapper for groff
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
442 ;; turns off error messages for compatibility. (At least, it's supposed
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
443 ;; to.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
444 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
445 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
446 ;; first lose the status output
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
447 (let ((case-fold-search t))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
448 (if (and (not (looking-at "[^\n]*warning"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
449 (looking-at "Reformatting.*\n"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
450 (delete-region (match-beginning 0) (match-end 0))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
451
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
452 ;; kludge around a groff bug where it won't keep quiet about some
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
453 ;; warnings even with -Wall or -Ww.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
454 (cond ((looking-at "grotty:")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
455 (while (looking-at "grotty:")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
456 (delete-region (point) (progn (forward-line 1) (point))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
457 (if (looking-at " *done\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
458 (delete-region (point) (match-end 0)))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
459
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
460 (let ((pages '())
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
461 p)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
462 ;; collect the page boundary markers before we start deleting, to make
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
463 ;; it easier to strip things out without changing the page sizes.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
464 (while (not (eobp))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
465 (forward-line 66)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
466 (setq pages (cons (point-marker) pages)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
467 (setq pages (nreverse pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
468 (while pages
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
469 (goto-char (car pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
470 (set-marker (car pages) nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
471 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
472 ;; The lines are: 3 blank; footer; 6 blank; header; 3 blank.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
473 ;; We're in between the previous footer and the following header,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
474 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
475 ;; First lose 3 blank lines, the header, and then 3 more.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
476 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
477 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
478 (skip-chars-forward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
479 (delete-region p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
480 (and (looking-at "[^\n]+\n\n?\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
481 (delete-region (match-beginning 0) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
482 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
483 ;; Next lose the footer, and the 3 blank lines after, and before it.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
484 ;; But don't lose the last footer of the manual entry; that contains
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
485 ;; the "last change" date, so it's not completely uninteresting.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
486 ;; (Actually lose all blank lines before it; sh(1) needs this.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
487 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
488 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
489 (beginning-of-line)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
490 (if (null (cdr pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
491 nil
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
492 (and (looking-at "[^\n]+\n\n?\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
493 (delete-region (match-beginning 0) (match-end 0))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
494 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
495 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
496 (if (> (- p (point)) 4)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
497 (delete-region (+ 2 (point)) p)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
498 (delete-region (1+ (point)) p))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
499 ; (and (looking-at "\n\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
500 ; (delete-region (match-beginning 0) (match-end 0)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
501
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
502 (setq pages (cdr pages)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
503 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
504 ;; Now nuke the extra blank lines at the beginning and end.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
505 (goto-char (point-min))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
506 (if (looking-at "\n+")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
507 (delete-region (match-beginning 0) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
508 (forward-line 1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
509 (if (looking-at "\n\n+")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
510 (delete-region (1+ (match-beginning 0)) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
511 (goto-char (point-max))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
512 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
513 (delete-region (point) (point-max))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
514 (beginning-of-line)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
515 (forward-char -1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
516 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
517 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
518 (if (= ?\n (following-char)) (forward-char 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
519 (if (> (point) (1+ p))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
520 (delete-region (point) p))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
521 ))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
522
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
523 (defun Manual-mouseify-xrefs ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
524 (goto-char (point-min))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
525 ;; skip the top line of manual pages, but not apropos listings.
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
526 (unless apropos-mode (forward-line 1))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
527 (let ((case-fold-search nil)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
528 s e name splitp extent)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
529 ;; possibly it would be faster to rewrite this expression to search for
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
530 ;; a less common sequence first (like "([0-9]") and then back up to see
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
531 ;; if it's really a match. This function is 15% of the total time, 13%
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
532 ;; of which is this call to re-search-forward.
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 163
diff changeset
533 (while (re-search-forward "[a-zA-Z_][-a-zA-Z0-9_.:]*([0-9][a-zA-Z0-9]*)"
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
534 nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
535 (setq s (match-beginning 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
536 e (match-end 0)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
537 name (buffer-substring s e)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
538 splitp nil)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
539
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
540 (goto-char s)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
541 ;; if this is a hyphenated xref, we're on the second line, 1st char now.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
542 (when (progn
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
543 (beginning-of-line)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
544 (and (looking-at (concat "^[ \t]+" (regexp-quote name)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
545 (progn
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
546 (backward-char 1)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
547 (or (equal (char-before) ?-)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
548 (equal (char-before) ?\255)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
549 (setq s (progn
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
550 (skip-chars-backward "-\255_a-zA-Z0-9")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
551 (point))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
552 name (buffer-substring s e))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
553 (setq splitp t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
554 ;; delete the spaces and dash from `name'
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
555 (let (i)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
556 (while (setq i (string-match "[-\255 \n\t]+" name i))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
557 (setq name (concat (substring name 0 i)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
558 (substring name (match-end 0)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
559 i (1+ i)))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
560
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
561 ;; if there are upper case letters in the section, downcase them.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
562 (if (string-match "(.*[A-Z]+.*)$" name)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
563 (setq name (concat (substring name 0 (match-beginning 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
564 (downcase (substring name (match-beginning 0))))))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
565
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
566 ;; if the xref was hyphenated, don't highlight the indention spaces.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
567 (if splitp
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
568 (progn
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
569 (setq extent (make-extent s (progn (goto-char s) (end-of-line) (point))))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
570 (set-extent-property extent 'man (list 'Manual-follow-xref name))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
571 (set-extent-property extent 'highlight t)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
572 (set-extent-face extent 'man-xref)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
573 (goto-char e)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
574 (skip-chars-backward "-_a-zA-Z0-9()")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
575 (setq extent (make-extent (point) e)))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
576 (setq extent (make-extent s e)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
577 (set-extent-property extent 'man (list 'Manual-follow-xref name))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
578 (set-extent-property extent 'highlight t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
579 (set-extent-face extent 'man-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
580 (goto-char e))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
581
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
582 (defun Manual-follow-xref (&optional name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
583 "Invoke `manual-entry' on the cross-reference under the mouse.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
584 When invoked noninteractively, the arg may be an xref string to parse instead."
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
585 (interactive "e")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
586 (if (eventp name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
587 (let* ((p (event-point name-or-event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
588 (extent (and p (extent-at p
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
589 (event-buffer name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
590 'highlight)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
591 (data (and extent (extent-property extent 'man))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
592 (if (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
593 (eval data)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
594 (error "no manual cross-reference there.")))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
595 (or (manual-entry name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
596 ;; If that didn't work, maybe it's in a different section than the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
597 ;; man page writer expected. For example, man pages tend assume
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
598 ;; that all user programs are in section 1, but X tends to generate
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
599 ;; makefiles that put things in section "n" instead...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
600 (and (string-match "[ \t]*([^)]+)\\'" name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
601 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
602 (message "No entries found for %s; checking other sections..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
603 name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
604 (manual-entry
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
605 (substring name-or-event 0 (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
606 nil t))))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
607
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
608 (defun Manual-popup-menu (&optional event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
609 "Pops up a menu of cross-references in this manual page.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
610 If there is a cross-reference under the mouse button which invoked this
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
611 command, it will be the first item on the menu. Otherwise, they are
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
612 on the menu in the order in which they appear in the buffer."
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
613 (interactive "e")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
614 (let ((buffer (current-buffer))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
615 (sep "---")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
616 xref items)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
617 (cond (event
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
618 (setq buffer (event-buffer event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
619 (let* ((p (event-point event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
620 (extent (and p (extent-at p buffer 'highlight)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
621 (data (and extent (extent-property extent 'man))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
622 (if (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
623 (setq xref (nth 1 data))))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
624 (if xref (setq items (list sep xref)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
625 (map-extents #'(lambda (extent ignore)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
626 (let ((data (extent-property extent 'man)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
627 (if (and (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
628 (not (member (nth 1 data) items)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
629 (setq items (cons (nth 1 data) items)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
630 nil))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
631 buffer)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
632 (if (eq sep (car items)) (setq items (cdr items)))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
633 (let ((popup-menu-titles t))
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
634 (and (null items) (setq popup-menu-titles nil))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
635 (popup-menu
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
636 (cons "Manual Entry"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
637 (mapcar #'(lambda (item)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
638 (if (eq item sep)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
639 item
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
640 (vector item
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
641 (list 'Manual-follow-xref item) t)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
642 (nreverse items)))))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
643
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
644 (defun pager-cleanup-hook ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
645 "cleanup man page if called via $PAGER"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
646 (let ((buf-name (or buffer-file-name (buffer-name))))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
647 (if (or (string-match "^/tmp/man[0-9]+" buf-name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
648 (string-match ".*/man/\\(man\\|cat\\)[1-9a-z]/" buf-name))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
649 (let (buffer manpage)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
650 (require 'man)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
651 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
652 (setq buffer-read-only nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
653 (Manual-nuke-nroff-bs)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
654 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
655 (if (re-search-forward "[^ \t]")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
656 (goto-char (- (point) 1)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
657 (if (looking-at "\\([a-zA-Z0-9]+\\)[ \t]*(")
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
658 (setq manpage (buffer-substring (match-beginning 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
659 (match-end 1)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
660 (setq manpage "???"))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
661 (flet
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
662 ((maybe-star ()
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
663 (if (or Manual-buffers-have-stars
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
664 (not buffers-menu-submenus-for-groups-p))
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
665 "*"
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
666 "")))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
667 (setq buffer
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
668 (rename-buffer
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
669 (generate-new-buffer-name (concat (maybe-star)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
670 manpage
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
671 (maybe-star))))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
672 (setq buffer-file-name nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
673 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
674 (insert (format "%s\n" buf-name))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
675 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
676 (buffer-disable-undo buffer)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
677 (set-buffer-modified-p nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
678 (Manual-mode)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
679 ))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
680
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
681 (add-hook 'server-visit-hook 'pager-cleanup-hook)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
682 (provide 'man)