0
|
1 ;;!emacs
|
|
2 ;;
|
|
3 ;; FILE: hib-doc-id.el
|
|
4 ;; SUMMARY: Implicit button type for document id index entries.
|
|
5 ;; USAGE: GNU Emacs Lisp Library
|
|
6 ;; KEYWORDS: docs, extensions, hypermedia
|
|
7 ;;
|
|
8 ;; AUTHOR: Bob Weiner
|
24
|
9 ;; ORG: InfoDock Associates
|
0
|
10 ;;
|
|
11 ;; ORIG-DATE: 30-Sep-92 at 19:39:59
|
24
|
12 ;; LAST-MOD: 12-Dec-96 at 15:15:28 by Bob Weiner
|
0
|
13 ;;
|
|
14 ;; This file is part of Hyperbole.
|
|
15 ;; Available for use and distribution under the same terms as GNU Emacs.
|
|
16 ;;
|
24
|
17 ;; Copyright (C) 1992-1996, InfoDock Associates
|
0
|
18 ;; Developed with support from Motorola Inc.
|
|
19 ;;
|
|
20 ;; DESCRIPTION:
|
|
21 ;;
|
|
22 ;; TO USE:
|
|
23 ;;
|
|
24 ;; Pressing the Action Key on a doc id such as, [Emacs-001],
|
|
25 ;; displays the online version of the document, if any. Pressing the
|
|
26 ;; Assist Key on it displays its document index entry.
|
|
27 ;;
|
|
28 ;; TO INSTALL:
|
|
29 ;;
|
|
30 ;; Set the value of 'doc-id-indices' before using the 'doc-id'
|
|
31 ;; implicit button type defined herein or you will get an error telling you
|
|
32 ;; to do so. See the documentation for 'doc-id-indices'.
|
|
33 ;;
|
|
34 ;; You must explicitly load this package in order to use it, since
|
|
35 ;; Hyperbole does not load it by default.
|
|
36 ;;
|
24
|
37 ;; Motorola PPG uses doc ids of the form, [Emacs-001], delimited by
|
|
38 ;; brackets, starting with a subject name, followed by a - and a
|
0
|
39 ;; multi-digit numeric identifier.
|
|
40 ;;
|
|
41 ;; Typically an index entry should have links to all available forms of its
|
|
42 ;; document, e.g. online, printed, source. Below is the index entry form
|
24
|
43 ;; we use. The default variable settings herein work with PPG's formats. If
|
0
|
44 ;; you prefer different ones, you must change all of the variable values.
|
|
45 ;;
|
|
46 ;; --------------------------------------------------------------------------
|
|
47 ;; Title: ID: []
|
|
48 ;; Email-To:
|
|
49 ;; Distribution:
|
|
50 ;;
|
|
51 ;; Abstract:
|
|
52 ;;
|
|
53 ;;
|
|
54 ;; References:
|
|
55 ;;
|
|
56 ;; Author:
|
|
57 ;; Copyright:
|
|
58 ;; Keywords:
|
|
59 ;;
|
|
60 ;; Online-Format:
|
|
61 ;; Online-Loc: ""
|
|
62 ;; Printed-Format:
|
|
63 ;; Printed-Loc: Local Library
|
|
64 ;; Printable-Loc: ""
|
|
65 ;; Source-Format:
|
|
66 ;; Source-Loc: ""
|
|
67 ;;
|
|
68 ;; Date:
|
|
69 ;; Version:
|
|
70 ;; Version-Changes:
|
|
71 ;; --------------------------------------------------------------------------
|
|
72 ;;
|
|
73 ;; DESCRIP-END.
|
|
74
|
|
75 ;;; ************************************************************************
|
|
76 ;;; Public implicit button types
|
|
77 ;;; ************************************************************************
|
|
78
|
|
79 ;;; ========================================================================
|
|
80 ;;; Displays a documentation index entry given an ID.
|
|
81 ;;; ========================================================================
|
|
82
|
|
83 (defact link-to-doc (doc-id)
|
|
84 "Displays online version of a document given by DOC-ID (no delimiters), in other window.
|
24
|
85 If online version of document is not found in `doc-id-indices', an error is
|
|
86 signalled."
|
0
|
87 (interactive "sID for document to link to (omit delimiters): ")
|
|
88 (let ((rolo-display-buffer (hypb:help-buf-name "Doc ID"))
|
|
89 (delim-doc-id (concat doc-id-start doc-id doc-id-end)))
|
|
90 (cond ((null doc-id-indices)
|
24
|
91 (error "(doc-id-index-entry): You must set the `doc-id-indices' variable first."))
|
0
|
92 ((let ((rolo-entry-regexp doc-id-index-entry-regexp))
|
|
93 (= 0 (rolo-grep (funcall doc-id-match doc-id)
|
|
94 1 doc-id-indices nil 'no-display)))
|
|
95 (error "(doc-id-index-entry): %s not found in document index."
|
|
96 delim-doc-id))
|
|
97 ;; Matching index entry has been put into 'rolo-display-buffer'.
|
|
98 (t (save-excursion
|
|
99 (set-buffer rolo-display-buffer)
|
|
100 (goto-char (point-min))
|
|
101 (message "Searching for document %s..." delim-doc-id)
|
|
102 (if (re-search-forward doc-id-online-regexp nil t)
|
|
103 (progn
|
|
104 (goto-char (match-beginning 1))
|
|
105 (let ((doc-path (buffer-substring
|
|
106 (match-beginning 1) (match-end 1)))
|
|
107 (ibut (ibut:at-p)))
|
|
108 (if ibut
|
|
109 (progn (hbut:act ibut)
|
|
110 (message "Displaying %s." delim-doc-id))
|
24
|
111 (error
|
|
112 "(link-to-doc): %s online location is invalid: \"%s\""
|
|
113 delim-doc-id doc-path))))
|
0
|
114 (error "(link-to-doc): %s is unavailable in online form."
|
|
115 delim-doc-id)))))))
|
|
116
|
|
117 (defib doc-id ()
|
|
118 "Displays an index entry for a site-specific document given its id.
|
24
|
119 Ids must be delimited by `doc-id-start' and `doc-id-end' and must
|
|
120 match the function given by `doc-id-p'."
|
0
|
121 (and (not (bolp))
|
|
122 (let* ((id-and-pos (hbut:label-p t doc-id-start doc-id-end t))
|
|
123 (id (car id-and-pos)))
|
|
124 (if (funcall doc-id-p id)
|
|
125 (progn (ibut:label-set id-and-pos)
|
|
126 (hact 'link-to-doc id))))))
|
|
127
|
|
128
|
|
129 ;;; ========================================================================
|
|
130 ;;; Displays a doc from SW Process Tree (Motorola Paging Products Specific)
|
|
131 ;;; ========================================================================
|
|
132
|
24
|
133 (if (and (boundp 'ppg-sw-process-directory) ppg-sw-process-directory
|
|
134 (file-exists-p ppg-sw-process-directory))
|
0
|
135 (defib ppg-sw-process ()
|
24
|
136 "Display a Paging Products software process document whose location is at point."
|
0
|
137 (let ((path (hpath:at-p nil t)))
|
|
138 (if (and path (string-match "/.+%s.+%s" path))
|
|
139 (progn (require 'sw-process)
|
|
140 (ibut:label-set path)
|
|
141 (setq path (format path ppg-sw-process-file-format
|
|
142 ppg-sw-process-file-suffix))
|
|
143 (if (file-exists-p path)
|
|
144 (hact 'link-to-file path)
|
|
145 (if (re-search-forward
|
|
146 "^Source-Loc:[ \t]*\"\\([^\"]+\\)\"" nil t)
|
|
147 (progn
|
|
148 (goto-char (match-beginning 1))
|
|
149 (let ((path-but (ibut:at-p)))
|
|
150 (if path-but
|
24
|
151 (hbut:act path-but)
|
|
152 (error
|
|
153 "(ppg-sw-process): \"%s\" does not exist." path)
|
|
154 ))))))))))
|
0
|
155
|
|
156 ;;; ************************************************************************
|
|
157 ;;; Public variables
|
|
158 ;;; ************************************************************************
|
|
159
|
|
160 (defvar doc-id-indices '()
|
|
161 "List of pathnames in which to search for site-specific document index entries.
|
|
162 Each file must utilize a wrolo record format, with each record start
|
24
|
163 delimited by `doc-id-index-entry-regexp'.")
|
0
|
164
|
|
165 ;;; ************************************************************************
|
|
166 ;;; Private functions
|
|
167 ;;; ************************************************************************
|
|
168
|
|
169 (defun doc-id:help (but)
|
|
170 "Displays site-specific document index entry given by doc-id BUT, in other window.
|
|
171 Also displays standard Hyperbole help for implicit button BUT."
|
|
172 (let ((rolo-entry-regexp doc-id-index-entry-regexp)
|
|
173 (rolo-display-buffer (hypb:help-buf-name "Doc ID"))
|
|
174 (doc-id (hbut:key-to-label (hattr:get but 'lbl-key))))
|
|
175 (cond ((null doc-id-indices)
|
|
176 (error "(doc-id-index-entry): You must set the 'doc-id-indices' variable first."))
|
|
177 ((= 0 (rolo-grep (funcall doc-id-match doc-id) 1 doc-id-indices))
|
|
178 (error
|
|
179 "(doc-id-index-entry): No document index entry found for %s%s%s."
|
|
180 doc-id-start doc-id doc-id-end)))
|
|
181 (let* ((report-buf (hypb:help-buf-name))
|
|
182 (temp-buffer-show-hook
|
|
183 (function
|
|
184 (lambda (buffer)
|
24
|
185 (setq *hkey-wconfig* (current-window-configuration)))
|
0
|
186 (let ((wind (get-buffer-create buffer)))
|
|
187 (setq minibuffer-scroll-window wind))))
|
|
188 (temp-buffer-show-function temp-buffer-show-hook))
|
|
189 (hbut:report but)
|
|
190 (save-excursion
|
|
191 (set-buffer rolo-display-buffer)
|
|
192 (setq buffer-read-only nil)
|
|
193 (goto-char (point-max))
|
|
194 (insert-buffer report-buf)
|
|
195 (set-buffer-modified-p nil)
|
|
196 (setq buffer-read-only nil)
|
|
197 (goto-char (point-min)))
|
|
198 (kill-buffer report-buf)
|
|
199 )))
|
|
200
|
|
201 ;;; ************************************************************************
|
|
202 ;;; Private variables
|
|
203 ;;; ************************************************************************
|
|
204
|
|
205 (defvar doc-id-start "["
|
|
206 "String which delimits start of a site-specific document id.")
|
|
207 (defvar doc-id-end "]"
|
|
208 "String which delimits end of a site-specific document id.")
|
|
209
|
|
210 (defvar doc-id-index-entry-regexp "^------+[ \t\n]+Title:"
|
|
211 "Regexp which matches start of a site-specific document index entry.")
|
|
212
|
|
213 (defvar doc-id-match
|
|
214 (function (lambda (doc-id)
|
|
215 (concat "ID:[ \t]*\\[" (regexp-quote doc-id) "\\]")))
|
|
216 "Function which returns regexp which matches only in DOC-ID's index entry.")
|
|
217
|
|
218 (defvar doc-id-p (function
|
|
219 (lambda (str)
|
|
220 (and (stringp str)
|
|
221 (> (length str) 0)
|
|
222 (= ?w (char-syntax (aref str 0)))
|
|
223 (string-match "\\`\\w+-[0-9][0-9][0-9]+\\'" str))))
|
24
|
224 "Function with a boolean result which tests whether or not arg `str' is a doc id.")
|
0
|
225
|
|
226 (defvar doc-id-online-regexp "^Online-Loc:[ \t]*\"\\([^\"]+\\)\""
|
|
227 "Regexp whose 1st grouping matches an implicit button which displays an online document within an index entry.")
|
|
228
|
|
229 (provide 'hib-doc-id)
|