comparison lisp/w3/w3-speak.el @ 0:376386a54a3c r19-14

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