home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / ispell-mode.el < prev    next >
Encoding:
Text File  |  1993-03-02  |  3.8 KB  |  106 lines

  1. ;;;
  2. ;;; ISPELL-MODE.EL -- electric minor mode interface to ispell package.
  3. ;;; in auto-ispell-mode `space' or `return' automatically trigger `ispell-word'
  4. ;;; on previously typed word.
  5.  
  6. ;;; Avishai Yacoby
  7.  
  8. ;; LCD Archive Entry:
  9. ;; ispell-mode|Avishai Yacobi|avishaiy@mcil.comm.mot.com|
  10. ;; Electric minor mode interface to ispell package.|
  11. ;; 1993-02-16||~/modes/ispell-mode.el.Z|
  12.  
  13. ;;
  14. ;; This file is not part of the GNU Emacs distribution (yet).
  15. ;;
  16. ;; This file is distributed in the hope that it will be useful,
  17. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  18. ;; accepts responsibility to anyone for the consequences of using it
  19. ;; or for whether it serves any particular purpose or works at all,
  20. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  21. ;; License for full details.
  22.  
  23. ;; Everyone is granted permission to copy, modify and redistribute
  24. ;; this file, but only under the conditions described in the
  25. ;; GNU Emacs General Public License.   A copy of this license is
  26. ;; supposed to have been given to you along with GNU Emacs so you
  27. ;; can know your rights and responsibilities.  It should be in a
  28. ;; file named COPYING.  Among other things, the copyright notice
  29. ;; and this notice must be preserved on all copies.
  30.  
  31. (defvar auto-ispell-flag nil)
  32.  
  33. (defvar aim-origin-keymap nil)
  34.  
  35. (defvar aim-space-hook nil)
  36.  
  37. (defvar aim-tab-hook nil)
  38.  
  39. (defvar aim-ret-hook nil)
  40.  
  41. (defun auto-ispell-mode ()
  42.   "Toggle auto-ispell-mode.
  43.  
  44. In auto-ispell-mode, inserting a space or a new line applies ispell-word
  45. on the previous word.
  46.  
  47. Pressing Esc-Tab activates ispell-complete-word.
  48. "
  49.   (interactive)
  50.   (if (not auto-ispell-flag)
  51.       (progn
  52.         (make-local-variable 'auto-ispell-flag)
  53.         (make-local-variable 'aim-ret-hook)
  54.         (make-local-variable 'aim-tab-hook)
  55.         (make-local-variable 'aim-space-hook)
  56.         (make-local-variable 'aim-origin-keymap)
  57.         (setq aim-origin-keymap (current-local-map))
  58.         (setq aim-space-hook (if aim-origin-keymap (lookup-key aim-origin-keymap " ") nil))
  59.         (setq aim-tab-hook (if aim-origin-keymap (lookup-key aim-origin-keymap "    ") nil))
  60.         (setq aim-ret-hook (if aim-origin-keymap (lookup-key aim-origin-keymap "\C-m") nil))
  61.         (use-local-map (if aim-origin-keymap
  62.                            (copy-keymap aim-origin-keymap)
  63.                          (make-sparse-keymap)))
  64.         (define-key (current-local-map) " " 'auto-ispell-space)
  65.         (define-key (current-local-map) "\C-m" 'auto-ispell-ret)
  66.         (define-key (current-local-map) "\t" 'ispell-complete-word)
  67.         (setq-default auto-ispell-flag nil)
  68.         (or (assq 'auto-ispell-flag minor-mode-alist)
  69.             (setq minor-mode-alist
  70.                   (cons '(auto-ispell-flag " Spell") minor-mode-alist)))
  71.         (setq auto-ispell-flag t))
  72.     (use-local-map aim-origin-keymap)
  73.     (kill-local-variable 'auto-ispell-flag)
  74.     (kill-local-variable 'aim-ret-hook)
  75.     (kill-local-variable 'aim-tab-hook)
  76.     (kill-local-variable 'aim-space-hook)
  77.     (kill-local-variable 'aim-origin-keymap)
  78.     (setq auto-ispell-flag nil))
  79.   (set-buffer-modified-p (buffer-modified-p)))
  80.  
  81. (defun auto-ispell-space ()
  82.   (interactive)
  83.   (if (and (commandp aim-space-hook)
  84.        (not (eq aim-space-hook 'self-insert-command))
  85.        (not (eq aim-space-hook 'auto-ispell-space)))
  86.       (run-hooks 'aim-space-hook)
  87.     (insert " "))
  88.   (if (> (current-column) fill-column)
  89.       (run-hooks 'auto-fill-hook))
  90.   (save-excursion
  91.     (backward-word 1)
  92.     (ispell-word)))
  93.  
  94. (defun auto-ispell-ret ()
  95.   (interactive)
  96.   (if (and (commandp aim-ret-hook)
  97.        (not (eq aim-ret-hook 'self-insert-command))
  98.        (not (eq aim-ret-hook 'auto-ispell-ret)))
  99.       (run-hooks 'aim-ret-hook)
  100.     (if (> (current-column) fill-column)
  101.     (run-hooks 'auto-fill-hook))
  102.     (insert "\n"))
  103.   (save-excursion
  104.     (backward-word 1)
  105.     (ispell-word)))
  106.