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