File: emacspeak-forms.el

package info (click to toggle)
emacspeak 29.0-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 12,904 kB
  • sloc: xml: 55,354; lisp: 48,335; cpp: 2,321; tcl: 1,500; makefile: 936; python: 836; sh: 785; perl: 459; ansic: 241
file content (288 lines) | stat: -rw-r--r-- 8,842 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
;;; emacspeak-forms.el --- Speech enable Emacs' forms mode  -- provides  a convenient database interface
;;; $Id: emacspeak-forms.el 5798 2008-08-22 17:35:01Z tv.raman.tv $
;;; $Author: tv.raman.tv $ 
;;; DescriptionEmacspeak extensions for forms-mode 
;;; Keywords:emacspeak, audio interface to emacs forms 
;;{{{  LCD Archive entry: 

;;; LCD Archive Entry:
;;; emacspeak| T. V. Raman |raman@cs.cornell.edu
;;; A speech interface to Emacs |
;;; $Date: 2007-08-25 18:28:19 -0700 (Sat, 25 Aug 2007) $ |
;;;  $Revision: 4532 $ | 
;;; Location undetermined
;;;

;;}}}
;;{{{  Copyright:
;;;Copyright (C) 1995 -- 2007, T. V. Raman 
;;; Copyright (c) 1996 by T. V. Raman 
;;; All Rights Reserved. 
;;;
;;; This file is not part of GNU Emacs, but the same permissions apply.
;;;
;;; GNU Emacs is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2, or (at your option)
;;; any later version.
;;;
;;; GNU Emacs is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; 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.

;;}}}

;;{{{ requires

(require 'forms)(require 'emacspeak-preamble)

;;}}}
;;{{{  Introduction:

;;; Provide additional advice to forms-mode 

;;}}}
;;{{{  custom
(defgroup emacspeak-forms nil
  "Emacspeak support for forms mode."
  :group 'emacspeak
  :group 'forms
  :prefix "emacspeak-forms-")

;;}}}
;;{{{ Helper functions

(defvar emacspeak-forms-current-record-summarizer
  'emacspeak-forms-speak-field
  "Summarizer function for summarizing a record. Default is to
speak the first field")
(make-variable-buffer-local
 emacspeak-forms-current-record-summarizer)

(defun emacspeak-forms-summarize-current-record ()
  "Summarize current record"
  (interactive)
  (declare (special emacspeak-forms-current-record-summarizer))
  (funcall emacspeak-forms-current-record-summarizer))

(defun emacspeak-forms-summarize-current-position ()
  "Summarize current position in list of records"
  (interactive)
  (declare (special forms--current-record forms--total-records
                    forms-file))
  (dtk-speak
   (format "Record %s of %s from %s"
           forms--current-record forms--total-records forms-file)))

(defcustom emacspeak-forms-rw-voice 'paul
  "Personality for read-write fields. "
  :type 'symbol
  :group 'emacspeak-forms)

(defcustom emacspeak-forms-ro-voice voice-annotate
  "Personality for read-only fields. "
  :type 'symbol
  :group 'emacspeak-forms)

(defun emacspeak-forms-speak-field ()
  "Speak current form field name and value.
Assumes that point is at the front of a field value."
  (interactive)
  (let ((voice-lock-mode t)
        (name nil)
        (value nil)
        (n-start nil))
    (save-excursion
      (backward-char 1)
      (setq n-start (point)))
    (setq name (buffer-substring n-start (point)))
    (setq value
          (buffer-substring
           (point)
           (or
            (next-single-property-change (point) 'read-only)
            (point))))
    (put-text-property 0 (length name)
                       'personality
                       emacspeak-forms-ro-voice name)
    (put-text-property 0 (length value )
                       'personality emacspeak-forms-rw-voice value)
    (dtk-speak (concat name " " value ))))

;;}}}
;;{{{ Advise interactive  commands

(defadvice forms-next-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'select-object)
    (goto-char (next-single-property-change 
                (point)
                'read-only
                (current-buffer)
                (point-max)))
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-prev-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'select-object)
    (goto-char (next-single-property-change 
                (point)
                'read-only
                (current-buffer)
                (point-max)))
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-first-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'select-object)
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-last-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'select-object)
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-jump-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'select-object)
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-search (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'search-hit)
    (emacspeak-forms-summarize-current-record)))

(defadvice forms-exit (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'close-object)
    (emacspeak-speak-mode-line)))

(defadvice forms-next-field (around emacspeak pre act comp)
  "Provide auditory feedback."
  (cond
   ((interactive-p)
    ad-do-it
    (emacspeak-auditory-icon 'large-movement)
    (emacspeak-forms-speak-field))
   (t ad-do-it))
  ad-return-value)

(defadvice forms-prev-field (after emacspeak pre act comp)
  "Provide auditory feedback."
  (cond
   ((interactive-p)
    ad-do-it
    (emacspeak-auditory-icon 'large-movement)
    (emacspeak-forms-speak-field))
   (t ad-do-it))
  ad-return-value)

(defadvice forms-kill-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'delete-object)
    ))

(defadvice forms-insert-record (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when (interactive-p)
    (emacspeak-auditory-icon 'open-object)
    ))

(defadvice forms-save-buffer (after emacspeak pre act comp)
  "Provide auditory feedback."
  (when  (interactive-p)
    (emacspeak-auditory-icon 'save-object)))

;;}}}
;;{{{ smart filters

(defun emacspeak-forms-flush-unwanted-records ()
  "Prompt for pattern and flush matching lines"
  (interactive)
  (let ((pattern (read-from-minibuffer
                  "Specify filter pattern")))
    (when (> (length pattern) 0)
      (flush-lines
       pattern))))

(defun emacspeak-forms-rerun-filter ()
  "Rerun  filter --allows us to nuke more matching records"
  (interactive)
  (declare (special forms--file-buffer
                    forms--total-records forms-read-only))
  (save-excursion
    (set-buffer forms--file-buffer)
    (let ((inhibit-read-only t)
          (file-modified (buffer-modified-p)))
      (emacspeak-forms-flush-unwanted-records)
      (if (not file-modified) (set-buffer-modified-p
                               nil))))
  (let (ro)
    (setq forms--total-records
          (save-excursion
            (prog1
                (progn
                  ;;(message "forms: counting records...")
                  (set-buffer forms--file-buffer)
                  (bury-buffer (current-buffer))
                  (setq ro buffer-read-only)
                  (count-lines (point-min) (point-max))))))
    (if ro
        (setq forms-read-only t)))
  (message "%s records after filtering"
           forms--total-records))

;;}}}
;;{{{ emacspeak forms find file
;;;###autoload
(defun emacspeak-forms-find-file (filename)
  "Visit a forms file"
  (interactive
   (list
    (read-file-name "Forms file: "
                    (expand-file-name "forms/" emacspeak-etc-directory))))
  (forms-find-file filename))

;;}}}
;;{{{ bind smart filters
(declaim (special forms-mode-map forms-mode-ro-map
                  forms-mode-edit-map))
(add-hook 'forms-mode-hooks
          (function
           (lambda nil 
             (mapcar 
              (function
               (lambda (map)
                 (define-key map "\C-m" 'emacspeak-forms-rerun-filter)
                 (define-key map "."
                   'emacspeak-forms-summarize-current-position)
                 (define-key map "," 'emacspeak-forms-summarize-current-record)))
              (list forms-mode-ro-map 
                    forms-mode-map))
;;; move to first field
             (forms-next-field 1))))
  

;;}}}
(provide  'emacspeak-forms)
;;{{{  emacs local variables 

;;; local variables:
;;; folded-file: t
;;; byte-compile-dynamic: t
;;; end: 

;;}}}