-
Notifications
You must be signed in to change notification settings - Fork 51
/
emacspeak-advice.el
2880 lines (2513 loc) · 82.8 KB
/
emacspeak-advice.el
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; emacspeak-advice.el --- Advice Emacs Core -*- lexical-binding: t; -*-
;;
;; $Author: tv.raman.tv $
;; Description: Core advice forms that make emacspeak work
;; Keywords: Emacspeak, Speech, Advice, Spoken output
;;; LCD Archive entry:a
;; LCD Archive Entry:
;; emacspeak| T. V. Raman |tv.raman.tv@gmail.com
;; A speech interface to Emacs |
;;
;; $Revision: 4550 $ |
;; Location https://github.com/tvraman/emacspeak
;;
;;; Copyright:
;; Copyright (C) 1995 -- 2024, T. V. Raman
;; Copyright (c) 1995, 1996, 1997 by T. V. Raman
;; All Rights Reserved.
;;
;; Copyright (c) 1994, 1995 by Digital Equipment Corporation.
;; 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, 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:
;;; Commentary:
;; This module defines the advice forms for making the core of Emacs speak
;; Advice forms that are specific to Emacs subsystems do not belong here!
;; I violate this at present by advising completion.
;; Note that we needed to advice a lot more for Emacs 19 and
;; Emacs 20 than we do for Emacs 21 and Emacs 22.
;; As of August 2007, this file is being purged of advice forms
;; not needed in Emacs 22.
;;; Code:
;; Required modules:
(eval-when-compile (require 'cl-lib))
(cl-declaim (optimize (safety 0) (speed 3)))
(eval-when-compile (require 'advice))
(require 'emacspeak-preamble)
;;; Advice Replace
(voice-setup-set-voice-for-face 'query-replace 'voice-animate)
(cl-loop
for f in
'(query-replace query-replace-regexp) do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Icon"
(when (ems-interactive-p) (emacspeak-icon 'task-done)))))
(defadvice perform-replace (around emacspeak pre act comp)
"Silence help."
(ems-with-messages-silenced ad-do-it))
(defadvice replace-highlight (after emacspeak pre act comp)
"Speak line. "
(emacspeak-speak-line))
;;; advice overlays
;;; Helpers:
(defun ems--add-personality (start end voice &optional object)
"Apply personality VOICE."
(when
(and
(integerp start) (integerp end)
(not (= start end)))
(with-current-buffer
(if (bufferp object) object (current-buffer))
(with-silent-modifications
(put-text-property start end 'personality voice object)))))
(defun ems--remove-personality (start end voice &optional object)
"Remove personality. "
(when
(and
voice
(integerp start) (integerp end)
(not (= start end))
(eq voice (get-text-property start 'personality object)))
(with-current-buffer
(if (bufferp object) object (current-buffer))
(with-silent-modifications
(put-text-property start end 'personality nil object)))))
(defvar ems--voiceify-overlays t
"Voicify overlays")
;; Needed for outline support:
(defadvice remove-overlays (around emacspeak pre act comp)
"Clean up properties mirrored from overlays."
(let ((ems--voiceify-overlays nil)
(beg (or (ad-get-arg 0) (point-min)))
(end (or (ad-get-arg 1) (point-max)))
(name (ad-get-arg 2)))
(when (zerop beg) (setq beg (point-min)))
(with-silent-modifications ; ignores value for now
(put-text-property beg end name nil))
ad-do-it))
(defadvice delete-overlay (before emacspeak pre act comp)
"Augment voice lock."
(when ems--voiceify-overlays
(let* ((o (ad-get-arg 0))
(buffer (overlay-buffer o))
(start (overlay-start o))
(end (overlay-end o))
(voice (dtk-get-voice-for-face (overlay-get o 'face)))
(invisible (overlay-get o 'invisible)))
(when (and start end voice buffer)
(with-current-buffer buffer
(save-restriction
(widen)
(ems--remove-personality start end voice buffer))))
(when (and start end invisible)
(with-silent-modifications
(put-text-property start end 'invisible nil))))))
(defadvice overlay-put (after emacspeak pre act comp)
"Augment voice lock."
(when (and (overlay-buffer (ad-get-arg 0)) ems--voiceify-overlays)
(let* ((overlay (ad-get-arg 0))
(prop (ad-get-arg 1))
(value (ad-get-arg 2))
(start (overlay-start overlay))
(end (overlay-end overlay))
(voice nil))
(cond
((and
(or
(memq prop '(font-lock-face face))
(and (eq prop 'category) (get value 'face)))
(integerp start) (integerp end))
(when (eq prop 'category) (setq value (get value 'face)))
(setq voice (dtk-get-voice-for-face value))
(when voice
(ems--add-personality
start end voice (overlay-buffer overlay))))
((eq prop 'invisible)
(with-current-buffer (overlay-buffer overlay)
(with-silent-modifications
(put-text-property start end 'invisible (or value nil)))))))))
(defadvice move-overlay (before emacspeak pre act comp)
"Used by emacspeak to augment voice lock."
(when ems--voiceify-overlays
(let*
((overlay (ad-get-arg 0))
(beg (ad-get-arg 1))
(end (ad-get-arg 2))
(object (ad-get-arg 3))
(buffer (overlay-buffer overlay))
(voice (dtk-get-voice-for-face (overlay-get overlay 'face)))
(invisible (overlay-get overlay 'invisible)))
(unless object (setq object (or buffer (current-buffer))))
(when
(and voice
(integerp (overlay-start overlay))
(integerp (overlay-end overlay)))
(ems--remove-personality
(overlay-start overlay) (overlay-end overlay) voice buffer)
(ems--add-personality beg end voice object))
(when invisible
(with-current-buffer buffer
(with-silent-modifications
(put-text-property
(overlay-start overlay) (overlay-end overlay) 'invisible nil)))
(with-current-buffer object
(with-silent-modifications
(put-text-property beg end 'invisible invisible)))))))
;;; advice cursor movement commands to speak
(cl-loop
for f in
'(next-line previous-line)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak line. Speak (visual) line if
`visual-line-mode' is on, and
indicate point by an aural highlight. Moving to
beginning or end of a physical line produces an auditory icon."
(when (ems-interactive-p)
(cond
((or line-move-visual visual-line-mode) (emacspeak-speak-visual-line))
(t (emacspeak-speak-line)))))))
(defadvice delete-horizontal-space (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p) (emacspeak-icon 'delete-object)))
(defadvice kill-visual-line (before emacspeak pre act comp)
"Speak line we're to kill."
(when (ems-interactive-p)
(emacspeak-icon 'delete-object)
(emacspeak-speak-visual-line)))
(cl-loop
for f in
'(beginning-of-visual-line end-of-visual-line)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak visual line with show-point enabled."
(when (ems-interactive-p)
(let ((emacspeak-show-point t))
(emacspeak-speak-visual-line))))))
(cl-loop
for f in
'(
next-logical-line previous-logical-line
delete-indentation back-to-indentation
lisp-indent-line goto-line goto-line-relative)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak line."
(when (ems-interactive-p)
(let ((emacspeak-show-point t))
(emacspeak-speak-line))))))
(cl-loop
for f in
'(forward-button backward-button)
do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak button with messages Silenced."
(cond
((ems-interactive-p)
(ems-with-messages-silenced
ad-do-it
(condition-case nil
(let* ((button (button-at (point)))
(start (button-start button))
(end (button-end button)))
(dtk-speak (buffer-substring start end))
(emacspeak-icon 'large-movement))
(error nil))))
(t ad-do-it))
ad-return-value)))
(defadvice blink-matching-open (after emacspeak pre act comp)
"Speak"
(emacspeak-speak-matching-paren))
(cl-loop
for f in
'(left-char right-char
backward-char forward-char)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak char under point.
When on a close delimiter, speak matching delimiter after a small delay. "
(when (ems-interactive-p)
(and dtk-stop-immediately (dtk-stop))
(emacspeak-speak-char t)
(when
(and
(= ?\) (char-syntax (following-char)))
(sit-for 0.25))
(emacspeak-icon 'tick-tick)
(save-excursion
(forward-char 1)
(emacspeak-speak-matching-paren)))))))
(cl-loop
for f in
'(forward-word right-word)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak word."
(when (ems-interactive-p)
(skip-syntax-forward " ")
(emacspeak-speak-word)))))
(cl-loop
for f in
'(backward-word left-word)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak word."
(when (ems-interactive-p) (emacspeak-speak-word)))))
(cl-loop
for f in
'(beginning-of-buffer end-of-buffer)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak the line."
(when (ems-interactive-p)
(emacspeak-icon 'large-movement)
(emacspeak-speak-line)
(dtk-notify (emacspeak-get-current-percentage-verbously))))))
(cl-loop
for f in
'(
tab-to-tab-stop indent-for-tab-command reindent-then-newline-and-indent
indent-sexp indent-pp-sexp
indent-region indent-relative)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(emacspeak-icon 'fill-object)
(emacspeak-speak-current-column)))))
(cl-loop
for f in
'(backward-sentence forward-sentence)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak sentence."
(when (ems-interactive-p) (emacspeak-speak-sentence)))))
(cl-loop
for f in
'(forward-sexp backward-sexp
beginning-of-defun end-of-defun)
do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak sexp or line."
(if (ems-interactive-p)
(let ((start (point))
(end (line-end-position))
(emacspeak-show-point t))
ad-do-it
(emacspeak-icon 'large-movement)
(cond
((>= end (point))
(emacspeak-speak-region start (point)))
(t (emacspeak-speak-line))))
ad-do-it)
ad-return-value)))
(cl-loop
for f in
'(forward-paragraph backward-paragraph)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak paragraph."
(when (ems-interactive-p)
(emacspeak-icon 'paragraph)
(emacspeak-speak-paragraph)))))
;; list navigation:
(cl-loop
for f in
'(
forward-list backward-list
up-list backward-up-list down-list)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak line."
(when (ems-interactive-p)
(let ((emacspeak-show-point t))
(emacspeak-icon 'large-movement)
(emacspeak-speak-line))))))
(cl-loop
for f in
'(forward-page backward-page)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(emacspeak-icon 'scroll)
(emacspeak-speak-page)))))
(cl-loop
for f in
'(scroll-other-window scroll-other-window-up scroll-other-window-down)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(save-window-excursion
(with-selected-window (other-window-for-scrolling)
(emacspeak-speak-windowful)))))))
(cl-loop
for f in
'(
scroll-up scroll-down
scroll-up-command scroll-down-command)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak next screenful."
(when (ems-interactive-p)
(emacspeak-icon 'scroll)
(dtk-notify
(propertize
(format "%s " (emacspeak-get-current-percentage-into-buffer))
'personality voice-smoothen))
(dtk-speak (emacspeak-get-window-contents))))))
;;; Advise modify case commands to speak
(defadvice upcase-word (around emacspeak pre act comp)
"Provide a tone, then Speak the word at point. "
(cond
((ems-interactive-p)
(dtk-tone-upcase)
(cond
((and (numberp current-prefix-arg)
(< current-prefix-arg 0))
ad-do-it
(let ((start (point)))
(save-excursion
(forward-word current-prefix-arg)
(emacspeak-speak-region start (point)))))
(t ad-do-it
(save-excursion
(skip-syntax-forward " ")
(if (eobp)
(message "Upper cased final word in buffer")
(emacspeak-speak-word))))))
(t ad-do-it))
ad-return-value)
(defadvice downcase-word (around emacspeak pre act comp)
"Provide a tone and Speak word at point. "
(cond
((ems-interactive-p)
(dtk-tone-downcase)
(cond
((and (numberp current-prefix-arg)
(< current-prefix-arg 0))
ad-do-it
(let ((start (point)))
(save-excursion
(forward-word current-prefix-arg)
(emacspeak-speak-region start (point)))))
(t ad-do-it
(save-excursion
(skip-syntax-forward " ")
(if (eobp)
(message "Lower cased final word in buffer")
(emacspeak-speak-word))))))
(t ad-do-it))
ad-return-value)
(defadvice capitalize-word (around emacspeak pre act comp)
"Provide a tone and Speak word at point. "
(cond
((ems-interactive-p)
(dtk-tone-upcase)
(cond
((and (numberp current-prefix-arg)
(< current-prefix-arg 0))
ad-do-it
(let ((start (point)))
(save-excursion
(forward-word current-prefix-arg)
(emacspeak-speak-region start (point)))))
(t ad-do-it
(save-excursion
(skip-syntax-forward " ")
(if (eobp)
(message "Capitalized final word in buffer")
(emacspeak-speak-word))))))
(t ad-do-it))
ad-return-value)
;;; Advice insert-char:
(defadvice insert-char (after emacspeak pre act comp)
"Speak char."
(when (ems-interactive-p) (emacspeak-speak-char-name (ad-get-arg 0))))
;;; Advice deletion commands:
(cl-loop
for f in
'(backward-delete-char backward-delete-char-untabify delete-backward-char)
do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak deleted character."
(cond
((ems-interactive-p)
(dtk-tone-deletion)
(emacspeak-speak-this-char (preceding-char))
ad-do-it)
(t ad-do-it))
ad-return-value)))
(cl-loop
for f in
'(delete-forward-char delete-char) do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak deleted character."
(cond
((ems-interactive-p)
(dtk-tone-deletion)
(emacspeak-speak-char t)
ad-do-it)
(t ad-do-it))
ad-return-value)))
(defadvice kill-word (before emacspeak pre act comp)
"Speak word beingkilled."
(when (ems-interactive-p)
(save-excursion
(skip-syntax-forward " ")
(dtk-tone-deletion)
(emacspeak-speak-word 1))))
(defadvice backward-kill-word (before emacspeak pre act comp)
"Speak word beingkilled."
(when (ems-interactive-p)
(save-excursion
(let ((start (point)))
(forward-word -1)
(dtk-tone-deletion)
(emacspeak-speak-region (point) start)))))
(cl-loop
for f in
'(kill-line kill-whole-line)
do
(eval
`(defadvice ,f (before emacspeak pre act comp)
"Speak line being killed. "
(when (ems-interactive-p)
(emacspeak-icon 'delete-object)
(dtk-tone-deletion)
(emacspeak-speak-line 1)))))
(defadvice kill-sexp (before emacspeak pre act comp)
"Speak the killed sexp."
(when (ems-interactive-p)
(emacspeak-icon 'delete-object)
(dtk-tone-deletion)
(emacspeak-speak-sexp 1)))
(defadvice kill-sentence (before emacspeak pre act comp)
"Speak the kill."
(when (ems-interactive-p)
(emacspeak-icon 'delete-object)
(dtk-tone-deletion)
(emacspeak-speak-line 1)))
(defadvice delete-blank-lines (before emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(let (thisblank singleblank)
(save-excursion
(forward-line 0)
(setq thisblank (looking-at "[ \t]*$"))
;; Set singleblank if there is just one blank line here.
(setq singleblank
(and thisblank
(not (looking-at "[ \t]*\n[ \t]*$"))
(or (bobp)
(progn (forward-line -1)
(not (looking-at "[ \t]*$")))))))
(cond
((and thisblank singleblank)
(message "Deleting current blank line"))
(thisblank (message "Deleting surrounding blank lines"))
(t (message "Deleting possible subsequent blank lines"))))))
;;; advice tabify:
(defadvice untabify (after emacspeak pre act comp)
"Fix NBSP chars."
(let ((start (ad-get-arg 0))
(end (ad-get-arg 1)))
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char start)
(while (re-search-forward (format "[%c]+" 160) end 'no-error)
(replace-match " "))))))
;;; Advice PComplete
(defadvice pcomplete-list (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(emacspeak-icon 'help)
(emacspeak-icon 'complete)))
(defadvice pcomplete-show-completions (around emacspeak pre act comp)
(ems-with-messages-silenced ad-do-it))
(defadvice pcomplete (around emacspeak pre act comp)
"Speak completion."
(let ((orig (save-excursion (skip-syntax-backward "^ >") (point))))
ad-do-it
(when (ems-interactive-p)
(emacspeak-speak-region orig (point))
(emacspeak-icon 'complete))
ad-return-value))
;;; Advice hippie expand:
(cl-loop
for f in
'(hippie-expand complete)
do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak completion."
(cond
((ems-interactive-p)
(let ((orig (save-excursion (skip-syntax-backward "^ >") (point))))
(ems-with-messages-silenced
ad-do-it
(emacspeak-icon 'complete)
(if (< orig (point))
(dtk-speak (buffer-substring orig (point)))
(dtk-speak (word-at-point))))))
(t ad-do-it))
ad-return-value)))
;;; advice minibuffer to speak
(voice-setup-set-voice-for-face 'minibuffer-prompt 'voice-bolden)
(defadvice minibuffer-completion-help (around emacspeak pre act comp)
"Silence messages"
(ems-with-messages-silenced ad-do-it))
(defadvice quoted-insert (after emacspeak pre act comp)
"Speak inserted character."
(when (ems-interactive-p)
(emacspeak-speak-this-char (preceding-char))))
(defadvice read-event (before emacspeak pre act comp)
"Speak prompt."
(when (ad-get-arg 0)
(dtk-notify (ad-get-arg 0))))
(defadvice read-multiple-choice (before emacspeak pre act comp)
"speak."
(let ((dtk-stop-immediately nil)
(msg (ad-get-arg 0))
(choices
(mapcar
#'(lambda (c)
(format "%c: %s"
(cl-first c) (cl-second c)))
(ad-get-arg 1)))
(details
(mapcar
#'(lambda (c)
(format "%c: %s: %s"
(cl-first c) (cl-second c)
(or (cl-third c) "")))
(ad-get-arg 1))))
(emacspeak-icon 'open-object)
(ems--log-message
(concat msg
(mapconcat #'identity details "\n ")))
(dtk-notify msg)
(sox-tones 2 2)
(dtk-speak-list choices)))
(cl-loop
for f in
'(
minibuffer-complete-history
next-history-element previous-history-element
next-line-or-history-element previous-line-or-history-element
previous-matching-history-element next-matching-history-element)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak the completion element just inserted."
(when (ems-interactive-p)
(emacspeak-icon 'select-object)
(tts-with-punctuations 'all
(dtk-speak
(or (minibuffer-contents)
(emacspeak-get-current-completion))))))))
(cl-loop
for f in
'( minibuffer-next-completion minibuffer-previous-completion
minibuffer-next-line-completion minibuffer-previous-line-completion)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(tts-with-punctuations 'all
(emacspeak-icon 'item)
(dtk-speak
(emacspeak-get-current-completion)))))))
(defvar emacspeak-last-message nil
"Last output from `message'.")
(defvar ems--lazy-msg-time (current-time)
"Time message was spoken")
(defcustom emacspeak-speak-messages-filter
'("Decrypting" "psession" "auto saving")
"List of strings used to filter spoken messages."
:type '(repeat :tag "Filtered Strings"
(string :tag "String" ))
:set
#'(lambda (sym val)
(set-default sym val ) ; turn list into a pattern to use
(setq ems--message-filter (regexp-opt val)))
:group 'emacspeak-speak)
(defadvice momentary-string-display (around emacspeak pre act comp)
"Speak."
(ems-with-messages-silenced
(let ((msg (ad-get-arg 0))
(exit (ad-get-arg 2)))
(dtk-notify
(format
"%s Press %s to exit"
msg
(if exit (format "%c" exit) "space")))
ad-do-it)))
(defadvice progress-reporter-do-update (around emacspeak pre act comp)
"Silence progress reporters."
(ems-with-messages-silenced ad-do-it)
(when ad-return-value (emacspeak-icon 'progress)))
(defadvice progress-reporter-done (after emacspeak pre act comp)
"speak."
(emacspeak-icon 'time))
(cl-loop
for f in
'( minibuffer-message set-minibuffer-message
message display-message-or-buffer) do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak message. Duplicates will not be spoken."
(cl-declare (special
emacspeak-last-message inhibit-message
ems--message-filter emacspeak-speak-messages))
(let ((m nil)
(o minibuffer-message-overlay))
ad-do-it
(cond
((or inhibit-message (null emacspeak-speak-messages)) ad-return-value)
(t ; possibly peak it
(setq m
(or (current-message) (and o (overlay-get o 'after-string))))
(when m (setq m (string-trim m)))
(when
(and ;dup throttle
m
(not (zerop (length m)))
(not (string= m emacspeak-last-message))
(not (string-match ems--message-filter m)))
(setq emacspeak-last-message m)
;;; so we really need to speak it
(emacspeak-icon 'key)
(tts-with-punctuations 'all (dtk-notify m 'dont-log)))))
ad-return-value))))
(defadvice display-message-or-buffer (after emacspeak pre act comp)
"Icon"
(let ((buffer-name (ad-get-arg 1)))
(when (bufferp ad-return-value)
(dtk-notify
(format "Displayed message in buffer %s" buffer-name)))))
(defvar emacspeak--last-docs nil
"Last docs considered in `emacspeak-speak-eldoc'.")
(defun emacspeak-speak-eldoc (docs interactive)
"Speak eldoc. Intended for `eldoc-display-functions'."
(with-current-buffer (get-buffer-create " *emacspeak-eldoc*")
(erase-buffer)
(insert (mapconcat #'car docs "\n"))
(unless (equal docs emacspeak--last-docs)
(emacspeak-icon 'doc))
(when interactive (dtk-notify (buffer-string))))
(setq emacspeak--last-docs docs))
(with-eval-after-load "eldoc"
(add-hook 'eldoc-display-functions #'emacspeak-speak-eldoc)
(voice-setup-set-voice-for-face
'eldoc-highlight-function-argument 'voice-bolden))
(defadvice ange-ftp-process-handle-hash (around emacspeak pre act comp)
"Jibber intelligently."
(cl-declare (special ange-ftp-last-percent))
(ems-with-messages-silenced
ad-do-it
(emacspeak-icon 'progress)
(dtk-speak (format " %s percent" ange-ftp-last-percent))))
(cl-declaim (special command-error-function))
(setq command-error-function 'emacspeak-error-handler)
(defvar ems--last-error-msg nil
"Cache last error message.")
(defvar ems--lazy-error-time (current-time)
"Time error was spoken")
(defun emacspeak-error-handler (data _ _)
"Custom error handler"
(emacspeak-icon 'warn-user)
(message (propertize (error-message-string data) 'face 'error)))
(defconst ems--error-limit 1.0
"Seconds used to rate-limit error messages.")
(defun emacspeak-fancy-error-handler (data _ caller)
"Custom error handler."
(cl-declare (special ems--error-limit))
(cl-declare (special ems--last-error-msg
ems--lazy-error-time))
(let ((m (error-message-string data))
(fn (if caller (symbol-name caller) "")))
(when ; speak conditionally
(and
(not (string= ems--last-error-msg m)) ; dont repeat
(< ems--error-limit ; rate limit
(float-time (time-subtract (current-time) ems--lazy-msg-time))))
(setq ems--last-error-msg m
ems--lazy-error-time (current-time))
(emacspeak-icon 'warn-user)
(message
(concat
(propertize
(if (string-match "^ad-Advice" fn) (substring fn 10) fn)
'personality voice-bolden)
m )))))
;; Silence messages from async handlers:
(defadvice timer-event-handler (around emacspeak pre act comp)
"Silence messages from by timer events."
(ems-with-messages-silenced ad-do-it))
;;; Advice completion-at-point:
(defadvice completion-at-point (around emacspeak pre act comp)
"Speak completion."
(let ((orig (save-excursion (skip-syntax-backward "^->_") (point))))
ad-do-it
(when (ems-interactive-p) (dtk-speak (buffer-substring orig (point)))
(emacspeak-icon 'complete))
ad-return-value))
(defadvice minibuffer-choose-completion (around emacspeak pre act comp)
"Speak completion."
(let ((orig (save-excursion (skip-syntax-backward "^ >_") (point))))
ad-do-it
(when (ems-interactive-p)
(dtk-speak (buffer-substring orig (point)))
(emacspeak-icon 'complete))
ad-return-value))
(defadvice minibuffer-choose-completion-or-exit (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p)
(emacspeak-speak-line)
(emacspeak-icon 'close-object)))
;;; advice various input functions to speak:
;; read-password--hide-password
(defadvice read-passwd--hide-password (after emacspeak pre act comp)
"Icon."
(dtk-notify
(if read-passwd--hide-password
"dot"
(if (characterp last-input-event)
(format "%c" last-input-event)
"dot")))
(emacspeak-icon 'repeat-active))
(defadvice read-passwd-toggle-visibility (after emacspeak pre act comp)
"speak."
(when (ems-interactive-p) ; we see old value
(emacspeak-icon (if read-passwd--hide-password 'off 'on))))
(defadvice read-passwd (before emacspeak pre act comp)
"speak."
(emacspeak-icon 'open-object)
(dtk-speak (or (ad-get-arg 0) "password: "))
(emacspeak-icon 'pwd))
(defvar emacspeak-read-char-prompt-cache nil
"Cache prompt from read-char etc.")
(cl-loop
for f in
'(read-key read-key-sequence read-key-sequence-vector
read-char read-char-exclusive)
do
(eval
`(defadvice ,f (before emacspeak pre act comp)
"Speak prompt"
(let ((prompt (ad-get-arg 0)))
(emacspeak-icon 'char)
(setq emacspeak-last-message prompt)
(setq emacspeak-read-char-prompt-cache prompt)
(tts-with-punctuations 'all (dtk-notify (or prompt "key")))))))
(defadvice read-char-choice (before emacspeak pre act comp)
"Speak the prompt. "
(let* ((prompt (ad-get-arg 0))
(chars (ad-get-arg 1))
(m
(format
"%s: %s"
prompt
(mapconcat #'(lambda (c) (format "%c" c)) chars ", "))))
(ems--log-message m)
(tts-with-punctuations 'all (dtk-speak m))))
;;; advice completion functions to speak:
(cl-loop
for f in
'(dabbrev-expand dabbrev-completion)
do
(eval
`(defadvice ,f (after emacspeak pre act comp)
"Speak completion."
(when (ems-interactive-p)
(accept-process-output)
(tts-with-punctuations 'all (dtk-speak dabbrev--last-expansion))))))
(voice-setup-add-map
'(
(completions-annotations voice-annotate)
(completions-common-part voice-monotone-extra)
(completions-first-difference voice-bolden)))
(cl-loop
for f in
'(
minibuffer-complete-word minibuffer-complete
crm-complete-word crm-complete crm-complete-and-exit
crm-minibuffer-complete crm-minibuffer-complete-and-exit)
do
(eval
`(defadvice ,f (around emacspeak pre act comp)
"Speak completion."
(cond
((ems-interactive-p)
(ems-with-messages-silenced
(let ((prior (point)))
(emacspeak-kill-buffer-carefully "*Completions*")
ad-do-it
(if (> (point) prior)
(tts-with-punctuations
'all (dtk-speak (buffer-substring (point) prior)))
(emacspeak-speak-completions-if-available)))))
(t ad-do-it))
ad-return-value)))