annotate lisp/utils/docref.el @ 0:376386a54a3c r19-14

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