annotate lisp/docref.el @ 15002:0588af7eae96

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