annotate lisp/docref.el @ 25641:952461b8fdaf

(find-file-noselect): Catch errors in file-expand-wildcards, and use the initial argument as file name directly. Likewise if nothing matches.
author Richard M. Stallman <rms@gnu.org>
date Sat, 11 Sep 1999 21:29:11 +0000
parents ac1673121774
children
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
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
63 (defgroup docref nil
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
64 "Simple cross references for Elisp documentation strings."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
65 :prefix "docref-"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
66 :group 'help
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
67 :group 'lisp
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
68 :group 'docs)
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
70 (defcustom docref-highlight-p t
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 "*If non-nil, \\(f@docref-subst) highlights cross-references.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 Under window system it highlights them with face defined by
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 \\(v@docref-highlight-face), on character terminal highlighted references
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
74 look like cross-references in info mode."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
75 :type 'boolean
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
76 :group 'docref)
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
78 (defcustom docref-highlight-face 'highlight
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
79 "*Face used to highlight cross-references (used by \\(f@docref-subst))"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
80 :type 'face
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
81 :group 'docref)
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
83 (defcustom docref-methods-alist
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 '(("f" . docref-describe-function) ; reference to a function documentation
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ("v" . docref-describe-variable) ; reference to a variable documentation
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ("F" . docref-read-file) ; reference to a file contents
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ("s" . docref-use-string) ; reference to a string
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ("V" . docref-use-variable-value) ; reference to variable value
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ("0" . beep)) ; just highlighted text
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "Alist which maps cross-reference ``types'' to retrieval functions.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 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
93 \(See \\(f@docref-subst)). The cdr is a function of one argument,
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
94 to be called to find this reference."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
95 :type '(repeat (cons string function))
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
96 :group 'docref)
11270
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
98 (defcustom docref-back-label "\nback"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
99 "Label to use by \\(f@docref-subst) for the go-back reference."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
100 :type 'string
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 14169
diff changeset
101 :group 'docref)
11270
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-back-reference nil
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "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
105 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
106 as the second argument to \\(f@docref-insert-label).
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 \\(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
108
15c71d840a81 (docref-last-active-buffer): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents: 11270
diff changeset
109 (defvar docref-last-active-buffer)
11270
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 ;;;###autoload
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defun docref-setup ()
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 "Process docref cross-references in the current buffer.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 See also \\(f@docref-subst)."
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (interactive)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (docref-subst (current-buffer))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (docref-mode))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defvar docref-mode-map nil)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (or docref-mode-map
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (let ((map (make-sparse-keymap)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (define-key map [mouse-2] 'docref-follow-mouse)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (define-key map "\C-c\C-b" 'docref-go-back)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (define-key map "\C-c\C-c" 'docref-follow)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (setq docref-mode-map map)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (defun docref-mode ()
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 "Major mode for help buffers that contain cross references.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 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
130 \\[docref-follow-mouse]. The command \\[docref-go-back] can used to go
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 back to where you came from."
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (interactive)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (kill-all-local-variables)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (setq major-mode 'docref-mode)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (setq mode-name "Docref")
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (use-local-map docref-mode-map)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (run-hooks 'docref-mode))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defun docref-subst (buf)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "Parse documentation cross-references in buffer BUF.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 Find cross-reference information in a buffer and
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 highlight them with face defined by \\(v@docref-highlight-face).
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 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
146 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
147 calling \\(f@describe-function)), DATA is an argument to this method
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 \(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
149 \\(v@docref-highlight-face).
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 The special reference `back' can be used to return back.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 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
153
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 See \\(v@docref-methods-alist) for currently defined methods."
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (interactive "b")
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (save-excursion
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (set-buffer buf)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (goto-char (point-min))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; The docref-seen property indicates that we have processed this
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;; buffer's contents already, so don't do it again.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (if (not (get-text-property (point-min) 'docref-seen))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (let ((old-modified (buffer-modified-p)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (while (re-search-forward "[\\](\\([^\)\@]+\\)\\(@[^\)\@]+\\)?@\\([^\)]*\\))"
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 nil t)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (let* ((start (match-beginning 0))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (type (buffer-substring (match-beginning 1) (match-end 1)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (data (buffer-substring (match-beginning 3) (match-end 3)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (label
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (if (match-beginning 2)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (buffer-substring (+ (match-beginning 2) 1) (match-end 2))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 data)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (replace-match "" t)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (docref-insert-label label (cons type data))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; Make a back-reference in this buffer, if desired.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 ;; (This is true if called from docref-follow.)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (if docref-back-reference
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (progn
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (goto-char (point-max))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (put-text-property (point-min) (1+ (point-min))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 'docref-back-position (point))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (docref-insert-label docref-back-label docref-back-reference)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (put-text-property (point-min) (1+ (point-min)) 'docref-seen t)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (set-buffer-modified-p old-modified)))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defun docref-insert-label (string ref)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let ((label (concat string))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (pos (point)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;; decorate the label
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (let ((leading-space-end (save-match-data
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (if (string-match "^\\([ \t\n]+\\)" label)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (match-end 1)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 0)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (trailing-space-start (save-match-data
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if (string-match "\\([ \t\n]+\\)$" label)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (match-beginning 1)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (length label)))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (if docref-highlight-p
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (if (not window-system)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (setq label
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (concat (substring label 0 leading-space-end)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 "(*note "
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (substring label leading-space-end trailing-space-start)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ")"
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (substring label trailing-space-start)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; window-system
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (put-text-property leading-space-end
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 trailing-space-start
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 'face docref-highlight-face label)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (put-text-property 0 (length label) 'docref ref label)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (insert label))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun docref-follow-mouse (click)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 "Follow the cross-reference that you click on."
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (interactive "e")
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (save-excursion
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (let* ((start (event-start click))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (window (car start))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (pos (car (cdr start)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (docref-last-active-buffer (current-buffer)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (set-buffer (window-buffer window))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (docref-follow pos))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (defun docref-go-back ()
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 "Go back to the previous contents of help buffer."
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (interactive)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (let ((pos (get-text-property (point-min) 'docref-back-position)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (if pos
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (docref-follow pos)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (error "No go-back reference"))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (defun docref-follow (&optional pos)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 "Follow cross-reference at point.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 For the cross-reference format, see \\(f@docref-subst).
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 The special reference named `back' can be used to return back"
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (interactive)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (or pos (setq pos (point)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (let ((docref-data (get-text-property pos 'docref)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (if docref-data
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ;; There is a reference at point. Follow it.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (let* ((type (car docref-data))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (name (cdr docref-data))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (method (assoc type docref-methods-alist))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (cur-contents (buffer-string))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (opoint (point))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (docref-back-reference (cons "s" cur-contents))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 success)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (if (null method)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (error "Unknown cross-reference type: %s" type))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (unwind-protect
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (save-excursion
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (funcall (cdr method) name)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setq success t))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (or success
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (progn
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; (cdr method) got an error.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;; Put back the text that we had.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (erase-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (insert cur-contents)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (goto-char opoint)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (set-buffer-modified-p nil))))))
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 ;; Builtin methods for accessing a reference.
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (defun docref-describe-function (data)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (save-excursion
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (if (boundp 'docref-last-active-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (set-buffer docref-last-active-buffer))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (describe-function (intern 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-describe-variable (data)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (save-excursion
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (if (boundp 'docref-last-active-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (set-buffer docref-last-active-buffer))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (describe-variable (intern data))))
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 (defun docref-read-file (data)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (with-output-to-temp-buffer (buffer-name)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (erase-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (insert-file-contents (expand-file-name data))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (defun docref-use-string (data)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (with-output-to-temp-buffer (buffer-name)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (erase-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (insert data)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (defun docref-use-variable-value (data)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (let ((sym (intern data)))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (with-output-to-temp-buffer (buffer-name)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (erase-buffer)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (princ (symbol-value sym)))))
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (provide 'docref)
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;;; docref.el ends here
ecaa82148bf5 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296