1 |
;;; flyspell.el --- on-the-fly spell checker |
;;; flyspell.el --- on-the-fly spell checker |
2 |
|
|
3 |
;; Copyright (C) 1998, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. |
;; Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr> |
;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr> |
6 |
;; Maintainer: FSF |
;; Maintainer: FSF |
56 |
:group 'processes) |
:group 'processes) |
57 |
|
|
58 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
59 |
|
;* Which emacs are we currently running */ |
60 |
|
;*---------------------------------------------------------------------*/ |
61 |
|
(defvar flyspell-emacs |
62 |
|
(cond |
63 |
|
((string-match "XEmacs" emacs-version) |
64 |
|
'xemacs) |
65 |
|
(t |
66 |
|
'emacs)) |
67 |
|
"The type of Emacs we are currently running.") |
68 |
|
|
69 |
|
(defvar flyspell-use-local-map |
70 |
|
(or (eq flyspell-emacs 'xemacs) |
71 |
|
(not (string< emacs-version "20")))) |
72 |
|
|
73 |
|
;*---------------------------------------------------------------------*/ |
74 |
;* User configuration ... */ |
;* User configuration ... */ |
75 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
76 |
(defcustom flyspell-highlight-flag t |
(defcustom flyspell-highlight-flag t |
124 |
delete-backward-char |
delete-backward-char |
125 |
backward-or-forward-delete-char |
backward-or-forward-delete-char |
126 |
delete-char |
delete-char |
127 |
scrollbar-vertical-drag) |
scrollbar-vertical-drag |
128 |
|
backward-delete-char-untabify) |
129 |
"The standard list of delayed commands for Flyspell. |
"The standard list of delayed commands for Flyspell. |
130 |
See `flyspell-delayed-commands'." |
See `flyspell-delayed-commands'." |
131 |
:group 'flyspell |
:group 'flyspell |
215 |
:type '(repeat (string))) |
:type '(repeat (string))) |
216 |
|
|
217 |
(defcustom flyspell-abbrev-p |
(defcustom flyspell-abbrev-p |
218 |
t |
nil |
219 |
"*If true, add correction to abbreviation table." |
"*If non-nil, add correction to abbreviation table." |
220 |
:group 'flyspell |
:group 'flyspell |
221 |
:version "21.1" |
:version "21.1" |
222 |
:type 'boolean) |
:type 'boolean) |
223 |
|
|
224 |
(defcustom flyspell-use-global-abbrev-table-p |
(defcustom flyspell-use-global-abbrev-table-p |
225 |
nil |
nil |
226 |
"*If true, prefer global abbrev table to local abbrev table." |
"*If non-nil, prefer global abbrev table to local abbrev table." |
227 |
:group 'flyspell |
:group 'flyspell |
228 |
:version "21.1" |
:version "21.1" |
229 |
:type 'boolean) |
:type 'boolean) |
240 |
If the region is smaller than this number of characters, |
If the region is smaller than this number of characters, |
241 |
`flyspell-region' checks the words sequentially using regular |
`flyspell-region' checks the words sequentially using regular |
242 |
flyspell methods. Else, if the region is large, a new Ispell process is |
flyspell methods. Else, if the region is large, a new Ispell process is |
243 |
spawned for speed." |
spawned for speed. |
244 |
|
|
245 |
|
If `flyspell-large-region' is nil, all regions are treated as small." |
246 |
:group 'flyspell |
:group 'flyspell |
247 |
:version "21.1" |
:version "21.1" |
248 |
:type 'number) |
:type '(choice number boolean)) |
249 |
|
|
250 |
(defcustom flyspell-insert-function (function insert) |
(defcustom flyspell-insert-function (function insert) |
251 |
"*Function for inserting word by flyspell upon correction." |
"*Function for inserting word by flyspell upon correction." |
262 |
:group 'flyspell |
:group 'flyspell |
263 |
:type '(choice string (const nil))) |
:type '(choice string (const nil))) |
264 |
|
|
265 |
|
(defcustom flyspell-use-meta-tab t |
266 |
|
"*Non-nil means that flyspell uses META-TAB to correct word." |
267 |
|
:group 'flyspell |
268 |
|
:type 'boolean) |
269 |
|
|
270 |
|
(defcustom flyspell-auto-correct-binding |
271 |
|
(cond |
272 |
|
((eq flyspell-emacs 'xemacs) |
273 |
|
[(control \;)]) |
274 |
|
(t |
275 |
|
[?\C-\;])) |
276 |
|
"The key binding for flyspell auto correction." |
277 |
|
:group 'flyspell) |
278 |
|
|
279 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
280 |
;* Mode specific options */ |
;* Mode specific options */ |
281 |
;* ------------------------------------------------------------- */ |
;* ------------------------------------------------------------- */ |
299 |
(put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
(put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
300 |
(defun mail-mode-flyspell-verify () |
(defun mail-mode-flyspell-verify () |
301 |
"This function is used for `flyspell-generic-check-word-p' in Mail mode." |
"This function is used for `flyspell-generic-check-word-p' in Mail mode." |
302 |
(let ((in-headers (save-excursion |
(let ((header-end (save-excursion |
303 |
;; When mail-header-separator is "", |
(goto-char (point-min)) |
304 |
;; it is likely to be found in both directions. |
(re-search-forward |
305 |
(not (re-search-backward (concat "^" (regexp-quote mail-header-separator) "$") nil t)))) |
(concat "^" |
306 |
(in-signature (save-excursion |
(regexp-quote mail-header-separator) |
307 |
(re-search-backward message-signature-separator nil t)))) |
"$") |
308 |
(cond (in-headers |
nil t) |
309 |
|
(point))) |
310 |
|
(signature-begin (save-excursion |
311 |
|
(goto-char (point-max)) |
312 |
|
(re-search-backward message-signature-separator |
313 |
|
nil t) |
314 |
|
(point)))) |
315 |
|
(cond ((< (point) header-end) |
316 |
(and (save-excursion (beginning-of-line) |
(and (save-excursion (beginning-of-line) |
317 |
(looking-at "^Subject:")) |
(looking-at "^Subject:")) |
318 |
(> (point) (match-end 0)))) |
(> (point) (match-end 0)))) |
319 |
(in-signature |
((> (point) signature-begin) |
320 |
nil) |
nil) |
321 |
(t |
(t |
322 |
(save-excursion |
(save-excursion |
390 |
"Turn on `flyspell-mode' for comments and strings." |
"Turn on `flyspell-mode' for comments and strings." |
391 |
(interactive) |
(interactive) |
392 |
(setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify) |
(setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify) |
393 |
(flyspell-mode 1)) |
(flyspell-mode 1) |
394 |
|
(run-hooks 'flyspell-prog-mode-hook)) |
395 |
|
|
396 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
397 |
;* Overlay compatibility */ |
;* Overlay compatibility */ |
406 |
(autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t) |
(autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t) |
407 |
|
|
408 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
|
;* Which emacs are we currently running */ |
|
|
;*---------------------------------------------------------------------*/ |
|
|
(defvar flyspell-emacs |
|
|
(cond |
|
|
((string-match "XEmacs" emacs-version) |
|
|
'xemacs) |
|
|
(t |
|
|
'emacs)) |
|
|
"The type of Emacs we are currently running.") |
|
|
|
|
|
(defvar flyspell-use-local-map |
|
|
(or (eq flyspell-emacs 'xemacs) |
|
|
(not (string< emacs-version "20")))) |
|
|
|
|
|
;*---------------------------------------------------------------------*/ |
|
409 |
;* The minor mode declaration. */ |
;* The minor mode declaration. */ |
410 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
411 |
(eval-when-compile (defvar flyspell-local-mouse-map)) |
(eval-when-compile (defvar flyspell-local-mouse-map)) |
416 |
|
|
417 |
(defvar flyspell-mouse-map |
(defvar flyspell-mouse-map |
418 |
(let ((map (make-sparse-keymap))) |
(let ((map (make-sparse-keymap))) |
419 |
|
(if flyspell-use-meta-tab |
420 |
|
(define-key map "\M-\t" #'flyspell-auto-correct-word)) |
421 |
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2]) |
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2]) |
422 |
#'flyspell-correct-word) |
#'flyspell-correct-word) |
423 |
(define-key map "\M-\t" #'flyspell-auto-correct-word) |
(define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word) |
424 |
|
(define-key map [(control \,)] 'flyspell-goto-next-error) |
425 |
|
(define-key map [(control \.)] 'flyspell-auto-correct-word) |
426 |
map)) |
map)) |
427 |
|
|
428 |
;;;###autoload |
;;;###autoload |
433 |
(setq minor-mode-map-alist |
(setq minor-mode-map-alist |
434 |
(cons (cons 'flyspell-mode flyspell-mode-map) |
(cons (cons 'flyspell-mode flyspell-mode-map) |
435 |
minor-mode-map-alist))) |
minor-mode-map-alist))) |
436 |
(define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word)) |
(if flyspell-use-meta-tab |
437 |
|
(define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word)) |
438 |
|
(cond |
439 |
|
((eq flyspell-emacs 'xemacs) |
440 |
|
(define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word) |
441 |
|
(define-key flyspell-mode-map [(control \,)] 'flyspell-goto-next-error) |
442 |
|
(define-key flyspell-mode-map [(control \.)] 'flyspell-auto-correct-word)) |
443 |
|
(flyspell-use-local-map |
444 |
|
(define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word) |
445 |
|
(define-key flyspell-mode-map [?\C-\,] 'flyspell-goto-next-error) |
446 |
|
(define-key flyspell-mode-map [?\C-\.] 'flyspell-auto-correct-word)))) |
447 |
|
|
448 |
|
|
449 |
;; the name of the overlay property that defines the keymap |
;; the name of the overlay property that defines the keymap |
450 |
(defvar flyspell-overlay-keymap-property-name 'keymap) |
(defvar flyspell-overlay-keymap-property-name 'keymap) |
496 |
Bindings: |
Bindings: |
497 |
\\[ispell-word]: correct words (using Ispell). |
\\[ispell-word]: correct words (using Ispell). |
498 |
\\[flyspell-auto-correct-word]: automatically correct word. |
\\[flyspell-auto-correct-word]: automatically correct word. |
499 |
\\[flyspell-correct-word] (or mouse-2): popup correct words. |
\\[flyspell-auto-correct-previous-word]: automatically correct the last misspelled word. |
500 |
|
\\[flyspell-correct-word] (or down-mouse-2): popup correct words. |
501 |
|
|
502 |
Hooks: |
Hooks: |
503 |
This runs `flyspell-mode-hook' after flyspell is entered. |
This runs `flyspell-mode-hook' after flyspell is entered. |
553 |
(and (consp ws) (window-minibuffer-p (car ws))))) |
(and (consp ws) (window-minibuffer-p (car ws))))) |
554 |
|
|
555 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
|
;* flyspell-version ... */ |
|
|
;*---------------------------------------------------------------------*/ |
|
|
;;;###autoload |
|
|
(defun flyspell-version () |
|
|
"The flyspell version" |
|
|
(interactive) |
|
|
"1.6h") |
|
|
|
|
|
;*---------------------------------------------------------------------*/ |
|
556 |
;* flyspell-accept-buffer-local-defs ... */ |
;* flyspell-accept-buffer-local-defs ... */ |
557 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
558 |
(defun flyspell-accept-buffer-local-defs () |
(defun flyspell-accept-buffer-local-defs () |
559 |
(ispell-accept-buffer-local-defs) |
;; strange problem. If buffer in current window has font-lock turned on, |
560 |
|
;; but SET-BUFFER was called to point to an invisible buffer, this ispell |
561 |
|
;; call will reset the buffer to the buffer in the current window. However, |
562 |
|
;; it only happens at startup (fix by Albert L. Ting). |
563 |
|
(let ((buf (current-buffer))) |
564 |
|
(ispell-accept-buffer-local-defs) |
565 |
|
(set-buffer buf)) |
566 |
(if (not (and (eq flyspell-dash-dictionary ispell-dictionary) |
(if (not (and (eq flyspell-dash-dictionary ispell-dictionary) |
567 |
(eq flyspell-dash-local-dictionary ispell-local-dictionary))) |
(eq flyspell-dash-local-dictionary ispell-local-dictionary))) |
568 |
;; the dictionary has changed |
;; The dictionary has changed |
569 |
(progn |
(progn |
570 |
(setq flyspell-dash-dictionary ispell-dictionary) |
(setq flyspell-dash-dictionary ispell-dictionary) |
571 |
(setq flyspell-dash-local-dictionary ispell-local-dictionary) |
(setq flyspell-dash-local-dictionary ispell-local-dictionary) |
604 |
(let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) |
(let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) |
605 |
(if mode-predicate |
(if mode-predicate |
606 |
(setq flyspell-generic-check-word-p mode-predicate))) |
(setq flyspell-generic-check-word-p mode-predicate))) |
607 |
|
;; work around the fact that the `local-map' text-property replaces the |
608 |
|
;; buffer's local map rather than shadowing it. |
609 |
|
(set (make-local-variable 'flyspell-mouse-map) |
610 |
|
(let ((map (copy-keymap flyspell-mouse-map))) |
611 |
|
(set-keymap-parent map (current-local-map)) |
612 |
|
(if (and (eq flyspell-emacs 'emacs) |
613 |
|
(not (string< emacs-version "20"))) |
614 |
|
(define-key map '[tool-bar] nil)) |
615 |
|
map)) |
616 |
|
(set (make-local-variable 'flyspell-mode-map) |
617 |
|
(let ((map (copy-keymap flyspell-mode-map))) |
618 |
|
(set-keymap-parent map (current-local-map)) |
619 |
|
(if (and (eq flyspell-emacs 'emacs) |
620 |
|
(not (string< emacs-version "20"))) |
621 |
|
(define-key map '[tool-bar] nil)) |
622 |
|
map)) |
623 |
;; the welcome message |
;; the welcome message |
624 |
(if (and flyspell-issue-message-flag |
(if (and flyspell-issue-message-flag |
625 |
flyspell-issue-welcome-flag |
flyspell-issue-welcome-flag |
678 |
(defvar flyspell-word-cache-start nil) |
(defvar flyspell-word-cache-start nil) |
679 |
(defvar flyspell-word-cache-end nil) |
(defvar flyspell-word-cache-end nil) |
680 |
(defvar flyspell-word-cache-word nil) |
(defvar flyspell-word-cache-word nil) |
681 |
|
(defvar flyspell-word-cache-result '_) |
682 |
(make-variable-buffer-local 'flyspell-word-cache-start) |
(make-variable-buffer-local 'flyspell-word-cache-start) |
683 |
(make-variable-buffer-local 'flyspell-word-cache-end) |
(make-variable-buffer-local 'flyspell-word-cache-end) |
684 |
(make-variable-buffer-local 'flyspell-word-cache-word) |
(make-variable-buffer-local 'flyspell-word-cache-word) |
685 |
|
(make-variable-buffer-local 'flyspell-word-cache-result) |
686 |
|
|
687 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
688 |
;* The flyspell pre-hook, store the current position. In the */ |
;* The flyspell pre-hook, store the current position. In the */ |
734 |
;* flyspell-check-pre-word-p ... */ |
;* flyspell-check-pre-word-p ... */ |
735 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
736 |
(defun flyspell-check-pre-word-p () |
(defun flyspell-check-pre-word-p () |
737 |
"Return non-nil if we should to check the word before point. |
"Return non-nil if we should check the word before point. |
738 |
More precisely, it applies to the word that was before point |
More precisely, it applies to the word that was before point |
739 |
before the current command." |
before the current command." |
740 |
(cond |
(cond |
791 |
The answer depends of several criteria. |
The answer depends of several criteria. |
792 |
Mostly we check word delimiters." |
Mostly we check word delimiters." |
793 |
(cond |
(cond |
794 |
((and (eq (char-after start) ?\n) (> stop start)) |
((and (memq (char-after start) '(?\n ? )) (> stop start)) |
795 |
t) |
t) |
796 |
((not (numberp flyspell-pre-point)) |
((not (numberp flyspell-pre-point)) |
797 |
t) |
t) |
980 |
;; when a word is not checked because of a delayed command |
;; when a word is not checked because of a delayed command |
981 |
;; we do not disable the ispell cache. |
;; we do not disable the ispell cache. |
982 |
(if (and (symbolp this-command) (get this-command 'flyspell-delayed)) |
(if (and (symbolp this-command) (get this-command 'flyspell-delayed)) |
983 |
(setq flyspell-word-cache-end -1)))) |
(progn |
984 |
|
(setq flyspell-word-cache-end -1) |
985 |
|
(setq flyspell-word-cache-result '_))))) |
986 |
(while (consp flyspell-changes) |
(while (consp flyspell-changes) |
987 |
(let ((start (car (car flyspell-changes))) |
(let ((start (car (car flyspell-changes))) |
988 |
(stop (cdr (car flyspell-changes)))) |
(stop (cdr (car flyspell-changes)))) |
1007 |
(message (format "mispelling `%s' %S" word replacements))))) |
(message (format "mispelling `%s' %S" word replacements))))) |
1008 |
|
|
1009 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1010 |
|
;* flyspell-word-search-backward ... */ |
1011 |
|
;*---------------------------------------------------------------------*/ |
1012 |
|
(defun flyspell-word-search-backward (word bound) |
1013 |
|
(save-excursion |
1014 |
|
(let ((r '()) |
1015 |
|
p) |
1016 |
|
(while (and (not r) (setq p (search-backward word bound t))) |
1017 |
|
(let ((lw (flyspell-get-word '()))) |
1018 |
|
(if (and (consp lw) (string-equal (car lw) word)) |
1019 |
|
(setq r p) |
1020 |
|
(goto-char p)))) |
1021 |
|
r))) |
1022 |
|
|
1023 |
|
;*---------------------------------------------------------------------*/ |
1024 |
|
;* flyspell-word-search-forward ... */ |
1025 |
|
;*---------------------------------------------------------------------*/ |
1026 |
|
(defun flyspell-word-search-forward (word bound) |
1027 |
|
(save-excursion |
1028 |
|
(let ((r '()) |
1029 |
|
p) |
1030 |
|
(while (and (not r) (setq p (search-forward word bound t))) |
1031 |
|
(let ((lw (flyspell-get-word '()))) |
1032 |
|
(if (and (consp lw) (string-equal (car lw) word)) |
1033 |
|
(setq r p) |
1034 |
|
(goto-char (1+ p))))) |
1035 |
|
r))) |
1036 |
|
|
1037 |
|
;*---------------------------------------------------------------------*/ |
1038 |
;* flyspell-word ... */ |
;* flyspell-word ... */ |
1039 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1040 |
(defun flyspell-word (&optional following) |
(defun flyspell-word (&optional following) |
1049 |
(if (or (eq flyspell-word nil) |
(if (or (eq flyspell-word nil) |
1050 |
(and (fboundp flyspell-generic-check-word-p) |
(and (fboundp flyspell-generic-check-word-p) |
1051 |
(not (funcall flyspell-generic-check-word-p)))) |
(not (funcall flyspell-generic-check-word-p)))) |
1052 |
'() |
t |
1053 |
(progn |
(progn |
1054 |
;; destructure return flyspell-word info list. |
;; destructure return flyspell-word info list. |
1055 |
(setq start (car (cdr flyspell-word)) |
(setq start (car (cdr flyspell-word)) |
1058 |
;; before checking in the directory, we check for doublons. |
;; before checking in the directory, we check for doublons. |
1059 |
(cond |
(cond |
1060 |
((and (or (not (eq ispell-parser 'tex)) |
((and (or (not (eq ispell-parser 'tex)) |
1061 |
(not (eq (char-after start) ?\\))) |
(and (> start (point-min)) |
1062 |
|
(not (eq (char-after (1- start)) ?})) |
1063 |
|
(not (eq (char-after (1- start)) ?\\)))) |
1064 |
flyspell-mark-duplications-flag |
flyspell-mark-duplications-flag |
1065 |
(save-excursion |
(save-excursion |
1066 |
(goto-char start) |
(goto-char (1- start)) |
1067 |
(word-search-backward word |
(let ((p (flyspell-word-search-backward |
1068 |
(- start |
word |
1069 |
(+ 1 (- end start))) |
(- start (1+ (- end start)))))) |
1070 |
t))) |
(and p (/= p (1- start)))))) |
1071 |
;; yes, this is a doublon |
;; yes, this is a doublon |
1072 |
(flyspell-highlight-incorrect-region start end 'doublon)) |
(flyspell-highlight-incorrect-region start end 'doublon) |
1073 |
|
nil) |
1074 |
((and (eq flyspell-word-cache-start start) |
((and (eq flyspell-word-cache-start start) |
1075 |
(eq flyspell-word-cache-end end) |
(eq flyspell-word-cache-end end) |
1076 |
(string-equal flyspell-word-cache-word word)) |
(string-equal flyspell-word-cache-word word)) |
1077 |
;; this word had been already checked, we skip |
;; this word had been already checked, we skip |
1078 |
nil) |
flyspell-word-cache-result) |
1079 |
((and (eq ispell-parser 'tex) |
((and (eq ispell-parser 'tex) |
1080 |
(flyspell-tex-command-p flyspell-word)) |
(flyspell-tex-command-p flyspell-word)) |
1081 |
;; this is a correct word (because a tex command) |
;; this is a correct word (because a tex command) |
1105 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1106 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1107 |
(setq poss (ispell-parse-output (car ispell-filter)))) |
(setq poss (ispell-parse-output (car ispell-filter)))) |
1108 |
(cond ((eq poss t) |
(let ((res (cond ((eq poss t) |
1109 |
;; correct |
;; correct |
1110 |
(flyspell-unhighlight-at start) |
(setq flyspell-word-cache-result t) |
1111 |
(if (> end start) |
(flyspell-unhighlight-at start) |
1112 |
(flyspell-unhighlight-at (- end 1))) |
(if (> end start) |
1113 |
t) |
(flyspell-unhighlight-at (- end 1))) |
1114 |
((and (stringp poss) flyspell-highlight-flag) |
t) |
1115 |
;; correct |
((and (stringp poss) flyspell-highlight-flag) |
1116 |
(flyspell-unhighlight-at start) |
;; correct |
1117 |
(if (> end start) |
(setq flyspell-word-cache-result t) |
1118 |
(flyspell-unhighlight-at (- end 1))) |
(flyspell-unhighlight-at start) |
1119 |
t) |
(if (> end start) |
1120 |
((null poss) |
(flyspell-unhighlight-at (- end 1))) |
1121 |
(flyspell-unhighlight-at start) |
t) |
1122 |
(if (> end start) |
((null poss) |
1123 |
(flyspell-unhighlight-at (- end 1)))) |
(setq flyspell-word-cache-result t) |
1124 |
((or (and (< flyspell-duplicate-distance 0) |
(flyspell-unhighlight-at start) |
1125 |
(or (save-excursion |
(if (> end start) |
1126 |
(goto-char start) |
(flyspell-unhighlight-at (- end 1))) |
1127 |
(word-search-backward word |
t) |
1128 |
(point-min) |
((or (and (< flyspell-duplicate-distance 0) |
1129 |
t)) |
(or (save-excursion |
1130 |
(save-excursion |
(goto-char start) |
1131 |
(goto-char end) |
(flyspell-word-search-backward |
1132 |
(word-search-forward word |
word |
1133 |
(point-max) |
(point-min))) |
1134 |
t)))) |
(save-excursion |
1135 |
(and (> flyspell-duplicate-distance 0) |
(goto-char end) |
1136 |
(or (save-excursion |
(flyspell-word-search-forward |
1137 |
(goto-char start) |
word |
1138 |
(word-search-backward |
(point-max))))) |
1139 |
word |
(and (> flyspell-duplicate-distance 0) |
1140 |
(- start |
(or (save-excursion |
1141 |
flyspell-duplicate-distance) |
(goto-char start) |
1142 |
t)) |
(flyspell-word-search-backward |
1143 |
(save-excursion |
word |
1144 |
(goto-char end) |
(- start |
1145 |
(word-search-forward |
flyspell-duplicate-distance))) |
1146 |
word |
(save-excursion |
1147 |
(+ end |
(goto-char end) |
1148 |
flyspell-duplicate-distance) |
(flyspell-word-search-forward |
1149 |
t))))) |
word |
1150 |
(if flyspell-highlight-flag |
(+ end |
1151 |
(flyspell-highlight-duplicate-region start end poss) |
flyspell-duplicate-distance)))))) |
1152 |
(message (format "duplicate `%s'" word)))) |
(setq flyspell-word-cache-result nil) |
1153 |
(t |
(if flyspell-highlight-flag |
1154 |
;; incorrect highlight the location |
(flyspell-highlight-duplicate-region |
1155 |
(if flyspell-highlight-flag |
start end poss) |
1156 |
(flyspell-highlight-incorrect-region start end poss) |
(message (format "duplicate `%s'" word))) |
1157 |
(flyspell-notify-misspell start end word poss)))) |
nil) |
1158 |
;; return to original location |
(t |
1159 |
(goto-char cursor-location) |
(setq flyspell-word-cache-result nil) |
1160 |
(if ispell-quit (setq ispell-quit nil))))))))) |
;; incorrect highlight the location |
1161 |
|
(if flyspell-highlight-flag |
1162 |
|
(flyspell-highlight-incorrect-region |
1163 |
|
start end poss) |
1164 |
|
(flyspell-notify-misspell start end word poss)) |
1165 |
|
nil)))) |
1166 |
|
;; return to original location |
1167 |
|
(goto-char cursor-location) |
1168 |
|
(if ispell-quit (setq ispell-quit nil)) |
1169 |
|
res)))))))) |
1170 |
|
|
1171 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1172 |
;* flyspell-tex-math-initialized ... */ |
;* flyspell-tex-math-initialized ... */ |
1273 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1274 |
;* flyspell-get-word ... */ |
;* flyspell-get-word ... */ |
1275 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1276 |
(defun flyspell-get-word (following) |
(defun flyspell-get-word (following &optional extra-otherchars) |
1277 |
"Return the word for spell-checking according to Ispell syntax. |
"Return the word for spell-checking according to Ispell syntax. |
1278 |
If argument FOLLOWING is non-nil or if `ispell-following-word' |
If optional argument FOLLOWING is non-nil or if `flyspell-following-word' |
1279 |
is non-nil when called interactively, then the following word |
is non-nil when called interactively, then the following word |
1280 |
\(rather than preceding\) is checked when the cursor is not over a word. |
\(rather than preceding\) is checked when the cursor is not over a word. |
1281 |
Optional second argument contains other chars that can be included in word |
Optional second argument contains otherchars that can be included in word |
1282 |
many times. |
many times. |
1283 |
|
|
1284 |
Word syntax described by `ispell-dictionary-alist' (which see)." |
Word syntax described by `flyspell-dictionary-alist' (which see)." |
1285 |
(let* ((flyspell-casechars (flyspell-get-casechars)) |
(let* ((flyspell-casechars (flyspell-get-casechars)) |
1286 |
(flyspell-not-casechars (flyspell-get-not-casechars)) |
(flyspell-not-casechars (flyspell-get-not-casechars)) |
1287 |
(ispell-otherchars (ispell-get-otherchars)) |
(ispell-otherchars (ispell-get-otherchars)) |
1288 |
(ispell-many-otherchars-p (ispell-get-many-otherchars-p)) |
(ispell-many-otherchars-p (ispell-get-many-otherchars-p)) |
1289 |
(word-regexp (if (string< "" ispell-otherchars) |
(word-regexp (concat flyspell-casechars |
1290 |
(concat flyspell-casechars |
"+\\(" |
1291 |
"+\\(" |
(if (not (string= "" ispell-otherchars)) |
1292 |
ispell-otherchars |
(concat ispell-otherchars "?")) |
1293 |
"?" |
(if extra-otherchars |
1294 |
flyspell-casechars |
(concat extra-otherchars "?")) |
1295 |
"+\\)" |
flyspell-casechars |
1296 |
(if ispell-many-otherchars-p |
"+\\)" |
1297 |
"*" "?")) |
(if (or ispell-many-otherchars-p |
1298 |
(concat flyspell-casechars "+"))) |
extra-otherchars) |
1299 |
did-it-once |
"*" "?"))) |
1300 |
|
did-it-once prevpt |
1301 |
start end word) |
start end word) |
1302 |
;; find the word |
;; find the word |
1303 |
(if (not (looking-at flyspell-casechars)) |
(if (not (looking-at flyspell-casechars)) |
1306 |
(re-search-backward flyspell-casechars (point-min) t))) |
(re-search-backward flyspell-casechars (point-min) t))) |
1307 |
;; move to front of word |
;; move to front of word |
1308 |
(re-search-backward flyspell-not-casechars (point-min) 'start) |
(re-search-backward flyspell-not-casechars (point-min) 'start) |
1309 |
(let ((pos nil)) |
(while (and (or (and (not (string= "" ispell-otherchars)) |
1310 |
(if (string< "" ispell-otherchars) |
(looking-at ispell-otherchars)) |
1311 |
(while (and (looking-at ispell-otherchars) |
(and extra-otherchars (looking-at extra-otherchars))) |
1312 |
(not (bobp)) |
(not (bobp)) |
1313 |
(or (not did-it-once) |
(or (not did-it-once) |
1314 |
ispell-many-otherchars-p) |
ispell-many-otherchars-p) |
1315 |
(not (eq pos (point)))) |
(not (eq prevpt (point)))) |
1316 |
(setq pos (point)) |
(if (and extra-otherchars (looking-at extra-otherchars)) |
1317 |
(setq did-it-once t) |
(progn |
1318 |
(backward-char 1) |
(backward-char 1) |
1319 |
(if (looking-at flyspell-casechars) |
(if (looking-at flyspell-casechars) |
1320 |
(re-search-backward flyspell-not-casechars (point-min) 'move) |
(re-search-backward flyspell-not-casechars (point-min) 'move))) |
1321 |
(backward-char -1))))) |
(setq did-it-once t |
1322 |
|
prevpt (point)) |
1323 |
|
(backward-char 1) |
1324 |
|
(if (looking-at flyspell-casechars) |
1325 |
|
(re-search-backward flyspell-not-casechars (point-min) 'move) |
1326 |
|
(backward-char -1)))) |
1327 |
;; Now mark the word and save to string. |
;; Now mark the word and save to string. |
1328 |
(if (eq (re-search-forward word-regexp (point-max) t) nil) |
(if (not (re-search-forward word-regexp (point-max) t)) |
1329 |
nil |
nil |
1330 |
(progn |
(progn |
1331 |
(setq start (match-beginning 0) |
(setq start (match-beginning 0) |
1384 |
(set-buffer buffer) |
(set-buffer buffer) |
1385 |
(goto-char (point-min)) |
(goto-char (point-min)) |
1386 |
(let ((size (- flyspell-large-region-end flyspell-large-region-beg)) |
(let ((size (- flyspell-large-region-end flyspell-large-region-beg)) |
1387 |
(start flyspell-large-region-beg)) |
(start flyspell-large-region-beg) |
1388 |
|
(pword "") |
1389 |
|
(pcount 1)) |
1390 |
;; now we are done with ispell, we have to find the word in |
;; now we are done with ispell, we have to find the word in |
1391 |
;; the initial buffer |
;; the initial buffer |
1392 |
(while (< (point) (- (point-max) 1)) |
(while (< (point) (- (point-max) 1)) |
1393 |
;; we have to fetch the incorrect word |
;; we have to fetch the incorrect word |
1394 |
(if (re-search-forward "\\([^\n]+\\)\n" (point-max) t) |
(if (re-search-forward "\\([^\n]+\\)\n" (point-max) t) |
1395 |
(let ((word (match-string 1))) |
(let ((word (match-string 1))) |
1396 |
|
(if (string= word pword) |
1397 |
|
(setq pcount (1+ pcount)) |
1398 |
|
(progn |
1399 |
|
(setq pword word) |
1400 |
|
(setq pcount 1))) |
1401 |
(goto-char (match-end 0)) |
(goto-char (match-end 0)) |
|
(set-buffer flyspell-large-region-buffer) |
|
|
(goto-char flyspell-large-region-beg) |
|
1402 |
(if flyspell-issue-message-flag |
(if flyspell-issue-message-flag |
1403 |
(message "Spell Checking...%d%% [%s]" |
(message "Spell Checking...%d%% [%s]" |
1404 |
(* 100 (/ (float (- (point) start)) size)) |
(* 100 (/ (float (point)) (point-max))) |
1405 |
word)) |
word)) |
1406 |
(if (search-forward word flyspell-large-region-end t) |
(set-buffer flyspell-large-region-buffer) |
1407 |
|
(goto-char flyspell-large-region-beg) |
1408 |
|
(let ((keep t) |
1409 |
|
(n 0)) |
1410 |
|
(while (and (or (< n pcount) keep) |
1411 |
|
(search-forward word flyspell-large-region-end t)) |
1412 |
(progn |
(progn |
|
(setq flyspell-large-region-beg (point)) |
|
1413 |
(goto-char (- (point) 1)) |
(goto-char (- (point) 1)) |
1414 |
(flyspell-word))) |
(setq n (1+ n)) |
1415 |
|
(setq keep (flyspell-word)))) |
1416 |
|
(if (= n pcount) |
1417 |
|
(setq flyspell-large-region-beg (point)))) |
1418 |
(set-buffer buffer)) |
(set-buffer buffer)) |
1419 |
(goto-char (point-max))))) |
(goto-char (point-max))))) |
1420 |
;; we are done |
;; we are done |
1486 |
(let ((old beg)) |
(let ((old beg)) |
1487 |
(setq beg end) |
(setq beg end) |
1488 |
(setq end old))) |
(setq end old))) |
1489 |
(if (> (- end beg) flyspell-large-region) |
(if (and flyspell-large-region (> (- end beg) flyspell-large-region)) |
1490 |
(flyspell-large-region beg end) |
(flyspell-large-region beg end) |
1491 |
(flyspell-small-region beg end))))) |
(flyspell-small-region beg end))))) |
1492 |
|
|
1633 |
(if (or flyspell-highlight-properties |
(if (or flyspell-highlight-properties |
1634 |
(not (flyspell-properties-at-p beg))) |
(not (flyspell-properties-at-p beg))) |
1635 |
(progn |
(progn |
1636 |
|
;; we cleanup all the overlay that are in the region, not |
1637 |
|
;; beginning at the word start position |
1638 |
|
(if (< (1+ beg) end) |
1639 |
|
(let ((os (overlays-in (1+ beg) end))) |
1640 |
|
(while (consp os) |
1641 |
|
(if (flyspell-overlay-p (car os)) |
1642 |
|
(delete-overlay (car os))) |
1643 |
|
(setq os (cdr os))))) |
1644 |
;; we cleanup current overlay at the same position |
;; we cleanup current overlay at the same position |
1645 |
(if (and (not flyspell-persistent-highlight) |
(if (and (not flyspell-persistent-highlight) |
1646 |
(overlayp flyspell-overlay)) |
(overlayp flyspell-overlay)) |
1647 |
(delete-overlay flyspell-overlay) |
(delete-overlay flyspell-overlay) |
1648 |
(let ((overlays (overlays-at beg))) |
(let ((os (overlays-at beg))) |
1649 |
(while (consp overlays) |
(while (consp os) |
1650 |
(if (flyspell-overlay-p (car overlays)) |
(if (flyspell-overlay-p (car os)) |
1651 |
(delete-overlay (car overlays))) |
(delete-overlay (car os))) |
1652 |
(setq overlays (cdr overlays))))) |
(setq os (cdr os))))) |
1653 |
;; now we can use a new overlay |
;; now we can use a new overlay |
1654 |
(setq flyspell-overlay |
(setq flyspell-overlay |
1655 |
(make-flyspell-overlay |
(make-flyspell-overlay |
1801 |
(flyspell-ajust-cursor-point pos (point) old-max) |
(flyspell-ajust-cursor-point pos (point) old-max) |
1802 |
(setq flyspell-auto-correct-pos (point))) |
(setq flyspell-auto-correct-pos (point))) |
1803 |
;; fetch the word to be checked |
;; fetch the word to be checked |
1804 |
(let ((word (flyspell-get-word nil)) |
(let ((word (flyspell-get-word nil))) |
1805 |
start end poss) |
(if (consp word) |
1806 |
;; destructure return word info list. |
(let ((start (car (cdr word))) |
1807 |
(setq start (car (cdr word)) |
(end (car (cdr (cdr word)))) |
1808 |
end (car (cdr (cdr word))) |
(word (car word)) |
1809 |
word (car word)) |
poss) |
1810 |
(setq flyspell-auto-correct-word word) |
(setq flyspell-auto-correct-word word) |
1811 |
;; now check spelling of word. |
;; now check spelling of word. |
1812 |
(process-send-string ispell-process "%\n") ;put in verbose mode |
(process-send-string ispell-process "%\n") ;put in verbose mode |
1813 |
(process-send-string ispell-process (concat "^" word "\n")) |
(process-send-string ispell-process (concat "^" word "\n")) |
1814 |
;; wait until ispell has processed word |
;; wait until ispell has processed word |
1815 |
(while (progn |
(while (progn |
1816 |
(accept-process-output ispell-process) |
(accept-process-output ispell-process) |
1817 |
(not (string= "" (car ispell-filter))))) |
(not (string= "" (car ispell-filter))))) |
1818 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1819 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1820 |
(setq poss (ispell-parse-output (car ispell-filter)))) |
(setq poss (ispell-parse-output (car ispell-filter)))) |
1821 |
(cond ((or (eq poss t) (stringp poss)) |
(cond |
1822 |
;; don't correct word |
((or (eq poss t) (stringp poss)) |
1823 |
t) |
;; don't correct word |
1824 |
((null poss) |
t) |
1825 |
;; ispell error |
((null poss) |
1826 |
(error "Ispell: error in Ispell process")) |
;; ispell error |
1827 |
(t |
(error "Ispell: error in Ispell process")) |
1828 |
;; the word is incorrect, we have to propose a replacement |
(t |
1829 |
(let ((replacements (if flyspell-sort-corrections |
;; the word is incorrect, we have to propose a replacement |
1830 |
(sort (car (cdr (cdr poss))) 'string<) |
(let ((replacements (if flyspell-sort-corrections |
1831 |
(car (cdr (cdr poss)))))) |
(sort (car (cdr (cdr poss))) 'string<) |
1832 |
(setq flyspell-auto-correct-region nil) |
(car (cdr (cdr poss)))))) |
1833 |
(if (consp replacements) |
(setq flyspell-auto-correct-region nil) |
1834 |
(progn |
(if (consp replacements) |
1835 |
(let ((replace (car replacements))) |
(progn |
1836 |
(let ((new-word replace)) |
(let ((replace (car replacements))) |
1837 |
(if (not (equal new-word (car poss))) |
(let ((new-word replace)) |
1838 |
(progn |
(if (not (equal new-word (car poss))) |
1839 |
;; the save the current replacements |
(progn |
1840 |
(setq flyspell-auto-correct-region |
;; the save the current replacements |
1841 |
(cons start (length new-word))) |
(setq flyspell-auto-correct-region |
1842 |
(let ((l replacements)) |
(cons start (length new-word))) |
1843 |
(while (consp (cdr l)) |
(let ((l replacements)) |
1844 |
(setq l (cdr l))) |
(while (consp (cdr l)) |
1845 |
(rplacd l (cons (car poss) replacements))) |
(setq l (cdr l))) |
1846 |
(setq flyspell-auto-correct-ring |
(rplacd l (cons (car poss) replacements))) |
1847 |
replacements) |
(setq flyspell-auto-correct-ring |
1848 |
(flyspell-unhighlight-at start) |
replacements) |
1849 |
(delete-region start end) |
(flyspell-unhighlight-at start) |
1850 |
(funcall flyspell-insert-function new-word) |
(delete-region start end) |
1851 |
(if flyspell-abbrev-p |
(funcall flyspell-insert-function new-word) |
1852 |
(if (flyspell-already-abbrevp |
(if flyspell-abbrev-p |
1853 |
(flyspell-abbrev-table) word) |
(if (flyspell-already-abbrevp |
1854 |
(flyspell-change-abbrev |
(flyspell-abbrev-table) word) |
1855 |
(flyspell-abbrev-table) |
(flyspell-change-abbrev |
1856 |
word |
(flyspell-abbrev-table) |
1857 |
new-word) |
word |
1858 |
(flyspell-define-abbrev word new-word))) |
new-word) |
1859 |
(flyspell-word) |
(flyspell-define-abbrev word |
1860 |
(flyspell-display-next-corrections |
new-word))) |
1861 |
(cons new-word flyspell-auto-correct-ring)) |
(flyspell-word) |
1862 |
(flyspell-ajust-cursor-point pos |
(flyspell-display-next-corrections |
1863 |
(point) |
(cons new-word flyspell-auto-correct-ring)) |
1864 |
old-max)))))))))) |
(flyspell-ajust-cursor-point pos |
1865 |
(setq flyspell-auto-correct-pos (point)) |
(point) |
1866 |
(ispell-pdict-save t))))) |
old-max)))))))))) |
1867 |
|
(setq flyspell-auto-correct-pos (point)) |
1868 |
|
(ispell-pdict-save t))))))) |
1869 |
|
|
1870 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1871 |
;* flyspell-auto-correct-previous-pos ... */ |
;* flyspell-auto-correct-previous-pos ... */ |
1878 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1879 |
(defun flyspell-auto-correct-previous-hook () |
(defun flyspell-auto-correct-previous-hook () |
1880 |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
1881 |
Sets flyspell-auto-correct-previous-pos to nil" |
Sets `flyspell-auto-correct-previous-pos' to nil" |
1882 |
(interactive) |
(interactive) |
1883 |
(remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t) |
(remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t) |
1884 |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
1885 |
(setq flyspell-auto-correct-previous-pos nil))) |
(setq flyspell-auto-correct-previous-pos nil))) |
1887 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1888 |
;* flyspell-auto-correct-previous-word ... */ |
;* flyspell-auto-correct-previous-word ... */ |
1889 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1890 |
(defun flyspell-auto-correct-previous-word (position) |
(defun flyspell-auto-correct-previous-word (position) |
1891 |
"*Auto correct the first mispelled word that occurs before point." |
"*Auto correct the first mispelled word that occurs before point. |
1892 |
|
But don't look beyond what's visible on the screen." |
1893 |
(interactive "d") |
(interactive "d") |
1894 |
|
|
1895 |
(add-hook 'pre-command-hook |
(let (top bot) |
1896 |
(function flyspell-auto-correct-previous-hook) t t) |
(save-excursion |
1897 |
|
(move-to-window-line 0) |
1898 |
|
(setq top (point)) |
1899 |
|
(move-to-window-line -1) |
1900 |
|
(setq bot (point))) |
1901 |
|
(save-excursion |
1902 |
|
(save-restriction |
1903 |
|
(narrow-to-region top bot) |
1904 |
|
(re-search-forward "\\s \\|\\'" nil t) |
1905 |
|
(overlay-recenter (point)) |
1906 |
|
|
1907 |
|
(add-hook 'pre-command-hook |
1908 |
|
(function flyspell-auto-correct-previous-hook) t t) |
1909 |
|
|
1910 |
|
(unless flyspell-auto-correct-previous-pos |
1911 |
|
;; only reset if a new overlay exists |
1912 |
|
(setq flyspell-auto-correct-previous-pos nil) |
1913 |
|
|
1914 |
|
(let ((overlay-list (overlays-in (point-min) position)) |
1915 |
|
(new-overlay 'dummy-value)) |
1916 |
|
|
1917 |
|
;; search for previous (new) flyspell overlay |
1918 |
|
(while (and new-overlay |
1919 |
|
(or (not (flyspell-overlay-p new-overlay)) |
1920 |
|
;; check if its face has changed |
1921 |
|
(not (eq (get-char-property |
1922 |
|
(overlay-start new-overlay) 'face) |
1923 |
|
'flyspell-incorrect-face)))) |
1924 |
|
(setq new-overlay (car-safe overlay-list)) |
1925 |
|
(setq overlay-list (cdr-safe overlay-list))) |
1926 |
|
|
1927 |
|
;; if nothing new exits new-overlay should be nil |
1928 |
|
(if new-overlay ;; the length of the word may change so go to the start |
1929 |
|
(setq flyspell-auto-correct-previous-pos |
1930 |
|
(overlay-start new-overlay))))) |
1931 |
|
|
1932 |
(save-excursion |
(when flyspell-auto-correct-previous-pos |
1933 |
(unless flyspell-auto-correct-previous-pos |
(save-excursion |
1934 |
;; only reset if a new overlay exists |
(goto-char flyspell-auto-correct-previous-pos) |
1935 |
(setq flyspell-auto-correct-previous-pos nil) |
(let ((ispell-following-word t)) ;; point is at start |
1936 |
|
(if (numberp flyspell-auto-correct-previous-pos) |
1937 |
(let ((overlay-list (overlays-in (point-min) position)) |
(goto-char flyspell-auto-correct-previous-pos)) |
1938 |
(new-overlay 'dummy-value)) |
(flyspell-auto-correct-word)) |
1939 |
|
;; the point may have moved so reset this |
1940 |
;; search for previous (new) flyspell overlay |
(setq flyspell-auto-correct-previous-pos (point)))))))) |
|
(while (and new-overlay |
|
|
(or (not (flyspell-overlay-p new-overlay)) |
|
|
;; check if its face has changed |
|
|
(not (eq (get-char-property |
|
|
(overlay-start new-overlay) 'face) |
|
|
'flyspell-incorrect-face)))) |
|
|
(setq new-overlay (car-safe overlay-list)) |
|
|
(setq overlay-list (cdr-safe overlay-list))) |
|
|
|
|
|
;; if nothing new exits new-overlay should be nil |
|
|
(if new-overlay;; the length of the word may change so go to the start |
|
|
(setq flyspell-auto-correct-previous-pos |
|
|
(overlay-start new-overlay))))) |
|
|
|
|
|
(when flyspell-auto-correct-previous-pos |
|
|
(save-excursion |
|
|
(goto-char flyspell-auto-correct-previous-pos) |
|
|
(let ((ispell-following-word t));; point is at start |
|
|
(if (numberp flyspell-auto-correct-previous-pos) |
|
|
(goto-char flyspell-auto-correct-previous-pos)) |
|
|
(flyspell-auto-correct-word)) |
|
|
;; the point may have moved so reset this |
|
|
(setq flyspell-auto-correct-previous-pos (point)))))) |
|
1941 |
|
|
1942 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
1943 |
;* flyspell-correct-word ... */ |
;* flyspell-correct-word ... */ |
1952 |
(let ((save (point))) |
(let ((save (point))) |
1953 |
(mouse-set-point event) |
(mouse-set-point event) |
1954 |
(let ((cursor-location (point)) |
(let ((cursor-location (point)) |
1955 |
(word (flyspell-get-word nil)) |
(word (flyspell-get-word nil))) |
1956 |
start end poss replace) |
(if (consp word) |
1957 |
;; destructure return word info list. |
(let ((start (car (cdr word))) |
1958 |
(setq start (car (cdr word)) |
(end (car (cdr (cdr word)))) |
1959 |
end (car (cdr (cdr word))) |
(word (car word)) |
1960 |
word (car word)) |
poss replace) |
1961 |
;; now check spelling of word. |
;; now check spelling of word. |
1962 |
(process-send-string ispell-process "%\n") ;put in verbose mode |
(process-send-string ispell-process "%\n") ;put in verbose mode |
1963 |
(process-send-string ispell-process (concat "^" word "\n")) |
(process-send-string ispell-process (concat "^" word "\n")) |
1964 |
;; wait until ispell has processed word |
;; wait until ispell has processed word |
1965 |
(while (progn |
(while (progn |
1966 |
(accept-process-output ispell-process) |
(accept-process-output ispell-process) |
1967 |
(not (string= "" (car ispell-filter))))) |
(not (string= "" (car ispell-filter))))) |
1968 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1969 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1970 |
(setq poss (ispell-parse-output (car ispell-filter)))) |
(setq poss (ispell-parse-output (car ispell-filter)))) |
1971 |
(cond ((or (eq poss t) (stringp poss)) |
(cond |
1972 |
;; don't correct word |
((or (eq poss t) (stringp poss)) |
1973 |
t) |
;; don't correct word |
1974 |
((null poss) |
t) |
1975 |
;; ispell error |
((null poss) |
1976 |
(error "Ispell: error in Ispell process")) |
;; ispell error |
1977 |
((string-match "GNU" (emacs-version)) |
(error "Ispell: error in Ispell process")) |
1978 |
;; the word is incorrect, we have to propose a replacement |
((string-match "GNU" (emacs-version)) |
1979 |
(setq replace (flyspell-emacs-popup event poss word)) |
;; the word is incorrect, we have to propose a replacement |
1980 |
(cond ((eq replace 'ignore) |
(setq replace (flyspell-emacs-popup event poss word)) |
1981 |
(goto-char save) |
(cond ((eq replace 'ignore) |
1982 |
nil) |
(goto-char save) |
1983 |
((eq replace 'save) |
nil) |
1984 |
(goto-char save) |
((eq replace 'save) |
1985 |
(process-send-string ispell-process (concat "*" word "\n")) |
(goto-char save) |
1986 |
(flyspell-unhighlight-at cursor-location) |
(process-send-string ispell-process |
1987 |
(setq ispell-pdict-modified-p '(t))) |
(concat "*" word "\n")) |
1988 |
((or (eq replace 'buffer) (eq replace 'session)) |
(flyspell-unhighlight-at cursor-location) |
1989 |
(process-send-string ispell-process (concat "@" word "\n")) |
(setq ispell-pdict-modified-p '(t))) |
1990 |
(if (null ispell-pdict-modified-p) |
((or (eq replace 'buffer) (eq replace 'session)) |
1991 |
(setq ispell-pdict-modified-p |
(process-send-string ispell-process |
1992 |
(list ispell-pdict-modified-p))) |
(concat "@" word "\n")) |
1993 |
(flyspell-unhighlight-at cursor-location) |
(if (null ispell-pdict-modified-p) |
1994 |
(goto-char save) |
(setq ispell-pdict-modified-p |
1995 |
(if (eq replace 'buffer) |
(list ispell-pdict-modified-p))) |
1996 |
(ispell-add-per-file-word-list word))) |
(flyspell-unhighlight-at cursor-location) |
1997 |
(replace |
(goto-char save) |
1998 |
(flyspell-unhighlight-at cursor-location) |
(if (eq replace 'buffer) |
1999 |
(let ((new-word (if (atom replace) |
(ispell-add-per-file-word-list word))) |
2000 |
replace |
(replace |
2001 |
(car replace))) |
(flyspell-unhighlight-at cursor-location) |
2002 |
(cursor-location (+ (- (length word) (- end start)) |
(let ((new-word (if (atom replace) |
2003 |
cursor-location))) |
replace |
2004 |
(if (not (equal new-word (car poss))) |
(car replace))) |
2005 |
(let ((old-max (point-max))) |
(cursor-location |
2006 |
(delete-region start end) |
(+ (- (length word) (- end start)) |
2007 |
(funcall flyspell-insert-function new-word) |
cursor-location))) |
2008 |
(if flyspell-abbrev-p |
(if (not (equal new-word (car poss))) |
2009 |
(flyspell-define-abbrev word new-word)) |
(let ((old-max (point-max))) |
2010 |
(flyspell-ajust-cursor-point save |
(delete-region start end) |
2011 |
cursor-location |
(funcall flyspell-insert-function new-word) |
2012 |
old-max))))) |
(if flyspell-abbrev-p |
2013 |
(t |
(flyspell-define-abbrev word new-word)) |
2014 |
(goto-char save) |
(flyspell-ajust-cursor-point save |
2015 |
nil))) |
cursor-location |
2016 |
((eq flyspell-emacs 'xemacs) |
old-max))))) |
2017 |
(flyspell-xemacs-popup |
(t |
2018 |
event poss word cursor-location start end save) |
(goto-char save) |
2019 |
(goto-char save))) |
nil))) |
2020 |
(ispell-pdict-save t)))) |
((eq flyspell-emacs 'xemacs) |
2021 |
|
(flyspell-xemacs-popup |
2022 |
|
event poss word cursor-location start end save) |
2023 |
|
(goto-char save))) |
2024 |
|
(ispell-pdict-save t)))))) |
2025 |
|
|
2026 |
;*---------------------------------------------------------------------*/ |
;*---------------------------------------------------------------------*/ |
2027 |
;* flyspell-xemacs-correct ... */ |
;* flyspell-xemacs-correct ... */ |