annotate lisp/utils/docref.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents ac2d302a0011
children
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 ;;; docref.el --- Simple cross references for Elisp documentation strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Vadim Geshel <vadik@unas.cs.kiev.ua>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Created: 12 Jul 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: docs, help, lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; original name was cross-ref.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
9 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
12 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
19 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
29
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; This package allows you to use a simple form of cross references in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; your Emacs Lisp documentation strings. Cross-references look like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; \\(type@[label@]data), where type defines a method for retrieving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; reference informatin, data is used by a method routine as an argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; and label "represents" the reference in text. If label is absent, data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; is used instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; Special reference labeled `back', when present, can be used to return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; to the previous contents of help buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Cross-referencing currently is intended for use in doc strings only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; and works only in temporary buffers (created by `with-output-to-temp-buffer').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; List of temp buffers in which cross-referencing is to be active is specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; by variable DOCREF-BUFFERS-LIST, which contains only "*Help*" by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Documentation strings for this package's functions and variables can serve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; as examples of usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; Customization:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; See source. The main customization variable is `docref-methods-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; It consists of (type . function) pairs, where type is a string which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; corresponds to type in cross-references and function is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; one argument - reference `data' - when a reference is activated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; Installation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; Place this file somewhere in your load-path, byte-compiled it, and add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; (require 'cross-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; to your .emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; User customizable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar docref-highlight-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "*If non-nil, \\(f@docref-subst) highlights cross-references.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 Under window system it highlights them with face defined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 \\(v@docref-highlight-face), on character terminal highlighted references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 look like cross-references in info mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defvar docref-highlight-face 'highlight
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "*Face used to highlight cross-references (used by \\(f@docref-subst))")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar docref-methods-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 '(("f" . docref-describe-function) ; reference to a function documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ("v" . docref-describe-variable) ; reference to a variable documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ("F" . docref-read-file) ; reference to a file contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ("s" . docref-use-string) ; reference to a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ("V" . docref-use-variable-value) ; reference to variable value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ("0" . beep)) ; just highlighted text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Alist which maps cross-reference ``types'' to retrieval functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 The car of each element is a string that serves as `type' in cross-references.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 \(See \\(f@docref-subst)). The cdr is a function of one argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 to be called to find this reference.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defvar docref-back-label "\nback"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Label to use by \\(f@docref-subst) for the go-back reference.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defvar docref-back-reference nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "If non-nil, this is a go-back reference to add to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 The value specifies how to go back. It should be suitable for use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 as the second argument to \\(f@docref-insert-label).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 \\(f@docref-subst) uses this to set up the go-back reference.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defvar docref-last-active-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (defun docref-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 "Process docref cross-references in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 See also \\(f@docref-subst)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (docref-subst (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (docref-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defvar docref-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or docref-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (define-key map [mouse-2] 'docref-follow-mouse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (define-key map "\C-c\C-b" 'docref-go-back)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (define-key map "\C-c\C-c" 'docref-follow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq docref-mode-map map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun docref-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Major mode for help buffers that contain cross references.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 To follow a reference, move to it and type \\[docref-follow], or use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 \\[docref-follow-mouse]. The command \\[docref-go-back] can used to go
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 back to where you came from."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq major-mode 'docref-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (setq mode-name "Docref")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (use-local-map docref-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (run-hooks 'docref-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defun docref-subst (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 "Parse documentation cross-references in buffer BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Find cross-reference information in a buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 highlight them with face defined by \\(v@docref-highlight-face).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Cross-reference has the following format: \\ (TYPE[@LABEL]@DATA), where
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 TYPE defines method used to retrieve xref data (like reading from file or
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 calling \\(f@describe-function)), DATA is an argument to this method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 \(like file name or function name), and LABEL is displayed in text using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 \\(v@docref-highlight-face).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 The special reference `back' can be used to return back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 The variable \\(v@docref-back-label) specifies the label to use for that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 See \\(v@docref-methods-alist) for currently defined methods."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (interactive "b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; The docref-seen property indicates that we have processed this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; buffer's contents already, so don't do it again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (if (not (get-text-property (point-min) 'docref-seen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (let ((old-modified (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (while (re-search-forward "[\\](\\([^\)\@]+\\)\\(@[^\)\@]+\\)?@\\([^\)]*\\))"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 nil t)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
152 (let* ((start (match-beginning 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
153 (type (buffer-substring (match-beginning 1) (match-end 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (data (buffer-substring (match-beginning 3) (match-end 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (if (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (buffer-substring (+ (match-beginning 2) 1) (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (replace-match "" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (docref-insert-label label (cons type data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; Make a back-reference in this buffer, if desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; (This is true if called from docref-follow.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if docref-back-reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (put-text-property (point-min) (1+ (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 'docref-back-position (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (docref-insert-label docref-back-label docref-back-reference)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (put-text-property (point-min) (1+ (point-min)) 'docref-seen t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (set-buffer-modified-p old-modified)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun docref-insert-label (string ref)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
174 (let ((label (concat string))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
175 (pos (point)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; decorate the label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((leading-space-end (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (if (string-match "^\\([ \t\n]+\\)" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (match-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (trailing-space-start (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (string-match "\\([ \t\n]+\\)$" label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (length label)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (if docref-highlight-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; XEmacs: we support faces on TTY's.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; (if (not window-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; (setq label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; (concat (substring label 0 leading-space-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; "(*note "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; (substring label leading-space-end trailing-space-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; ")"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; (substring label trailing-space-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; window-system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (put-text-property leading-space-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 trailing-space-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 'face docref-highlight-face label))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (put-text-property 0 (length label) 'docref ref label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (insert label))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defun docref-follow-mouse (click)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "Follow the cross-reference that you click on."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; XEmacs changes here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let* ((window (event-window click))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (pos (event-point click))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (docref-last-active-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (set-buffer (window-buffer window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (docref-follow pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (defun docref-go-back ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 "Go back to the previous contents of help buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (let ((pos (get-text-property (point-min) 'docref-back-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (docref-follow pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (error "No go-back reference"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (defun docref-follow (&optional pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "Follow cross-reference at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 For the cross-reference format, see \\(f@docref-subst).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 The special reference named `back' can be used to return back"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (or pos (setq pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let ((docref-data (get-text-property pos 'docref)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (if docref-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;; There is a reference at point. Follow it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (let* ((type (car docref-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (name (cdr docref-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (method (assoc type docref-methods-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (cur-contents (buffer-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (docref-back-reference (cons "s" cur-contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 success)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (null method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (error "Unknown cross-reference type: %s" type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (funcall (cdr method) name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq success t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (or success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; (cdr method) got an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; Put back the text that we had.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (insert cur-contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (goto-char opoint)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (set-buffer-modified-p nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;; Builtin methods for accessing a reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun docref-describe-function (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (boundp 'docref-last-active-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (set-buffer docref-last-active-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (describe-function (intern data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defun docref-describe-variable (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if (boundp 'docref-last-active-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (set-buffer docref-last-active-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (describe-variable (intern data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (defun docref-read-file (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (with-output-to-temp-buffer (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (insert-file-contents (expand-file-name data))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defun docref-use-string (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (with-output-to-temp-buffer (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (insert data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (defun docref-use-variable-value (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (let ((sym (intern data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (with-output-to-temp-buffer (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (princ (symbol-value sym)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (provide 'docref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;;; docref.el ends here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284