annotate lisp/packages/man.el @ 120:cca96a509cfe r20-1b12

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