annotate lisp/docref.el @ 13488:71c747dc59ca

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