1 ;;; spell.el --- spelling correction interface for Emacs.
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 (defvar spell-command
"spell"
23 "*Command to run the spell program.")
25 (defvar spell-filter nil
26 "*Filter function to process text before passing it to spell program.
27 This function might remove text-processor commands.
28 nil means don't alter the text before checking it.")
31 (defun spell-buffer ()
32 "Check spelling of every word in the buffer.
33 For each incorrect word, you are asked for the correct spelling
34 and then put into a query-replace to fix some or all occurrences.
35 If you do not want to change a word, just give the same word
36 as its \"correct\" spelling; then the query replace is skipped."
38 (spell-region (point-min) (point-max) "buffer"))
42 "Check spelling of word at or before point.
43 If it is not correct, ask user for the correct spelling
44 and query-replace the entire buffer to substitute it."
46 (let (beg end spell-filter
)
48 (if (not (looking-at "\\<"))
53 (spell-region beg end
(buffer-substring beg end
))))
56 (defun spell-region (start end
&optional description
)
57 "Like spell-buffer but applies only to region.
58 Used in a program, applies from START to END.
59 DESCRIPTION is an optional string naming the unit being checked:
60 for example, \"word\"."
62 (let ((filter spell-filter
)
63 (buf (get-buffer-create " *temp*")))
68 (message "Checking spelling of %s..." (or description
"region"))
69 (if (and (null filter
) (= ?
\n (char-after (1- end
))))
70 (if (string= "spell" spell-command
)
71 (call-process-region start end
"spell" nil buf
)
72 (call-process-region start end shell-file-name
73 nil buf nil
"-c" spell-command
))
74 (let ((oldbuf (current-buffer)))
77 (insert-buffer-substring oldbuf start end
)
78 (or (bolp) (insert ?
\n))
79 (if filter
(funcall filter
))
80 (if (string= "spell" spell-command
)
81 (call-process-region (point-min) (point-max) "spell" t buf
)
82 (call-process-region (point-min) (point-max) shell-file-name
83 t buf nil
"-c" spell-command
)))))
84 (message "Checking spelling of %s...%s"
85 (or description
"region")
94 (while (save-excursion
99 (goto-char (point-min))
101 (buffer-substring (point)
102 (progn (end-of-line) (point)))))
104 (delete-region (point-min) (point))
106 (read-input (concat "`" word
107 "' not recognized; edit a replacement: ")
109 (flush-lines (concat "^" (regexp-quote word
) "$")))
110 (if (not (equal word newword
))
112 (goto-char (point-min))
113 (query-replace-regexp (concat "\\b" (regexp-quote word
) "\\b")
118 (defun spell-string (string)
119 "Check spelling of string supplied as argument."
120 (interactive "sSpell string: ")
121 (let ((buf (get-buffer-create " *temp*")))
127 (if (string= "spell" spell-command
)
128 (call-process-region (point-min) (point-max) "spell"
130 (call-process-region (point-min) (point-max) shell-file-name
131 t t nil
"-c" spell-command
))
132 (if (= 0 (buffer-size))
133 (message "%s is correct" string
)
134 (goto-char (point-min))
135 (while (search-forward "\n" nil t
)
137 (message "%sincorrect" (buffer-substring 1 (point-max)))))))
139 ;;; spell.el ends here