diff lisp/w3/w3-speak.el @ 14:9ee227acff29 r19-15b90

Import from CVS: tag r19-15b90
author cvs
date Mon, 13 Aug 2007 08:48:42 +0200
parents ac2d302a0011
children 0293115a14e9
line wrap: on
line diff
--- a/lisp/w3/w3-speak.el	Mon Aug 13 08:48:18 2007 +0200
+++ b/lisp/w3/w3-speak.el	Mon Aug 13 08:48:42 2007 +0200
@@ -1,12 +1,14 @@
-;;; w3-speak.el --- Emacs-W3 speech interface
-;; Authors: wmperry and Raman
-;; Created: 1996/07/09 14:08:09
-;; Version: 1.4
+;;; w3-speak.el,v --- Emacs-W3 speech interface
+;; Author: wmperry
+;; Original author: William Perry --<wmperry@cs.indiana.edu>
+;; Cloned from emacspeak-w3.el
+;; Created: 1996/10/16 20:56:40
+;; Version: 1.14
 ;; Keywords: hypermedia, speech
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;{{{  Copyright
-
-;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
+;;; Copyright (c) 1996 by T.V. Raman (raman@adobe.com)
+;;; Copyright (c) 1996 by William M. Perry (wmperry@spry.com)
 ;;;
 ;;; This file is not part of GNU Emacs, but the same permissions apply.
 ;;;
@@ -21,8 +23,9 @@
 ;;; GNU General Public License for more details.
 ;;;
 ;;; You should have received a copy of the GNU General Public License
-;;; along with GNU Emacs; see the file COPYING.  If not, write to
-;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;;; Boston, MA 02111-1307, USA.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -32,32 +35,26 @@
 ;;; This file would not be possible without the help of
 ;;; T.V. Raman (raman@adobe.com) and his continued efforts to make Emacs-W3
 ;;; even remotely useful. :)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-;;}}}
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;{{{  Required modules
+;;; This conforms to http://www4.inria.fr/speech2.html
 
 (require 'widget)
 (require 'w3-forms)
 (require 'advice)
-
 ;; This condition-case needs to be here or it completely chokes
 ;; byte-compilation for people who do not have Emacspeak installed.
 ;; *sigh*
-
 (condition-case ()
     (progn
       (require 'emacspeak)
       (require 'dtk-voices)
-      (require 'dtk-css-speech)
       (require 'emacspeak-speak)
       (require 'emacspeak-sounds)
       (eval-when (compile)
-	(require 'emacspeak-fix-interactive)))
+		 (require 'emacspeak-fix-interactive)))
   (error (message "Emacspeak not found - speech will not work.")))
 
-;;}}}
-
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; How to get information summarizing a form field, so it can be spoken in
@@ -76,6 +73,21 @@
   (get type 'w3-speak-summarizer))
 
 ;;}}}
+;;{{{  Associate summarizer functions for form fields 
+
+(w3-speak-define-field-summarizer 'text)
+(w3-speak-define-field-summarizer 'option)
+(w3-speak-define-field-summarizer 'checkbox)
+(w3-speak-define-field-summarizer 'reset)
+(w3-speak-define-field-summarizer 'submit)
+(w3-speak-define-field-summarizer 'button)
+(w3-speak-define-field-summarizer 'radio)
+(w3-speak-define-field-summarizer 'multiline)
+(w3-speak-define-field-summarizer 'image)
+
+;;}}}
+
+
 ;;{{{  define the form field summarizer functions
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -92,23 +104,13 @@
   (let (
 	(label (w3-speak-extract-form-field-label data))
 	(name  (w3-form-element-name data))
-	(value (widget-value (w3-form-element-widget data))))
+	(value (widget-get (w3-form-element-widget data) :value)))
     (dtk-speak
      (format "Text  field  %s  %s " (or label (concat "called " name))
 	     (concat "set to " value)))))
 
-(defun w3-speak-summarize-file-field (data)
-  "Summarize a f field of type file  given the field data."
-  (let (
-	(label (w3-speak-extract-form-field-label data))
-	(name  (w3-form-element-name data))
-	(value (widget-value (w3-form-element-widget data))))
-    (dtk-speak
-     (format "File   field  %s  %s " (or label (concat "called " name))
-	     (concat "set to " value)))))
-
-(defun w3-speak-summarize-textarea-field (data)
-  "Summarize a textarea  field given the field data."
+(defun w3-speak-summarize-multiline-field (data)
+  "Summarize a text field given the field data."
   (let (
         (name (w3-form-element-name data))
         (label (w3-speak-extract-form-field-label data))
@@ -160,7 +162,7 @@
 			(reset "Reset Form")
 			(button "A Button"))))))
 
-(defalias 'w3-speak-summarize-reset-field  'w3-speak-summarize-submit-field)
+(defalias 'w3-speak-summarize-reset-field 'w3-speak-summarize-submit-field)
 (defalias 'w3-speak-summarize-button-field 'w3-speak-summarize-submit-field)
 
 (defun w3-speak-summarize-radio-field (data)
@@ -175,22 +177,8 @@
 						      "not pressed")))))
 
 ;;}}}
-;;{{{  Associate summarizer functions for form fields 
-
-(w3-speak-define-field-summarizer 'text)
-(w3-speak-define-field-summarizer 'option)
-(w3-speak-define-field-summarizer 'checkbox)
-(w3-speak-define-field-summarizer 'reset)
-(w3-speak-define-field-summarizer 'submit)
-(w3-speak-define-field-summarizer 'button)
-(w3-speak-define-field-summarizer 'radio)
-(w3-speak-define-field-summarizer 'multiline)
-(w3-speak-define-field-summarizer 'image)
-(w3-speak-define-field-summarizer 'file)
-
-;;}}}
 
-;;{{{ speaking form fields
+;;{{{  speaking form fields 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Now for the guts
@@ -206,7 +194,9 @@
          (type (and data (w3-form-element-type data)))
          (summarizer (and type (w3-speak-get-field-summarizer type))))
     (cond
-     ((and data summarizer (fboundp summarizer))
+     ((and data
+           summarizer
+           (fboundp summarizer))
       (funcall summarizer data))
      (data
       (message "Please define a summarizer function for %s"  type))
@@ -214,38 +204,37 @@
 
 ;;}}}
 
-;;{{{ Movement notification
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Movement notification
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (defadvice w3-scroll-up (after emacspeak pre act comp)
   "Provide auditory feedback"
   (when (interactive-p)
-    (let ((start (point )))
-      (emacspeak-auditory-icon 'scroll)
-      (save-excursion
-        (forward-line (window-height))
-        (emacspeak-speak-region start (point ))))))
+	(let ((start (point )))
+	  (emacspeak-auditory-icon 'scroll)
+	  (save-excursion
+	    (forward-line (window-height))
+	    (emacspeak-speak-region start (point ))))))
 
 (defadvice w3-follow-link (around emacspeak pre act)
   "Provide feedback on what you did. "
-  (let ((data (w3-speak-extract-form-field-information))
-        (form-field-p nil))
+  (let ((data (emacspeak-w3-extract-form-field-information))
+        (form-field-p nil)
+        (this-zone nil)
+        (opoint nil))
     (if data
-	(setq form-field-p t))
+	(setq form-field-p t 
+	      opoint (point)))
     ad-do-it
     (when form-field-p
       (w3-speak-summarize-form-field)
       (case (w3-form-element-type data)
-	((radio checkbox button)
+	((radio checkbox)
 	 (emacspeak-auditory-icon 'button))
-        ((text textarea)
-         (emacspeak-auditory-icon 'close-object)
 	;; fill in any others here
 	(otherwise
 	 nil)))
-    ad-return-value)))
+    ad-return-value))
 
 (defadvice w3-revert-form (after emacspeak pre act)
   "Announce that you cleared the form. "
@@ -256,24 +245,6 @@
   (when (interactive-p)
     (w3-speak-summarize-form-field)))
 
-(defadvice widget-forward (after emacspeak pre act)
-  "Produce an auditory icon when moving forward.
-If on a form field, then summarize it."
-  (declare   (special emacspeak-lazy-message-time))
-  (when (interactive-p)
-    (let ((emacspeak-lazy-message-time 0))
-      (w3-speak-summarize-form-field)
-      (emacspeak-auditory-icon 'large-movement))))
-
-(defadvice widget-backward (after emacspeak pre act)
-  "Produce an auditory icon when moving backward.
-If on a form field, then summarize it."
-  (declare (special emacspeak-lazy-message-time))
-  (when (interactive-p )
-    (let ((emacspeak-lazy-message-time 0))
-    (w3-speak-summarize-form-field)
-    (emacspeak-auditory-icon 'large-movement))))
-
 (defadvice w3-start-of-document (after emacspeak pre act)
   "Produce an auditory icon.  Also speak the first line. "
   (when (interactive-p)
@@ -281,7 +252,7 @@
     (emacspeak-auditory-icon 'large-movement)))
 
 (defadvice w3-end-of-document (after emacspeak pre act)
-  "Produce an auditory icon.  "
+  "Produce an auditory icon.  Also speak the first line."
   (when (interactive-p)
     (emacspeak-speak-line)
     (emacspeak-auditory-icon 'large-movement)))
@@ -299,21 +270,13 @@
     (emacspeak-speak-mode-line)))
 
 (defadvice w3-fetch (around  emacspeak  act comp )
-  "First produce an auditory icon to indicate retrieval.  After
-retrieval, set voice-lock-mode to t after displaying the buffer, and
-then speak the mode-line. "
+  "First produce an auditory icon to indicate retrieval.
+After retrieval, 
+set  voice-lock-mode to t after displaying the buffer,
+and then speak the mode-line. "
   (declare (special dtk-punctuation-mode))
-  (when (interactive-p)
-    (emacspeak-auditory-icon 'select-object)
-    ad-do-it
-    (set (make-local-variable 'voice-lock-mode) t)
-    (setq dtk-punctuation-mode "some")
-    (modify-syntax-entry 10 " ")
-    (emacspeak-auditory-icon 'open-object)
-    (emacspeak-speak-mode-line )))
-  
-;;}}}
-;;{{{  top level
+  (emacspeak-auditory-icon 'select-object)
+  ad-do-it)
 
 (defun w3-speak-mode-hook ()
   (set (make-local-variable 'voice-lock-mode) t)
@@ -340,14 +303,25 @@
           w3-delimit-emphasis nil)
     (add-hook 'w3-mode-hook 'w3-speak-mode-hook)))
 
-;;}}}
-;;{{{ make-local-hook
+(defun w3-speak-browse-page ()
+  "Browse a WWW page"
+  (interactive)
+  (emacspeak-audio-annotate-paragraphs)
+  (emacspeak-execute-repeatedly 'forward-paragraph))
+
+(declaim (special w3-mode-map))
+(define-key w3-mode-map "." 'w3-speak-browse-page)
 
-;;; hope this is correct:
-(unless (fboundp 'make-local-hook)
-(defun make-local-hook (var)
-  (make-variable-buffer-local var))
-)
+(defvar url-speak-last-progress-indication 0
+  "Caches when we last produced a progress auditory icon")
 
-;;}}}
+(defadvice url-lazy-message (around emacspeak pre act)
+  "Provide pleasant auditory feedback about progress"
+  (declare (special url-speak-last-progress-indication ))
+  (let ((now (nth 1 (current-time))))
+    (when (> now
+	     (+ 3 url-speak-last-progress-indication))
+	  (setq url-speak-last-progress-indication now)
+	  (emacspeak-auditory-icon 'progress))))
+
 (provide 'w3-speak)