aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-08-03 03:27:54 +0000
committerRichard M. Stallman1998-08-03 03:27:54 +0000
commit65a5c06afd122d584817b3de932e1b0a545cf570 (patch)
tree63a551da0eeef650b4d7c940d772fc7d7601bf03
parent49da2e496a3aa14f51b234a9dc5c9b2e80e40a04 (diff)
downloademacs-65a5c06afd122d584817b3de932e1b0a545cf570.tar.gz
emacs-65a5c06afd122d584817b3de932e1b0a545cf570.zip
(flyspell-duplicate-distance): Doc fix; change default to 10000.
(flyspell-mode-on): Fix the welcome message to deal with how the binding for flyspell-auto-correct-word is now made. (flyspell-delay, flyspell-delayed-commands): Doc fixes. (flyspell-mode-off): Kill Ispell only if it is per-buffer. (flyspell-mode-map): Explicitly bind M-TAB. (flyspell-auto-correct-binding): Variable deleted. (flyspell-incorrect-face, flyspell-duplicate-face): Fix typos. (flyspell-check-pre-word-p): Check for word syntax in previous char. (flyspell-word): Set process-kill-without-query for Ispell. (flyspell-region): Put region args in order; use right percantage. (flyspell-properties-at-p): Rename arg to POS; doc fix. (flyspell-highlight-incorrect-region): Check flyspell-highlight-properties first. (flyspell-highlight-duplicate-region): Likewise. (flyspell-auto-correct-word): Doc fix.
-rw-r--r--lisp/textmodes/flyspell.el101
1 files changed, 59 insertions, 42 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index 0550e585ee0..da6b98dff6b 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -27,7 +27,8 @@
27;; Flyspell is a minor Emacs mode performing on-the-fly spelling 27;; Flyspell is a minor Emacs mode performing on-the-fly spelling
28;; checking. 28;; checking.
29;; 29;;
30;; To enter the flyspell minor mode, Meta-x flyspell-mode. 30;; To enable Flyspell minor mode, type Meta-x flyspell-mode.
31;; This applies only to the current buffer.
31;; 32;;
32;; Note: consider setting the variable ispell-parser to `tex' to 33;; Note: consider setting the variable ispell-parser to `tex' to
33;; avoid TeX command checking; use `(setq ispell-parser 'tex)' 34;; avoid TeX command checking; use `(setq ispell-parser 'tex)'
@@ -44,6 +45,9 @@
44(require 'font-lock) 45(require 'font-lock)
45(require 'ispell) 46(require 'ispell)
46 47
48;*---------------------------------------------------------------------*/
49;* Group ... */
50;*---------------------------------------------------------------------*/
47(defgroup flyspell nil 51(defgroup flyspell nil
48 "Spellchecking on the fly." 52 "Spellchecking on the fly."
49 :tag "FlySpell" 53 :tag "FlySpell"
@@ -70,26 +74,20 @@ Non-nil means use highlight, nil means use minibuffer messages."
70 :group 'flyspell 74 :group 'flyspell
71 :type 'boolean) 75 :type 'boolean)
72 76
73(defcustom flyspell-auto-correct-binding "\M-\t"
74 "*Non-nil means that its value (a binding) will bound to the flyspell
75auto-correct."
76 :group 'flyspell
77 :type '(choice (const nil) string))
78
79(defcustom flyspell-command-hook t 77(defcustom flyspell-command-hook t
80 "*Non-nil means that `post-command-hook' is used to check already-typed words." 78 "*Non-nil means that `post-command-hook' is used to check already-typed words."
81 :group 'flyspell 79 :group 'flyspell
82 :type 'boolean) 80 :type 'boolean)
83 81
84(defcustom flyspell-duplicate-distance -1 82(defcustom flyspell-duplicate-distance 10000
85 "*The distance from duplication. 83 "*The maximum distance between duplicate mispelled words, for flagging them.
86-1 means no limit. 84-1 means no limit (search the whole buffer).
870 means no window." 850 means do not search for duplicate misspelled words."
88 :group 'flyspell 86 :group 'flyspell
89 :type 'number) 87 :type 'number)
90 88
91(defcustom flyspell-delay 3 89(defcustom flyspell-delay 3
92 "*The number of seconds to wait before checking words, for a \"delayed\" command." 90 "*The number of seconds to wait before checking, after a \"delayed\" command."
93 :group 'flyspell 91 :group 'flyspell
94 :type 'number) 92 :type 'number)
95 93
@@ -114,12 +112,13 @@ See `flyspell-delayed-commands'."
114 112
115(defcustom flyspell-delayed-commands nil 113(defcustom flyspell-delayed-commands nil
116 "List of commands that are \"delayed\" for Flyspell mode. 114 "List of commands that are \"delayed\" for Flyspell mode.
117These commands do not activate flyspell checking." 115After these commands, Flyspell checking is delayed for a short time,
116whose length is specified by `flyspell-delay'."
118 :group 'flyspell 117 :group 'flyspell
119 :type '(repeat (symbol))) 118 :type '(repeat (symbol)))
120 119
121(defcustom flyspell-issue-welcome-flag t 120(defcustom flyspell-issue-welcome-flag t
122 "*Non-nil means that Flyspell issues a welcome message when started." 121 "*Non-nil means that Flyspell should display a welcome message when started."
123 :group 'flyspell 122 :group 'flyspell
124 :type 'boolean) 123 :type 'boolean)
125 124
@@ -202,7 +201,7 @@ property of the major mode name.")
202 'xemacs) 201 'xemacs)
203 (t 202 (t
204 'emacs)) 203 'emacs))
205 "The Emacs we are currently running.") 204 "The type of Emacs we are currently running.")
206 205
207;*---------------------------------------------------------------------*/ 206;*---------------------------------------------------------------------*/
208;* The minor mode declaration. */ 207;* The minor mode declaration. */
@@ -222,9 +221,8 @@ property of the major mode name.")
222 (cons (cons 'flyspell-mode flyspell-mode-map) 221 (cons (cons 'flyspell-mode flyspell-mode-map)
223 minor-mode-map-alist))) 222 minor-mode-map-alist)))
224 223
225(if flyspell-auto-correct-binding 224(define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word)
226 (define-key flyspell-mode-map flyspell-auto-correct-binding 225
227 (function flyspell-auto-correct-word)))
228;; mouse bindings 226;; mouse bindings
229(cond 227(cond
230 ((eq flyspell-emacs 'xemacs) 228 ((eq flyspell-emacs 'xemacs)
@@ -239,23 +237,22 @@ property of the major mode name.")
239 (if (string-match "19.*XEmacs" emacs-version) 237 (if (string-match "19.*XEmacs" emacs-version)
240 'keymap 238 'keymap
241 'local-map)) 239 'local-map))
242 240
243;*---------------------------------------------------------------------*/ 241;*---------------------------------------------------------------------*/
244;* Highlighting */ 242;* Highlighting */
245;*---------------------------------------------------------------------*/ 243;*---------------------------------------------------------------------*/
246(defface flyspell-incorrect-face 244(defface flyspell-incorrect-face
247 '((((class color)) (:foreround "OrangeRed")) 245 '((((class color)) (:foreground "OrangeRed" :bold t :underline t))
248 (t (:bold t))) 246 (t (:bold t)))
249 "Face used for showing misspelled words in Flyspell." 247 "Face used for showing misspelled words in Flyspell."
250 :group 'flyspell) 248 :group 'flyspell)
251 249
252(defface flyspell-duplicate-face 250(defface flyspell-duplicate-face
253 '((((class color)) (:foreround "Gold3")) 251 '((((class color)) (:foreground "Gold3" :bold t :underline t))
254 (t (:bold t))) 252 (t (:bold t)))
255 "Face used for showing misspelled words in Flyspell." 253 "Face used for showing misspelled words in Flyspell."
256 :group 'flyspell) 254 :group 'flyspell)
257 255
258
259(defvar flyspell-overlay nil) 256(defvar flyspell-overlay nil)
260 257
261;*---------------------------------------------------------------------*/ 258;*---------------------------------------------------------------------*/
@@ -315,7 +312,7 @@ flyspell-buffer checks the whole buffer."
315 (make-variable-buffer-local 'ispell-filter-continue) 312 (make-variable-buffer-local 'ispell-filter-continue)
316 (make-variable-buffer-local 'ispell-process-directory) 313 (make-variable-buffer-local 'ispell-process-directory)
317 (make-variable-buffer-local 'ispell-parser))) 314 (make-variable-buffer-local 'ispell-parser)))
318 ;; we initialize delayed commands symbol 315 ;; We put the `flyspel-delayed' property on some commands.
319 (flyspell-delay-commands) 316 (flyspell-delay-commands)
320 ;; we bound flyspell action to post-command hook 317 ;; we bound flyspell action to post-command hook
321 (if flyspell-command-hook 318 (if flyspell-command-hook
@@ -333,17 +330,21 @@ flyspell-buffer checks the whole buffer."
333 (function flyspell-pre-command-hook) 330 (function flyspell-pre-command-hook)
334 t 331 t
335 t))) 332 t)))
333
334 ;; Set flyspell-generic-check-word-p based on the major mode.
336 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) 335 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
337 (if mode-predicate 336 (if mode-predicate
338 (setq flyspell-generic-check-word-p mode-predicate))) 337 (setq flyspell-generic-check-word-p mode-predicate)))
339 338
340 ;; the welcome message 339 ;; the welcome message
341 (if flyspell-issue-welcome-flag 340 (if flyspell-issue-welcome-flag
342 (message 341 (let ((binding (where-is-internal 'flyspell-auto-correct-word
343 (if flyspell-auto-correct-binding 342 nil 'non-ascii)))
344 (format "Welcome to flyspell. Use %S or mouse-2 to correct words." 343 (message
345 (key-description flyspell-auto-correct-binding)) 344 (if binding
346 "Welcome to flyspell. Use mouse-2 to correct words."))) 345 (format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
346 (key-description binding))
347 "Welcome to flyspell. Use Mouse-2 to correct words."))))
347 ;; we have to kill the flyspell process when the buffer is deleted. 348 ;; we have to kill the flyspell process when the buffer is deleted.
348 ;; (thanks to Jeff Miller and Roland Rosenfeld who sent me this 349 ;; (thanks to Jeff Miller and Roland Rosenfeld who sent me this
349 ;; improvement). 350 ;; improvement).
@@ -423,8 +424,10 @@ COMMAND is the name of the command to be delayed."
423;*---------------------------------------------------------------------*/ 424;*---------------------------------------------------------------------*/
424(defun flyspell-mode-off () 425(defun flyspell-mode-off ()
425 "Turn flyspell mode off. Do not use this--use `flyspell-mode' instead." 426 "Turn flyspell mode off. Do not use this--use `flyspell-mode' instead."
426 ;; we stop the running ispell 427 ;; If we have an Ispell process for each buffer,
427 (ispell-kill-ispell t) 428 ;; kill the one for this buffer.
429 (if flyspell-multi-language-p
430 (ispell-kill-ispell t))
428 ;; we remove the hooks 431 ;; we remove the hooks
429 (if flyspell-command-hook 432 (if flyspell-command-hook
430 (progn 433 (progn
@@ -485,7 +488,8 @@ before the current command."
485 (not (bufferp flyspell-pre-buffer)) 488 (not (bufferp flyspell-pre-buffer))
486 (not (buffer-live-p flyspell-pre-buffer))) 489 (not (buffer-live-p flyspell-pre-buffer)))
487 nil) 490 nil)
488 ((or (= flyspell-pre-point (- (point) 1)) 491 ((or (and (= flyspell-pre-point (- (point) 1))
492 (eq (char-syntax (char-after flyspell-pre-point)) ?w))
489 (= flyspell-pre-point (point)) 493 (= flyspell-pre-point (point))
490 (= flyspell-pre-point (+ (point) 1))) 494 (= flyspell-pre-point (+ (point) 1)))
491 nil) 495 nil)
@@ -568,6 +572,10 @@ before the current command."
568 ;; put in verbose mode 572 ;; put in verbose mode
569 (process-send-string ispell-process 573 (process-send-string ispell-process
570 (concat "^" word "\n")) 574 (concat "^" word "\n"))
575 ;; we mark the ispell process so it can be killed
576 ;; when emacs is exited without query
577 (if (fboundp 'process-kill-without-query)
578 (process-kill-without-query ispell-process))
571 ;; wait until ispell has processed word 579 ;; wait until ispell has processed word
572 (while (progn 580 (while (progn
573 (accept-process-output ispell-process) 581 (accept-process-output ispell-process)
@@ -622,8 +630,7 @@ before the current command."
622 t))))) 630 t)))))
623 (if flyspell-highlight-flag 631 (if flyspell-highlight-flag
624 (flyspell-highlight-duplicate-region start end) 632 (flyspell-highlight-duplicate-region start end)
625 (message (format "misspelling duplicate `%s'" 633 (message (format "duplicate `%s'" word))))
626 word))))
627 (t 634 (t
628 ;; incorrect highlight the location 635 ;; incorrect highlight the location
629 (if flyspell-highlight-flag 636 (if flyspell-highlight-flag
@@ -769,13 +776,17 @@ Word syntax described by `ispell-dictionary-alist' (which see)."
769 "Flyspell text between BEG and END." 776 "Flyspell text between BEG and END."
770 (interactive "r") 777 (interactive "r")
771 (save-excursion 778 (save-excursion
779 (if (> beg end)
780 (let ((old beg))
781 (setq beg end)
782 (setq end old)))
772 (goto-char beg) 783 (goto-char beg)
773 (let ((count 0)) 784 (let ((count 0))
774 (while (< (point) end) 785 (while (< (point) end)
775 (if (= count 100) 786 (if (= count 100)
776 (progn 787 (progn
777 (message "Spell Checking...%d%%" 788 (message "Spell Checking...%d%%"
778 (* 100 (/ (float (point)) (- end beg)))) 789 (* 100 (/ (float (- (point) beg)) (- end beg))))
779 (setq count 0)) 790 (setq count 0))
780 (setq count (+ 1 count))) 791 (setq count (+ 1 count)))
781 (flyspell-word) 792 (flyspell-word)
@@ -834,9 +845,12 @@ Word syntax described by `ispell-dictionary-alist' (which see)."
834;* ------------------------------------------------------------- */ 845;* ------------------------------------------------------------- */
835;* Is there an highlight properties at position pos? */ 846;* Is there an highlight properties at position pos? */
836;*---------------------------------------------------------------------*/ 847;*---------------------------------------------------------------------*/
837(defun flyspell-properties-at-p (beg) 848(defun flyspell-properties-at-p (pos)
838 "Return the text property at position BEG." 849 "Return t if there is a text property at POS, not counting `local-map'.
839 (let ((prop (text-properties-at beg)) 850If variable `flyspell-highlight-properties' is set to nil,
851text with properties are not checked. This function is used to discover
852if the character at POS has any other property."
853 (let ((prop (text-properties-at pos))
840 (keep t)) 854 (keep t))
841 (while (and keep (consp prop)) 855 (while (and keep (consp prop))
842 (if (and (eq (car prop) 'local-map) (consp (cdr prop))) 856 (if (and (eq (car prop) 'local-map) (consp (cdr prop)))
@@ -867,7 +881,7 @@ for the overlay."
867(defun flyspell-highlight-incorrect-region (beg end) 881(defun flyspell-highlight-incorrect-region (beg end)
868 "Set up an overlay on a misspelled word, in the buffer from BEG to END." 882 "Set up an overlay on a misspelled word, in the buffer from BEG to END."
869 (run-hook-with-args 'flyspell-incorrect-hook beg end) 883 (run-hook-with-args 'flyspell-incorrect-hook beg end)
870 (if (or (not (flyspell-properties-at-p beg)) flyspell-highlight-properties) 884 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
871 (progn 885 (progn
872 ;; we cleanup current overlay at the same position 886 ;; we cleanup current overlay at the same position
873 (if (and (not flyspell-persistent-highlight) 887 (if (and (not flyspell-persistent-highlight)
@@ -888,7 +902,7 @@ for the overlay."
888;*---------------------------------------------------------------------*/ 902;*---------------------------------------------------------------------*/
889(defun flyspell-highlight-duplicate-region (beg end) 903(defun flyspell-highlight-duplicate-region (beg end)
890 "Set up an overlay on a duplicated word, in the buffer from BEG to END." 904 "Set up an overlay on a duplicated word, in the buffer from BEG to END."
891 (if (or (not (flyspell-properties-at-p beg)) flyspell-highlight-properties) 905 (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg)))
892 (progn 906 (progn
893 ;; we cleanup current overlay at the same position 907 ;; we cleanup current overlay at the same position
894 (if (and (not flyspell-persistent-highlight) 908 (if (and (not flyspell-persistent-highlight)
@@ -915,7 +929,10 @@ for the overlay."
915;* flyspell-auto-correct-word ... */ 929;* flyspell-auto-correct-word ... */
916;*---------------------------------------------------------------------*/ 930;*---------------------------------------------------------------------*/
917(defun flyspell-auto-correct-word (pos) 931(defun flyspell-auto-correct-word (pos)
918 "Auto-correct the word at position POS." 932 "Correct the word at POS.
933This command proposes various successive corrections for the word at POS.
934The variable `flyspell-auto-correct-binding' specifies the key to bind
935to this command."
919 (interactive "d") 936 (interactive "d")
920 ;; use the correct dictionary 937 ;; use the correct dictionary
921 (ispell-accept-buffer-local-defs) 938 (ispell-accept-buffer-local-defs)
@@ -1135,7 +1152,7 @@ The word checked is the word at the mouse position."
1135 (insert word)))))) 1152 (insert word))))))
1136 1153
1137;*---------------------------------------------------------------------*/ 1154;*---------------------------------------------------------------------*/
1138;* flyspell-emacs-popup */ 1155;* flyspell-emacs-popup ... */
1139;*---------------------------------------------------------------------*/ 1156;*---------------------------------------------------------------------*/
1140(defun flyspell-emacs-popup (event poss word) 1157(defun flyspell-emacs-popup (event poss word)
1141 "The Emacs popup menu." 1158 "The Emacs popup menu."
@@ -1178,7 +1195,7 @@ The word checked is the word at the mouse position."
1178 menu))))) 1195 menu)))))
1179 1196
1180;*---------------------------------------------------------------------*/ 1197;*---------------------------------------------------------------------*/
1181;* flyspell-xemacs-popup */ 1198;* flyspell-xemacs-popup ... */
1182;*---------------------------------------------------------------------*/ 1199;*---------------------------------------------------------------------*/
1183(defun flyspell-xemacs-popup (event poss word cursor-location start end) 1200(defun flyspell-xemacs-popup (event poss word cursor-location start end)
1184 "The xemacs popup menu." 1201 "The xemacs popup menu."