PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/emacspeak-29.0/lisp/emacspeak-ispell.el

#
Emacs Lisp | 205 lines | 109 code | 26 blank | 70 comment | 5 complexity | a54d934098661399a7afe86ef63cbc37 MD5 | raw file
Possible License(s): MIT
  1. ;;; emacspeak-ispell.el --- Speech enable Ispell -- Emacs' interactive spell checker
  2. ;;; $Id: emacspeak-ispell.el 5798 2008-08-22 17:35:01Z tv.raman.tv $
  3. ;;; $Author: tv.raman.tv $
  4. ;;; Description: Emacspeak extension to speech enable ispell
  5. ;;; Keywords: Emacspeak, Ispell, Spoken Output, Ispell version 2.30
  6. ;;{{{ LCD Archive entry:
  7. ;;; LCD Archive Entry:
  8. ;;; emacspeak| T. V. Raman |raman@cs.cornell.edu
  9. ;;; A speech interface to Emacs |
  10. ;;; $Date: 2007-08-25 18:28:19 -0700 (Sat, 25 Aug 2007) $ |
  11. ;;; $Revision: 4532 $ |
  12. ;;; Location undetermined
  13. ;;;
  14. ;;}}}
  15. ;;{{{ Copyright:
  16. ;;;Copyright (C) 1995 -- 2007, T. V. Raman
  17. ;;; Copyright (c) 1994, 1995 by Digital Equipment Corporation.
  18. ;;; All Rights Reserved.
  19. ;;;
  20. ;;; This file is not part of GNU Emacs, but the same permissions apply.
  21. ;;;
  22. ;;; GNU Emacs is free software; you can redistribute it and/or modify
  23. ;;; it under the terms of the GNU General Public License as published by
  24. ;;; the Free Software Foundation; either version 2, or (at your option)
  25. ;;; any later version.
  26. ;;;
  27. ;;; GNU Emacs is distributed in the hope that it will be useful,
  28. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. ;;; GNU General Public License for more details.
  31. ;;;
  32. ;;; You should have received a copy of the GNU General Public License
  33. ;;; along with GNU Emacs; see the file COPYING. If not, write to
  34. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  35. ;;}}}
  36. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  37. ;;{{{ Introduction:
  38. ;;; This module speech enables ispell.
  39. ;;; Implementation note: This is hard because of how ispell.el is written
  40. ;;; Namely, all of the work is done by one huge hairy function.
  41. ;;; This makes advising it hard.
  42. ;;; Original version of this extension was written under emacs-19.28
  43. ;;; for ispell.el version 2.30
  44. ;;; Now updating it for ispell.el version 2.37.
  45. ;;; Support for 2.30 will wither away
  46. ;;}}}
  47. ;;{{{ requires
  48. (require 'emacspeak-preamble)
  49. ;;}}}
  50. ;;{{{ define personalities
  51. (voice-setup-add-map
  52. '(
  53. (ispell-highlight-face voice-bolden)
  54. ))
  55. ;;}}}
  56. ;;{{{ first set up voice highlighting
  57. (defadvice ispell-highlight-spelling-error (after emacspeak act )
  58. "Use voice locking to highlight the error.
  59. Will clobber any existing personality property defined on start end"
  60. (let ((start (ad-get-arg 0))
  61. (end (ad-get-arg 1 ))
  62. (highlight (ad-get-arg 2 )))
  63. (if highlight
  64. (put-text-property start end
  65. 'personality voice-bolden)
  66. (put-text-property start end
  67. 'personality nil ))))
  68. ;;}}}
  69. ;;{{{ ispell command loop:
  70. ;;;Signature for ispell-command-loop in 2.30
  71. ;;;defun ispell-command-loop (miss guess word)
  72. ;;;Signature in 2.37:
  73. ;;; defun ispell-command-loop (miss guess word start end)
  74. ;;; Advice speaks the line containing the error with the erroneous
  75. ;;; word highlighted.
  76. ;;{{{ new version
  77. (defgroup emacspeak-ispell nil
  78. "Spell checking group."
  79. :group 'emacspeak)
  80. (defcustom emacspeak-ispell-max-choices 10
  81. "Emacspeak will not speak the choices if there are more than this
  82. many available corrections."
  83. :type 'number
  84. :group 'emacspeak-ispell)
  85. (defadvice ispell-command-loop (before emacspeak pre act )
  86. "Speak the line containing the incorrect word.
  87. Then speak the possible corrections. "
  88. (let ((scratch-buffer (get-buffer-create " *dtk-scratch-buffer* "))
  89. (choices (ad-get-arg 0 ))
  90. (line nil)
  91. (start (ad-get-arg 3))
  92. (end (ad-get-arg 4))
  93. (position 0))
  94. (setq line
  95. (ems-set-personality-temporarily start end voice-bolden
  96. (thing-at-point
  97. 'line)))
  98. (save-excursion
  99. (set-buffer scratch-buffer)
  100. (setq voice-lock-mode t)
  101. (setq buffer-undo-list t)
  102. (dtk-set-punctuations 'all)
  103. (erase-buffer)
  104. (insert line)
  105. (cond
  106. ((< (length choices)
  107. emacspeak-ispell-max-choices)
  108. (loop for choice in choices
  109. do
  110. (insert (format "%s %s\n" position choice))
  111. (incf position)))
  112. (t (insert
  113. (format "There were %s corrections available."
  114. (length choices)))))
  115. (modify-syntax-entry 10 ">")
  116. (dtk-speak (buffer-string )))))
  117. ;;}}}
  118. (defadvice ispell-comments-and-strings (around emacspeak pre act comp)
  119. "Stop chatter by turning off messages"
  120. (cond
  121. ((interactive-p)
  122. (let ((dtk-stop-immediately t )
  123. (voice-lock-mode t)
  124. (emacspeak-speak-messages nil))
  125. ad-do-it
  126. (emacspeak-auditory-icon 'task-done)))
  127. (t ad-do-it)))
  128. (defadvice ispell-help (before emacspeak pre act)
  129. "Speak the help message. "
  130. (let ((dtk-stop-immediately nil))
  131. (dtk-speak (documentation 'ispell-help ))))
  132. ;;}}}
  133. ;;{{{ Advice top-level ispell commands:
  134. (defadvice ispell-buffer (around emacspeak pre act comp)
  135. "Produce auditory icons for ispell."
  136. (cond
  137. ((interactive-p)
  138. (let ((dtk-stop-immediately t )
  139. (voice-lock-mode t)
  140. (emacspeak-speak-messages nil))
  141. ad-do-it
  142. (emacspeak-auditory-icon 'task-done)))
  143. (t ad-do-it))
  144. ad-return-value)
  145. (defadvice ispell-region (around emacspeak pre act comp)
  146. "Produce auditory icons for ispell."
  147. (cond
  148. ((interactive-p)
  149. (let ((dtk-stop-immediately t )
  150. (voice-lock-mode t)
  151. (emacspeak-speak-messages nil))
  152. ad-do-it
  153. (emacspeak-auditory-icon 'task-done)))
  154. (t ad-do-it))
  155. ad-return-value)
  156. (defadvice ispell-word (around emacspeak pre act comp)
  157. "Produce auditory icons for ispell."
  158. (declare (special emacspeak-last-message))
  159. (cond
  160. ((interactive-p)
  161. (let ((dtk-stop-immediately t )
  162. (voice-lock-mode t)
  163. (emacspeak-speak-messages nil))
  164. (setq emacspeak-last-message nil)
  165. ad-do-it
  166. (when (interactive-p)
  167. (emacspeak-speak-message-again))
  168. (emacspeak-auditory-icon 'task-done)))
  169. (t ad-do-it))
  170. ad-return-value)
  171. ;;}}}
  172. (provide 'emacspeak-ispell)
  173. ;;{{{ emacs local variables
  174. ;;; local variables:
  175. ;;; folded-file: t
  176. ;;; byte-compile-dynamic: t
  177. ;;; end:
  178. ;;}}}