80
|
1 ;;; w3-speak.el,v --- Emacs-W3 speech interface
|
|
2 ;; Author: wmperry
|
|
3 ;; Original author: William Perry --<wmperry@cs.indiana.edu>
|
|
4 ;; Cloned from emacspeak-w3.el
|
|
5 ;; Created: 1996/10/16 20:56:40
|
|
6 ;; Version: 1.14
|
0
|
7 ;; Keywords: hypermedia, speech
|
80
|
8
|
70
|
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
80
|
10 ;;; Copyright (c) 1996 by T.V. Raman (raman@adobe.com)
|
|
11 ;;; Copyright (c) 1996 by William M. Perry (wmperry@spry.com)
|
0
|
12 ;;;
|
|
13 ;;; This file is not part of GNU Emacs, but the same permissions apply.
|
|
14 ;;;
|
|
15 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
16 ;;; it under the terms of the GNU General Public License as published by
|
|
17 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
18 ;;; any later version.
|
|
19 ;;;
|
|
20 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
21 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 ;;; GNU General Public License for more details.
|
|
24 ;;;
|
|
25 ;;; You should have received a copy of the GNU General Public License
|
80
|
26 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
27 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
28 ;;; Boston, MA 02111-1307, USA.
|
0
|
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
30
|
|
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
32 ;;; A replacement module for emacspeak-w3 that uses all the new functionality
|
|
33 ;;; of Emacs-W3 3.0.
|
|
34 ;;;
|
|
35 ;;; This file would not be possible without the help of
|
|
36 ;;; T.V. Raman (raman@adobe.com) and his continued efforts to make Emacs-W3
|
|
37 ;;; even remotely useful. :)
|
80
|
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
70
|
39
|
80
|
40 ;;; This conforms to http://www4.inria.fr/speech2.html
|
0
|
41
|
|
42 (require 'widget)
|
|
43 (require 'w3-forms)
|
|
44 (require 'advice)
|
|
45 ;; This condition-case needs to be here or it completely chokes
|
|
46 ;; byte-compilation for people who do not have Emacspeak installed.
|
|
47 ;; *sigh*
|
|
48 (condition-case ()
|
|
49 (progn
|
|
50 (require 'emacspeak)
|
|
51 (require 'dtk-voices)
|
|
52 (require 'emacspeak-speak)
|
|
53 (require 'emacspeak-sounds)
|
|
54 (eval-when (compile)
|
80
|
55 (require 'emacspeak-fix-interactive)))
|
0
|
56 (error (message "Emacspeak not found - speech will not work.")))
|
|
57
|
|
58
|
70
|
59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
60 ;;; How to get information summarizing a form field, so it can be spoken in
|
|
61 ;;; a sane manner.
|
|
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
63 ;;{{{ putting and getting form field summarizer
|
|
64
|
|
65 (defsubst w3-speak-define-field-summarizer (type &optional function-name)
|
|
66 "Associate the name of a function that describes this type of form field."
|
|
67 (put type 'w3-speak-summarizer
|
|
68 (or function-name (intern
|
|
69 (format "w3-speak-summarize-%s-field" type)))))
|
|
70
|
|
71 (defsubst w3-speak-get-field-summarizer (type)
|
|
72 "Retrieve function-name string for this voice"
|
|
73 (get type 'w3-speak-summarizer))
|
|
74
|
|
75 ;;}}}
|
80
|
76 ;;{{{ Associate summarizer functions for form fields
|
|
77
|
|
78 (w3-speak-define-field-summarizer 'text)
|
|
79 (w3-speak-define-field-summarizer 'option)
|
|
80 (w3-speak-define-field-summarizer 'checkbox)
|
|
81 (w3-speak-define-field-summarizer 'reset)
|
|
82 (w3-speak-define-field-summarizer 'submit)
|
|
83 (w3-speak-define-field-summarizer 'button)
|
|
84 (w3-speak-define-field-summarizer 'radio)
|
|
85 (w3-speak-define-field-summarizer 'multiline)
|
|
86 (w3-speak-define-field-summarizer 'image)
|
|
87
|
|
88 ;;}}}
|
|
89
|
|
90
|
70
|
91 ;;{{{ define the form field summarizer functions
|
|
92
|
|
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
94 ;;; Now actually define the summarizers
|
|
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
96
|
|
97 (defsubst w3-speak-extract-form-field-label (data)
|
|
98 ;;; FIXXX!!! Need to reimplement using the new forms implementation!
|
|
99 (declare (special w3-form-labels))
|
|
100 nil)
|
|
101
|
|
102 (defun w3-speak-summarize-text-field (data)
|
|
103 "Summarize a text field given the field data."
|
|
104 (let (
|
|
105 (label (w3-speak-extract-form-field-label data))
|
|
106 (name (w3-form-element-name data))
|
80
|
107 (value (widget-get (w3-form-element-widget data) :value)))
|
70
|
108 (dtk-speak
|
|
109 (format "Text field %s %s " (or label (concat "called " name))
|
|
110 (concat "set to " value)))))
|
|
111
|
80
|
112 (defun w3-speak-summarize-multiline-field (data)
|
|
113 "Summarize a text field given the field data."
|
70
|
114 (let (
|
|
115 (name (w3-form-element-name data))
|
|
116 (label (w3-speak-extract-form-field-label data))
|
|
117 (value (w3-form-element-value data)))
|
|
118 (dtk-speak
|
|
119 (format "Multiline text input %s %s" (or label (concat "called " name))
|
|
120 (concat "set to " value)))))
|
|
121
|
|
122 (defun w3-speak-summarize-checkbox-field (data)
|
|
123 "Summarize a checkbox field given the field data."
|
|
124 (let (
|
|
125 (name (w3-form-element-name data))
|
|
126 (label (w3-speak-extract-form-field-label data))
|
|
127 (checked (widget-value (w3-form-element-widget data))))
|
|
128 (dtk-speak
|
|
129 (format "Checkbox %s is %s" (or label name) (if checked "on" "off")))))
|
|
130
|
|
131 (defun w3-speak-summarize-option-field (data)
|
|
132 "Summarize a options field given the field data."
|
|
133 (let (
|
|
134 (name (w3-form-element-name data))
|
|
135 (label (w3-speak-extract-form-field-label data))
|
|
136 (default (w3-form-element-default-value data)))
|
|
137 (dtk-speak
|
|
138 (format "Choose an option %s %s" (or label name)
|
|
139 (if (string= "" default)
|
|
140 ""
|
|
141 (format "default is %s" default))))))
|
|
142
|
|
143 ;;; to handle brain dead nynex forms
|
|
144 (defun w3-speak-summarize-image-field (data)
|
|
145 "Summarize a image field given the field data.
|
|
146 Currently, only the NYNEX server uses this."
|
|
147 (let (
|
|
148 (name (w3-form-element-name data))
|
|
149 (label (w3-speak-extract-form-field-label data)))
|
|
150 (dtk-speak
|
|
151 (substring name 1))))
|
|
152
|
|
153 (defun w3-speak-summarize-submit-field (data)
|
|
154 "Summarize a submit field given the field data."
|
|
155 (let (
|
|
156 (type (w3-form-element-type data))
|
|
157 (label (w3-speak-extract-form-field-label data))
|
|
158 (button-text (widget-value (w3-form-element-widget data))))
|
|
159 (message "%s" (or label button-text
|
|
160 (case type
|
|
161 (submit "Submit Form")
|
|
162 (reset "Reset Form")
|
|
163 (button "A Button"))))))
|
|
164
|
80
|
165 (defalias 'w3-speak-summarize-reset-field 'w3-speak-summarize-submit-field)
|
70
|
166 (defalias 'w3-speak-summarize-button-field 'w3-speak-summarize-submit-field)
|
|
167
|
|
168 (defun w3-speak-summarize-radio-field (data)
|
|
169 "Summarize a radio field given the field data."
|
|
170 (let (
|
|
171 (name (w3-form-element-name data))
|
|
172 (label (w3-speak-extract-form-field-label data))
|
|
173 (checked (widget-value (w3-form-element-widget data))))
|
|
174 (dtk-speak
|
|
175 (format "Radio button %s is %s" (or label name) (if checked
|
|
176 "pressed"
|
|
177 "not pressed")))))
|
|
178
|
|
179 ;;}}}
|
|
180
|
80
|
181 ;;{{{ speaking form fields
|
0
|
182
|
|
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
184 ;;; Now for the guts
|
|
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
70
|
186 (defun w3-speak-extract-form-field-information ()
|
|
187 (let* ((widget (widget-at (point)))
|
|
188 (data (and widget (widget-get widget 'w3-form-data))))
|
|
189 data))
|
|
190
|
0
|
191 (defun w3-speak-summarize-form-field ()
|
|
192 "Summarizes field under point if any."
|
70
|
193 (let* ((data (w3-speak-extract-form-field-information))
|
|
194 (type (and data (w3-form-element-type data)))
|
|
195 (summarizer (and type (w3-speak-get-field-summarizer type))))
|
|
196 (cond
|
80
|
197 ((and data
|
|
198 summarizer
|
|
199 (fboundp summarizer))
|
70
|
200 (funcall summarizer data))
|
|
201 (data
|
|
202 (message "Please define a summarizer function for %s" type))
|
|
203 (t nil))))
|
2
|
204
|
0
|
205 ;;}}}
|
|
206
|
|
207 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
208 ;;; Movement notification
|
|
209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
210 (defadvice w3-scroll-up (after emacspeak pre act comp)
|
|
211 "Provide auditory feedback"
|
|
212 (when (interactive-p)
|
80
|
213 (let ((start (point )))
|
|
214 (emacspeak-auditory-icon 'scroll)
|
|
215 (save-excursion
|
|
216 (forward-line (window-height))
|
|
217 (emacspeak-speak-region start (point ))))))
|
0
|
218
|
|
219 (defadvice w3-follow-link (around emacspeak pre act)
|
|
220 "Provide feedback on what you did. "
|
80
|
221 (let ((data (emacspeak-w3-extract-form-field-information))
|
|
222 (form-field-p nil)
|
|
223 (this-zone nil)
|
|
224 (opoint nil))
|
0
|
225 (if data
|
80
|
226 (setq form-field-p t
|
|
227 opoint (point)))
|
0
|
228 ad-do-it
|
|
229 (when form-field-p
|
|
230 (w3-speak-summarize-form-field)
|
|
231 (case (w3-form-element-type data)
|
80
|
232 ((radio checkbox)
|
0
|
233 (emacspeak-auditory-icon 'button))
|
|
234 ;; fill in any others here
|
|
235 (otherwise
|
|
236 nil)))
|
80
|
237 ad-return-value))
|
0
|
238
|
|
239 (defadvice w3-revert-form (after emacspeak pre act)
|
|
240 "Announce that you cleared the form. "
|
|
241 (dtk-speak "Cleared the form. "))
|
|
242
|
|
243 (defadvice w3-finish-text-entry (after emacspeak pre act )
|
|
244 "Announce what the field was set to."
|
|
245 (when (interactive-p)
|
|
246 (w3-speak-summarize-form-field)))
|
|
247
|
|
248 (defadvice w3-start-of-document (after emacspeak pre act)
|
|
249 "Produce an auditory icon. Also speak the first line. "
|
|
250 (when (interactive-p)
|
|
251 (emacspeak-speak-line)
|
|
252 (emacspeak-auditory-icon 'large-movement)))
|
|
253
|
|
254 (defadvice w3-end-of-document (after emacspeak pre act)
|
80
|
255 "Produce an auditory icon. Also speak the first line."
|
0
|
256 (when (interactive-p)
|
|
257 (emacspeak-speak-line)
|
|
258 (emacspeak-auditory-icon 'large-movement)))
|
|
259
|
|
260 (defadvice w3-goto-last-buffer (after emacspeak pre act)
|
|
261 "Speak the modeline so I know where I am."
|
|
262 (when (interactive-p)
|
|
263 (emacspeak-auditory-icon 'select-object)
|
|
264 (emacspeak-speak-mode-line)))
|
|
265
|
|
266 (defadvice w3-quit (after emacspeak pre act)
|
|
267 "Speak the mode line of the new buffer."
|
|
268 (when (interactive-p)
|
|
269 (emacspeak-auditory-icon 'close-object)
|
|
270 (emacspeak-speak-mode-line)))
|
|
271
|
|
272 (defadvice w3-fetch (around emacspeak act comp )
|
80
|
273 "First produce an auditory icon to indicate retrieval.
|
|
274 After retrieval,
|
|
275 set voice-lock-mode to t after displaying the buffer,
|
|
276 and then speak the mode-line. "
|
0
|
277 (declare (special dtk-punctuation-mode))
|
80
|
278 (emacspeak-auditory-icon 'select-object)
|
|
279 ad-do-it)
|
0
|
280
|
|
281 (defun w3-speak-mode-hook ()
|
|
282 (set (make-local-variable 'voice-lock-mode) t)
|
|
283 (setq dtk-punctuation-mode "some")
|
|
284 (emacspeak-auditory-icon 'open-object)
|
|
285 (emacspeak-speak-mode-line))
|
|
286
|
|
287 ;;; This is really the only function you should need to call unless
|
|
288 ;;; you are adding functionality.
|
|
289 (defun w3-speak-use-voice-locking (&optional arg)
|
|
290 "Tells w3 to start using voice locking.
|
|
291 This is done by setting the w3 variables so that anchors etc are not marked by
|
|
292 delimiters. We then turn on voice-lock-mode.
|
|
293 Interactive prefix arg does the opposite. "
|
|
294 (interactive "P")
|
70
|
295 (declare (special w3-delimit-links w3-delimit-emphasis w3-echo-link))
|
0
|
296 (setq w3-echo-link 'text)
|
|
297 (if arg
|
70
|
298 (progn
|
|
299 (setq w3-delimit-links 'guess
|
|
300 w3-delimit-emphasis 'guess)
|
|
301 (remove-hook 'w3-mode-hook 'w3-speak-mode-hook))
|
|
302 (setq w3-delimit-links nil
|
|
303 w3-delimit-emphasis nil)
|
0
|
304 (add-hook 'w3-mode-hook 'w3-speak-mode-hook)))
|
|
305
|
80
|
306 (defun w3-speak-browse-page ()
|
|
307 "Browse a WWW page"
|
|
308 (interactive)
|
|
309 (emacspeak-audio-annotate-paragraphs)
|
|
310 (emacspeak-execute-repeatedly 'forward-paragraph))
|
|
311
|
|
312 (declaim (special w3-mode-map))
|
|
313 (define-key w3-mode-map "." 'w3-speak-browse-page)
|
2
|
314
|
80
|
315 (defvar url-speak-last-progress-indication 0
|
|
316 "Caches when we last produced a progress auditory icon")
|
2
|
317
|
80
|
318 (defadvice url-lazy-message (around emacspeak pre act)
|
|
319 "Provide pleasant auditory feedback about progress"
|
|
320 (declare (special url-speak-last-progress-indication ))
|
|
321 (let ((now (nth 1 (current-time))))
|
|
322 (when (> now
|
|
323 (+ 3 url-speak-last-progress-indication))
|
|
324 (setq url-speak-last-progress-indication now)
|
|
325 (emacspeak-auditory-icon 'progress))))
|
|
326
|
0
|
327 (provide 'w3-speak)
|