annotate lisp/packages/man.el @ 149:538048ae2ab8 r20-3b1

Import from CVS: tag r20-3b1
author cvs
date Mon, 13 Aug 2007 09:36:16 +0200
parents 318232e2a3f0
children 0132846995bd
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
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
4 ;; Copyright (C) 1985, 1993, 1994, 1996 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
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
34 "Browse manual pages"
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'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
47 :type '(choice (const :tag "fundamental-mode other window" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
48 (const :tag "view-mode current window" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
49 (const :tag "view-mode other window" other))
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
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
60
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
61 ;; New variables.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
62
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
63 (defcustom Manual-snip-subchapter
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
64 (not (string-match "solaris" system-configuration))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
65 "*Should man look in chapter 3 for ctime(3c)?
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
66 This is relavent for Solaris and, perhaps, other systems which have
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
67 `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
68 :type 'boolean
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
69 :group 'man)
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
70
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
71 (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
72 If non-nil, use RosettaMan (rman) to filter man pages.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
73 This makes man-page cleanup virtually instantaneous, instead of
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
74 potentially taking a long time.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
75
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
76 Here is information on RosettaMan, from Neal.Becker@comsat.com (Neal Becker):
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
77
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
78 RosettaMan is a filter for UNIX manual pages. It takes as input man
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
79 pages formatted for a variety of UNIX flavors (not [tn]roff source)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
80 and produces as output a variety of file formats. Currently
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
81 RosettaMan accepts man pages as formatted by the following flavors of
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
82 UNIX: Hewlett-Packard HP-UX, AT&T System V, SunOS, Sun Solaris, OSF/1,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
83 DEC Ultrix, SGI IRIX, Linux, SCO; and produces output for the following
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
84 formats: printable ASCII only (stripping page headers and footers),
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
85 section and subsection headers only, TkMan, [tn]roff, Ensemble, RTF,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
86 SGML (soon--I finally found a DTD), HTML, MIME, LaTeX, LaTeX 2e, Perl 5's pod.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
87
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
88 RosettaMan improves on other man page filters in several ways: (1) its
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
89 analysis recognizes the structural pieces of man pages, enabling high
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
90 quality output, (2) its modular structure permits easy augmentation of
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
91 output formats, (3) it accepts man pages formatted with the varient
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
92 macros of many different flavors of UNIX, and (4) it doesn't require
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
93 modification or cooperation with any other program.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
94
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
95 RosettaMan is a rewrite of TkMan's man page filter, called bs2tk. (If
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
96 you haven't heard about TkMan, a hypertext man page browser, you
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
97 should grab it via anonymous ftp from ftp.cs.berkeley.edu:
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
98 /ucb/people/phelps/tkman.tar.Z.) Whereas bs2tk generated output only for
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
99 TkMan, RosettaMan generalizes the process so that the analysis can be
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
100 leveraged to new output formats. A single analysis engine recognizes
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
101 section heads, subsection heads, body text, lists, references to other
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
102 man pages, boldface, italics, bold italics, special characters (like
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
103 bullets), tables (to a degree) and strips out page headers and
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
104 footers. The engine sends signals to the selected output functions so
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
105 that an enhancement in the engine improves the quality of output of
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
106 all of them. Output format functions are easy to add, and thus far
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
107 average about about 75 lines of C code each.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
108
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
109
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
110
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
111 *** NOTES ON CURRENT VERSION ***
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
112
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
113 Help! I'm looking for people to help with the following projects.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
114 \(1) Better RTF output format. The current one works, but could be
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
115 made better. (2) Roff macros that produce text that is easily
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
116 parsable. RosettaMan handles a great variety, but some things, like
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
117 H-P's tables, are intractable. If you write an output format or
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
118 otherwise improve RosettaMan, please send in your code so that I may
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
119 share the wealth in future releases.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
120
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
121 This version can try to identify tables (turn this on with the -T
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
122 switch) by looking for lines with a large amount of interword spacing,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
123 reasoning that this is space between columns of a table. This
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
124 heuristic doesn't always work and sometimes misidentifies ordinary
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
125 text as tables. In general I think it is impossible to perfectly
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
126 identify tables from nroff formatted text. However, I do think the
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
127 heuristics can be tuned, so if you have a collection of manual pages
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
128 with unrecognized tables, send me the lot, in formatted form (i.e.,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
129 after formatting with nroff -man), and uuencode them to preserve the
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
130 control characters. Better, if you can think of heuristics that
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
131 distinguish tables from ordinary text, I'd like to hear them.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
132
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
133
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
134 Notes for HTML consumers: This filter does real (heuristic)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
135 parsing--no <PRE>! Man page references are turned into hypertext links."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
136 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
137 :group 'man)
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
138
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
139 (defface man-italic '((t (:italic t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
140 "Manual italics face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
141 :group 'man)
10
49a24b4fd526 Import from CVS: tag r19-15b6
cvs
parents: 8
diff changeset
142
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
143 (defface man-bold '((t (:bold t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
144 "Manual bold face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
145 :group 'man)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
147 (defface man-heading '((t (:bold t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
148 "Manual headings face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
149 :group 'man)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
151 (defface man-xref '((t (:underline t)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
152 "Manual xrefs face"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
153 :group 'man)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 104
diff changeset
154
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
155
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
156 (defvar Manual-mode-map
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
157 (let ((m (make-sparse-keymap)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
158 (set-keymap-name m 'Manual-mode-map)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
159 (define-key m "l" 'Manual-last-page)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
160 (define-key m 'button2 'Manual-follow-xref)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
161 (define-key m 'button3 'Manual-popup-menu)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
162 m))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;###autoload
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
165 (defun manual-entry (topic &optional arg silent)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
166 "Display the Unix manual entry (or entries) for TOPIC."
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
167 (interactive
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
168 (list (let* ((fmh "-A-Za-z0-9_.")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
169 (default (save-excursion
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
170 (buffer-substring
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
171 (progn
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
172 (re-search-backward "\\sw" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
173 (skip-chars-backward fmh) (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
174 (progn (skip-chars-forward fmh) (point)))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
175 (thing (read-string
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
176 (if (equal default "") "Manual entry: "
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
177 (concat "Manual entry: (default " default ") ")))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
178 (if (equal thing "") default thing))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
179 (prefix-numeric-value current-prefix-arg)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
180 ;;(interactive "sManual entry (topic): \np")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
181 (or arg (setq arg 1))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
182 (let (section apropos-mode)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
183 (let ((case-fold-search nil))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
184 (if (and (null section)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
185 (string-match "\\`[ \t]*\\([^( \t]+\\)[ \t]*(\\(.+\\))[ \t]*\\'"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
186 topic))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
187 (setq section (substring topic (match-beginning 2)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
188 (match-end 2))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
189 topic (substring topic (match-beginning 1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
190 (match-end 1)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
191 (if (string-match "\\`[ \t]*-k[ \t]+\\([^ \t]+\\)\\'" topic)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
192 (setq section "-k"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
193 topic (substring topic (match-beginning 1))))))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
194
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
195 (when Manual-snip-subchapter
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
196 ;; jwz: turn section "3x11" and "3n" into "3".
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
197 (if (and section (string-match "\\`\\([0-9]+\\)[^0-9]" section))
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 120
diff changeset
198 (setq section (substring section 0 (match-end 1)))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
199 (if (equal section "-k")
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
200 (setq apropos-mode t))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
201
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
202 (let ((bufname (cond (apropos-mode
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
203 (concat "*man apropos " topic "*"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
204 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
205 (concat "*man " topic
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
206 (if section (concat "." section) "")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
207 "*"))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
208 (temp-buffer-show-function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
209 (cond ((eq 't Manual-buffer-view-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
210 'view-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
211 ((eq 'nil Manual-buffer-view-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
212 temp-buffer-show-function)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
213 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
214 'view-buffer-other-window))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
215
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
216 (cond ((get-buffer bufname)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
217 ;; reselect an old man page buffer if it exists already.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
218 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
219 (set-buffer (get-buffer bufname))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
220 (Manual-mode))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
221 (if temp-buffer-show-function
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
222 (funcall temp-buffer-show-function (get-buffer bufname))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
223 (display-buffer bufname)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
224 (t
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
225 (with-output-to-temp-buffer bufname
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
226 (buffer-disable-undo standard-output)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
227 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
228 (set-buffer standard-output)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
229 (setq buffer-read-only nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
230 (erase-buffer)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
231
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
232 (let ((args (list topic))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
233 args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
234 (if section
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
235 (setq args
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
236 (if (eq system-type 'usg-unix-v)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
237 (cons "-s" (cons section args))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
238 (cons section args))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
239 (setq args-string
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
240 (mapconcat 'identity (cons Manual-program args) " "))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
241 (if (string-match "\\`\\([^ \t/]*/\\)+" args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
242 (setq args-string
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
243 (substring args-string (match-end 0))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
244
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
245 (message "%s (running...)" args-string)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 144
diff changeset
246 (apply 'call-process Manual-program nil '(t nil) nil args)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
247
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
248 (if (< (buffer-size) 200)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
249 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
250 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
251 (error (buffer-substring (point)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
252 (progn (end-of-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
253 (point))))))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
254
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
255 (message "%s (cleaning...)" args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
256 (Manual-nuke-nroff-bs apropos-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
257 (message "%s (done.)" args-string)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
258 )
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 4
diff changeset
259
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
260 (set-buffer-modified-p nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
261 (Manual-mode)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
262 ))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
263 (setq Manual-page-history
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
264 (cons (buffer-name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
265 (delete (buffer-name) Manual-page-history)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
266 (message nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
267 t)
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
268
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
269 (defun Manual-mode ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
270 (kill-all-local-variables)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
271 (setq buffer-read-only t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
272 (use-local-map Manual-mode-map)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
273 (setq major-mode 'Manual-mode
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
274 mode-name "Manual")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
275 ;; man pages with long lines are buggy!
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
276 ;; This looks slightly better if they only
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
277 ;; overran by a couple of chars.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
278 (setq truncate-lines t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
279 ;; turn off horizontal scrollbars in this buffer
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
280 (when (featurep 'scrollbar)
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
281 (set-specifier scrollbar-height (cons (current-buffer) 0)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
282 (run-hooks 'Manual-mode-hook))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
283
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
284 (defun Manual-last-page ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
285 (interactive)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
286 (while (or (not (get-buffer (car (or Manual-page-history
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
287 (error "No more history.")))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
288 (eq (get-buffer (car Manual-page-history)) (current-buffer)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
289 (setq Manual-page-history (cdr Manual-page-history)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
290 (switch-to-buffer (car Manual-page-history)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
291
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
292
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
293 (defmacro Manual-delete-char (n)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
294 ;; 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
295 ;; 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
296 ;; in delete-char alone.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
297 (list 'delete-region '(point) (list '+ '(point) n)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
298
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
299 ;; Hint: BS stands form more things than "back space"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
300 (defun Manual-nuke-nroff-bs (&optional apropos-mode)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
301 (interactive "*")
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
302 (if Manual-use-rosetta-man
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
303 (call-process-region (point-min) (point-max) "rman" t t nil)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
304 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
305 ;; turn underlining into italics
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
306 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
307 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
308 (while (search-forward "_\b" nil t)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
309 ;; searching for underscore-backspace and then comparing the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
310 ;; following chars until the sequence ends turns out to be much
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
311 ;; faster than searching for a regexp which matches the whole
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
312 ;; sequence.
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
313 (let ((s (match-beginning 0)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
314 (goto-char s)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
315 (while (and (= (following-char) ?_)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
316 (= (char-after (1+ (point))) ?\b))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
317 (Manual-delete-char 2)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
318 (forward-char 1))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
319 (set-extent-face (make-extent s (point)) 'man-italic)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
320 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
321 ;; turn overstriking into bold
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
322 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
323 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
324 (while (re-search-forward "\\([^\n]\\)\\(\b\\1\\)" nil t)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
325 ;; Surprisingly, searching for the above regexp is faster than searching
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
326 ;; for a backspace and then comparing the preceding and following chars,
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
327 ;; I presume because there are many false matches, meaning more funcalls
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
328 ;; to re-search-forward.
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
329 (let ((s (match-beginning 0)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
330 (goto-char s)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
331 ;; Some systems (SGI) overstrike multiple times, eg, "M\bM\bM\bM".
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
332 (while (looking-at "\\([^\n]\\)\\(\b\\1\\)+")
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
333 (delete-region (+ (point) 1) (match-end 0))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
334 (forward-char 1))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
335 (set-extent-face (make-extent s (point)) 'man-bold)))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
336 ;;
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
337 ;; hack bullets: o^H+ --> +
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)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
340 (Manual-delete-char -2))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
341
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
342 (if (> (buffer-size) 100) ; minor kludge
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
343 (Manual-nuke-nroff-bs-footers))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
344 ) ;; not Manual-use-rosetta-man
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
345 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
346 ;; turn subsection header lines into bold
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
347 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
348 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
349 (if apropos-mode
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
350 (while (re-search-forward "[a-zA-Z0-9] ([0-9]" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
351 (forward-char -2)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
352 (delete-backward-char 1))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
353
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
354 ;; (while (re-search-forward "^[^ \t\n]" nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
355 ;; (set-extent-face (make-extent (match-beginning 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
356 ;; (progn (end-of-line) (point)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
357 ;; 'man-heading))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
358
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
359 ;; boldface the first line
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
360 (if (looking-at "[^ \t\n].*$")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
361 (set-extent-face (make-extent (match-beginning 0) (match-end 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
362 'man-bold))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
363
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
364 ;; boldface subsequent title lines
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
365 ;; Regexp to match section headers changed to match a non-indented
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
366 ;; line preceded by a blank line and followed by an indented line.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
367 ;; This seems to work ok for manual pages but gives better results
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
368 ;; with other nroff'd files
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
369 (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
370 (goto-char (match-end 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
371 (set-extent-face (make-extent (match-beginning 1) (match-end 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
372 'man-heading)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
373 (forward-line 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
374 )
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
375
76
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
376 (if Manual-use-rosetta-man
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
377 nil
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
378 ;; Zap ESC7, ESC8, and ESC9
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
379 ;; This is for Sun man pages like "man 1 csh"
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
380 (goto-char (point-min))
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
381 (while (re-search-forward "\e[789]" nil t)
c0c698873ce1 Import from CVS: tag r20-0b33
cvs
parents: 74
diff changeset
382 (replace-match "")))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
383
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
384 ;; Nuke blanks lines at start.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
385 ;; (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
386 ;; (skip-chars-forward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
387 ;; (delete-region (point-min) (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
388
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
389 (Manual-mouseify-xrefs)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
390 )
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
391
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
392 (fset 'nuke-nroff-bs 'Manual-nuke-nroff-bs) ; use old name
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
393
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 (defun Manual-nuke-nroff-bs-footers ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
396 ;; Nuke headers and footers.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
397 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
398 ;; 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
399 ;; 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
400 ;; 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
401 ;; and a page break between paragraphs (the amount of extra whitespace
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
402 ;; 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
403 ;; 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
404 ;; 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
405 ;; it: FMH.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
406 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
407 ;; 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
408 ;; 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
409 ;; nroff doesn't do any diagnostics, and the "gnroff" wrapper for groff
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
410 ;; turns off error messages for compatibility. (At least, it's supposed
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
411 ;; to.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
412 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
413 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
414 ;; first lose the status output
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
415 (let ((case-fold-search t))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
416 (if (and (not (looking-at "[^\n]*warning"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
417 (looking-at "Reformatting.*\n"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
418 (delete-region (match-beginning 0) (match-end 0))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
419
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
420 ;; 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
421 ;; warnings even with -Wall or -Ww.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
422 (cond ((looking-at "grotty:")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
423 (while (looking-at "grotty:")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
424 (delete-region (point) (progn (forward-line 1) (point))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
425 (if (looking-at " *done\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
426 (delete-region (point) (match-end 0)))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
427
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
428 (let ((pages '())
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
429 p)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
430 ;; collect the page boundary markers before we start deleting, to make
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
431 ;; it easier to strip things out without changing the page sizes.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
432 (while (not (eobp))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
433 (forward-line 66)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
434 (setq pages (cons (point-marker) pages)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
435 (setq pages (nreverse pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
436 (while pages
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
437 (goto-char (car pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
438 (set-marker (car pages) nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
439 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
440 ;; The lines are: 3 blank; footer; 6 blank; header; 3 blank.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
441 ;; We're in between the previous footer and the following header,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
442 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
443 ;; First lose 3 blank lines, the header, and then 3 more.
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 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
446 (skip-chars-forward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
447 (delete-region p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
448 (and (looking-at "[^\n]+\n\n?\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
449 (delete-region (match-beginning 0) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
450 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
451 ;; 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
452 ;; 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
453 ;; the "last change" date, so it's not completely uninteresting.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
454 ;; (Actually lose all blank lines before it; sh(1) needs this.)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
455 ;;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
456 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
457 (beginning-of-line)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
458 (if (null (cdr pages))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
459 nil
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
460 (and (looking-at "[^\n]+\n\n?\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
461 (delete-region (match-beginning 0) (match-end 0))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
462 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
463 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
464 (if (> (- p (point)) 4)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
465 (delete-region (+ 2 (point)) p)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
466 (delete-region (1+ (point)) p))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
467 ; (and (looking-at "\n\n?\n?")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
468 ; (delete-region (match-beginning 0) (match-end 0)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
469
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
470 (setq pages (cdr pages)))
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 ;; Now nuke the extra blank lines at the beginning and end.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
473 (goto-char (point-min))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
474 (if (looking-at "\n+")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
475 (delete-region (match-beginning 0) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
476 (forward-line 1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
477 (if (looking-at "\n\n+")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
478 (delete-region (1+ (match-beginning 0)) (match-end 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
479 (goto-char (point-max))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
480 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
481 (delete-region (point) (point-max))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
482 (beginning-of-line)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
483 (forward-char -1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
484 (setq p (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
485 (skip-chars-backward "\n")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
486 (if (= ?\n (following-char)) (forward-char 1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
487 (if (> (point) (1+ p))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
488 (delete-region (point) p))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
489 ))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
490
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
491 (defun Manual-mouseify-xrefs ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
492 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
493 (forward-line 1)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
494 (let ((case-fold-search nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
495 s e name extent)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
496 ;; possibly it would be faster to rewrite this expression to search for
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
497 ;; 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
498 ;; 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
499 ;; of which is this call to re-search-forward.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
500 (while (re-search-forward "[a-zA-Z_][-a-zA-Z0-9_.]*([0-9][a-zA-Z0-9]*)"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
501 nil t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
502 (setq s (match-beginning 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
503 e (match-end 0)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
504 name (buffer-substring s e))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
505 (goto-char s)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
506 (skip-chars-backward " \t")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
507 (if (and (bolp)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
508 (progn (backward-char 1) (= (preceding-char) ?-)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
509 (progn
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
510 (setq s (point))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
511 (skip-chars-backward "-a-zA-Z0-9_.")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
512 (setq name (concat (buffer-substring (point) (1- s)) name))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
513 (setq s (point))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
514 ;; if there are upper case letters in the section, downcase them.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
515 (if (string-match "(.*[A-Z]+.*)$" name)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
516 (setq name (concat (substring name 0 (match-beginning 0))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
517 (downcase (substring name (match-beginning 0))))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
518 ;; (setq already-fontified (extent-at s))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
519 (setq extent (make-extent s e))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
520 (set-extent-property extent 'man (list 'Manual-follow-xref name))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
521 (set-extent-property extent 'highlight t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
522 ;; (if (not already-fontified)...
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
523 (set-extent-face extent 'man-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
524 (goto-char e))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
525
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
526 (defun Manual-follow-xref (&optional name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
527 "Invoke `manual-entry' on the cross-reference under the mouse.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
528 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
529 (interactive "e")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
530 (if (eventp name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
531 (let* ((p (event-point name-or-event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
532 (extent (and p (extent-at p
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
533 (event-buffer name-or-event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
534 'highlight)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
535 (data (and extent (extent-property extent 'man))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
536 (if (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
537 (eval data)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
538 (error "no manual cross-reference there.")))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
539 (or (manual-entry name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
540 ;; 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
541 ;; man page writer expected. For example, man pages tend assume
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
542 ;; 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
543 ;; makefiles that put things in section "n" instead...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
544 (and (string-match "[ \t]*([^)]+)\\'" name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
545 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
546 (message "No entries found for %s; checking other sections..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
547 name-or-event)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
548 (manual-entry
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
549 (substring name-or-event 0 (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
550 nil t))))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
551
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
552 (defun Manual-popup-menu (&optional event)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
553 "Pops up a menu of cross-references in this manual page.
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
554 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
555 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
556 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
557 (interactive "e")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
558 (let ((buffer (current-buffer))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
559 (sep "---")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
560 (prefix "Show Manual Page for ")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
561 xref items)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
562 (cond (event
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
563 (setq buffer (event-buffer event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
564 (let* ((p (event-point event))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
565 (extent (and p (extent-at p buffer 'highlight)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
566 (data (and extent (extent-property extent 'man))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
567 (if (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
568 (setq xref (nth 1 data))))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
569 (if xref (setq items (list sep xref)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
570 (map-extents #'(lambda (extent ignore)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
571 (let ((data (extent-property extent 'man)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
572 (if (and (eq (car-safe data) 'Manual-follow-xref)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
573 (not (member (nth 1 data) items)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
574 (setq items (cons (nth 1 data) items)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
575 nil))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
576 buffer)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
577 (if (eq sep (car items)) (setq items (cdr items)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
578 (let ((popup-menu-titles nil))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
579 (popup-menu
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
580 (cons "Manual Entry"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
581 (mapcar #'(lambda (item)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
582 (if (eq item sep)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
583 item
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
584 (vector (concat prefix item)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
585 (list 'Manual-follow-xref item) t)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
586 (nreverse items)))))))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 26
diff changeset
587
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
588 (defun pager-cleanup-hook ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
589 "cleanup man page if called via $PAGER"
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
590 (let ((buf-name (or buffer-file-name (buffer-name))))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
591 (if (or (string-match "^/tmp/man[0-9]+" buf-name)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
592 (string-match ".*/man/\\(man\\|cat\\)[1-9a-z]/" buf-name))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
593 (let (buffer manpage)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
594 (require 'man)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
595 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
596 (setq buffer-read-only nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
597 (Manual-nuke-nroff-bs)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
598 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
599 (if (re-search-forward "[^ \t]")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
600 (goto-char (- (point) 1)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
601 (if (looking-at "\\([a-zA-Z0-9]+\\)[ \t]*(")
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
602 (setq manpage (buffer-substring (match-beginning 1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 86
diff changeset
603 (match-end 1)))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
604 (setq manpage "???"))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
605 (setq buffer
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
606 (rename-buffer
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
607 (generate-new-buffer-name (concat "*man " manpage "*"))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
608 (setq buffer-file-name nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
609 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
610 (insert (format "%s\n" buf-name))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
611 (goto-char (point-min))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
612 (buffer-disable-undo buffer)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
613 (set-buffer-modified-p nil)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
614 (Manual-mode)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
615 ))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
616
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
617 (add-hook 'server-visit-hook 'pager-cleanup-hook)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
618 (provide 'man)