46 |
|
|
47 |
(require 'ispell) |
(require 'ispell) |
48 |
|
|
49 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
50 |
;* Group ... */ |
;;* Group ... */ |
51 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
52 |
(defgroup flyspell nil |
(defgroup flyspell nil |
53 |
"Spell checking on the fly." |
"Spell checking on the fly." |
54 |
:tag "FlySpell" |
:tag "FlySpell" |
56 |
:group 'ispell |
:group 'ispell |
57 |
:group 'processes) |
:group 'processes) |
58 |
|
|
59 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
60 |
;* Which emacs are we currently running */ |
;;* User configuration ... */ |
61 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
|
(defvar flyspell-emacs |
|
|
(cond |
|
|
((string-match "XEmacs" emacs-version) |
|
|
'xemacs) |
|
|
(t |
|
|
'emacs)) |
|
|
"The type of Emacs we are currently running.") |
|
|
|
|
|
;*---------------------------------------------------------------------*/ |
|
|
;* User configuration ... */ |
|
|
;*---------------------------------------------------------------------*/ |
|
62 |
(defcustom flyspell-highlight-flag t |
(defcustom flyspell-highlight-flag t |
63 |
"*How Flyspell should indicate misspelled words. |
"How Flyspell should indicate misspelled words. |
64 |
Non-nil means use highlight, nil means use minibuffer messages." |
Non-nil means use highlight, nil means use minibuffer messages." |
65 |
:group 'flyspell |
:group 'flyspell |
66 |
:type 'boolean) |
:type 'boolean) |
67 |
|
|
68 |
(defcustom flyspell-mark-duplications-flag t |
(defcustom flyspell-mark-duplications-flag t |
69 |
"*Non-nil means Flyspell reports a repeated word as an error. |
"Non-nil means Flyspell reports a repeated word as an error. |
70 |
Detection of repeated words is not implemented in |
Detection of repeated words is not implemented in |
71 |
\"large\" regions; see `flyspell-large-region'." |
\"large\" regions; see `flyspell-large-region'." |
72 |
:group 'flyspell |
:group 'flyspell |
73 |
:type 'boolean) |
:type 'boolean) |
74 |
|
|
75 |
(defcustom flyspell-sort-corrections nil |
(defcustom flyspell-sort-corrections nil |
76 |
"*Non-nil means, sort the corrections alphabetically before popping them." |
"Non-nil means, sort the corrections alphabetically before popping them." |
77 |
:group 'flyspell |
:group 'flyspell |
78 |
:version "21.1" |
:version "21.1" |
79 |
:type 'boolean) |
:type 'boolean) |
80 |
|
|
81 |
(defcustom flyspell-duplicate-distance -1 |
(defcustom flyspell-duplicate-distance -1 |
82 |
"*The maximum distance for finding duplicates of unrecognized words. |
"The maximum distance for finding duplicates of unrecognized words. |
83 |
This applies to the feature that when a word is not found in the dictionary, |
This applies to the feature that when a word is not found in the dictionary, |
84 |
if the same spelling occurs elsewhere in the buffer, |
if the same spelling occurs elsewhere in the buffer, |
85 |
Flyspell uses a different face (`flyspell-duplicate') to highlight it. |
Flyspell uses a different face (`flyspell-duplicate') to highlight it. |
91 |
:type 'number) |
:type 'number) |
92 |
|
|
93 |
(defcustom flyspell-delay 3 |
(defcustom flyspell-delay 3 |
94 |
"*The number of seconds to wait before checking, after a \"delayed\" command." |
"The number of seconds to wait before checking, after a \"delayed\" command." |
95 |
:group 'flyspell |
:group 'flyspell |
96 |
:type 'number) |
:type 'number) |
97 |
|
|
98 |
(defcustom flyspell-persistent-highlight t |
(defcustom flyspell-persistent-highlight t |
99 |
"*Non-nil means misspelled words remain highlighted until corrected. |
"Non-nil means misspelled words remain highlighted until corrected. |
100 |
If this variable is nil, only the most recently detected misspelled word |
If this variable is nil, only the most recently detected misspelled word |
101 |
is highlighted." |
is highlighted." |
102 |
:group 'flyspell |
:group 'flyspell |
103 |
:type 'boolean) |
:type 'boolean) |
104 |
|
|
105 |
(defcustom flyspell-highlight-properties t |
(defcustom flyspell-highlight-properties t |
106 |
"*Non-nil means highlight incorrect words even if a property exists for this word." |
"Non-nil means highlight incorrect words even if a property exists for this word." |
107 |
:group 'flyspell |
:group 'flyspell |
108 |
:type 'boolean) |
:type 'boolean) |
109 |
|
|
147 |
:type '(repeat (symbol))) |
:type '(repeat (symbol))) |
148 |
|
|
149 |
(defcustom flyspell-issue-welcome-flag t |
(defcustom flyspell-issue-welcome-flag t |
150 |
"*Non-nil means that Flyspell should display a welcome message when started." |
"Non-nil means that Flyspell should display a welcome message when started." |
151 |
:group 'flyspell |
:group 'flyspell |
152 |
:type 'boolean) |
:type 'boolean) |
153 |
|
|
154 |
(defcustom flyspell-issue-message-flag t |
(defcustom flyspell-issue-message-flag t |
155 |
"*Non-nil means that Flyspell emits messages when checking words." |
"Non-nil means that Flyspell emits messages when checking words." |
156 |
:group 'flyspell |
:group 'flyspell |
157 |
:type 'boolean) |
:type 'boolean) |
158 |
|
|
159 |
(defcustom flyspell-incorrect-hook nil |
(defcustom flyspell-incorrect-hook nil |
160 |
"*List of functions to be called when incorrect words are encountered. |
"List of functions to be called when incorrect words are encountered. |
161 |
Each function is given three arguments. The first two |
Each function is given three arguments. The first two |
162 |
arguments are the beginning and the end of the incorrect region. |
arguments are the beginning and the end of the incorrect region. |
163 |
The third is either the symbol `doublon' or the list |
The third is either the symbol `doublon' or the list |
189 |
:type 'string) |
:type 'string) |
190 |
|
|
191 |
(defcustom flyspell-check-tex-math-command nil |
(defcustom flyspell-check-tex-math-command nil |
192 |
"*Non nil means check even inside TeX math environment. |
"Non nil means check even inside TeX math environment. |
193 |
TeX math environments are discovered by the TEXMATHP that implemented |
TeX math environments are discovered by the TEXMATHP that implemented |
194 |
inside the texmathp.el Emacs package. That package may be found at: |
inside the texmathp.el Emacs package. That package may be found at: |
195 |
http://strw.leidenuniv.nl/~dominik/Tools" |
http://strw.leidenuniv.nl/~dominik/Tools" |
205 |
|
|
206 |
(defcustom flyspell-abbrev-p |
(defcustom flyspell-abbrev-p |
207 |
nil |
nil |
208 |
"*If non-nil, add correction to abbreviation table." |
"If non-nil, add correction to abbreviation table." |
209 |
:group 'flyspell |
:group 'flyspell |
210 |
:version "21.1" |
:version "21.1" |
211 |
:type 'boolean) |
:type 'boolean) |
212 |
|
|
213 |
(defcustom flyspell-use-global-abbrev-table-p |
(defcustom flyspell-use-global-abbrev-table-p |
214 |
nil |
nil |
215 |
"*If non-nil, prefer global abbrev table to local abbrev table." |
"If non-nil, prefer global abbrev table to local abbrev table." |
216 |
:group 'flyspell |
:group 'flyspell |
217 |
:version "21.1" |
:version "21.1" |
218 |
:type 'boolean) |
:type 'boolean) |
219 |
|
|
220 |
(defcustom flyspell-mode-line-string " Fly" |
(defcustom flyspell-mode-line-string " Fly" |
221 |
"*String displayed on the modeline when flyspell is active. |
"String displayed on the modeline when flyspell is active. |
222 |
Set this to nil if you don't want a modeline indicator." |
Set this to nil if you don't want a modeline indicator." |
223 |
:group 'flyspell |
:group 'flyspell |
224 |
:type '(choice string (const :tag "None" nil))) |
:type '(choice string (const :tag "None" nil))) |
225 |
|
|
226 |
(defcustom flyspell-large-region 1000 |
(defcustom flyspell-large-region 1000 |
227 |
"*The threshold that determines if a region is small. |
"The threshold that determines if a region is small. |
228 |
If the region is smaller than this number of characters, |
If the region is smaller than this number of characters, |
229 |
`flyspell-region' checks the words sequentially using regular |
`flyspell-region' checks the words sequentially using regular |
230 |
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 |
239 |
:type '(choice number (const :tag "All small" nil))) |
:type '(choice number (const :tag "All small" nil))) |
240 |
|
|
241 |
(defcustom flyspell-insert-function (function insert) |
(defcustom flyspell-insert-function (function insert) |
242 |
"*Function for inserting word by flyspell upon correction." |
"Function for inserting word by flyspell upon correction." |
243 |
:group 'flyspell |
:group 'flyspell |
244 |
:type 'function) |
:type 'function) |
245 |
|
|
254 |
:type '(choice string (const nil))) |
:type '(choice string (const nil))) |
255 |
|
|
256 |
(defcustom flyspell-use-meta-tab t |
(defcustom flyspell-use-meta-tab t |
257 |
"*Non-nil means that flyspell uses META-TAB to correct word." |
"Non-nil means that flyspell uses M-TAB to correct word." |
258 |
:group 'flyspell |
:group 'flyspell |
259 |
:type 'boolean) |
:type 'boolean) |
260 |
|
|
263 |
"The key binding for flyspell auto correction." |
"The key binding for flyspell auto correction." |
264 |
:group 'flyspell) |
:group 'flyspell) |
265 |
|
|
266 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
267 |
;* Mode specific options */ |
;;* Mode specific options */ |
268 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
269 |
;* Mode specific options enable users to disable flyspell on */ |
;;* Mode specific options enable users to disable flyspell on */ |
270 |
;* certain word depending of the emacs mode. For instance, when */ |
;;* certain word depending of the emacs mode. For instance, when */ |
271 |
;* using flyspell with mail-mode add the following expression */ |
;;* using flyspell with mail-mode add the following expression */ |
272 |
;* in your .emacs file: */ |
;;* in your .emacs file: */ |
273 |
;* (add-hook 'mail-mode */ |
;;* (add-hook 'mail-mode */ |
274 |
;* '(lambda () (setq flyspell-generic-check-word-p */ |
;;* '(lambda () (setq flyspell-generic-check-word-p */ |
275 |
;* 'mail-mode-flyspell-verify))) */ |
;;* 'mail-mode-flyspell-verify))) */ |
276 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
277 |
(defvar flyspell-generic-check-word-p nil |
(defvar flyspell-generic-check-word-p nil |
278 |
"Function providing per-mode customization over which words are flyspelled. |
"Function providing per-mode customization over which words are flyspelled. |
279 |
Returns t to continue checking, nil otherwise. |
Returns t to continue checking, nil otherwise. |
281 |
property of the major mode name.") |
property of the major mode name.") |
282 |
(make-variable-buffer-local 'flyspell-generic-check-word-p) |
(make-variable-buffer-local 'flyspell-generic-check-word-p) |
283 |
|
|
284 |
;*--- mail mode -------------------------------------------------------*/ |
;;*--- mail mode -------------------------------------------------------*/ |
285 |
(put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
(put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
286 |
(put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
(put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
287 |
(defun mail-mode-flyspell-verify () |
(defun mail-mode-flyspell-verify () |
310 |
(beginning-of-line) |
(beginning-of-line) |
311 |
(not (looking-at "[>}|]\\|To:"))))))) |
(not (looking-at "[>}|]\\|To:"))))))) |
312 |
|
|
313 |
;*--- texinfo mode ----------------------------------------------------*/ |
;;*--- texinfo mode ----------------------------------------------------*/ |
314 |
(put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify) |
(put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify) |
315 |
(defun texinfo-mode-flyspell-verify () |
(defun texinfo-mode-flyspell-verify () |
316 |
"This function is used for `flyspell-generic-check-word-p' in Texinfo mode." |
"This function is used for `flyspell-generic-check-word-p' in Texinfo mode." |
318 |
(forward-word -1) |
(forward-word -1) |
319 |
(not (looking-at "@")))) |
(not (looking-at "@")))) |
320 |
|
|
321 |
;*--- tex mode --------------------------------------------------------*/ |
;;*--- tex mode --------------------------------------------------------*/ |
322 |
(put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify) |
(put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify) |
323 |
(defun tex-mode-flyspell-verify () |
(defun tex-mode-flyspell-verify () |
324 |
"This function is used for `flyspell-generic-check-word-p' in LaTeX mode." |
"This function is used for `flyspell-generic-check-word-p' in LaTeX mode." |
333 |
(and (>= this (match-beginning 0)) |
(and (>= this (match-beginning 0)) |
334 |
(<= this (match-end 0)) ))))))) |
(<= this (match-end 0)) ))))))) |
335 |
|
|
336 |
;*--- sgml mode -------------------------------------------------------*/ |
;;*--- sgml mode -------------------------------------------------------*/ |
337 |
(put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) |
(put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) |
338 |
(put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) |
(put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) |
339 |
|
|
360 |
(and (re-search-backward "&[^;]*" s t) |
(and (re-search-backward "&[^;]*" s t) |
361 |
(= (match-end 0) this))))))))) |
(= (match-end 0) this))))))))) |
362 |
|
|
363 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
364 |
;* Programming mode */ |
;;* Programming mode */ |
365 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
366 |
(defvar flyspell-prog-text-faces |
(defvar flyspell-prog-text-faces |
367 |
'(font-lock-string-face font-lock-comment-face font-lock-doc-face) |
'(font-lock-string-face font-lock-comment-face font-lock-doc-face) |
368 |
"Faces corresponding to text in programming-mode buffers.") |
"Faces corresponding to text in programming-mode buffers.") |
380 |
(flyspell-mode 1) |
(flyspell-mode 1) |
381 |
(run-hooks 'flyspell-prog-mode-hook)) |
(run-hooks 'flyspell-prog-mode-hook)) |
382 |
|
|
383 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
384 |
;* Overlay compatibility */ |
;;* Overlay compatibility */ |
385 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
386 |
(autoload 'make-overlay "overlay" "Overlay compatibility kit." t) |
(autoload 'make-overlay "overlay" "Overlay compatibility kit." t) |
387 |
(autoload 'overlayp "overlay" "Overlay compatibility kit." t) |
(autoload 'overlayp "overlay" "Overlay compatibility kit." t) |
388 |
(autoload 'overlays-in "overlay" "Overlay compatibility kit." t) |
(autoload 'overlays-in "overlay" "Overlay compatibility kit." t) |
392 |
(autoload 'overlay-get "overlay" "Overlay compatibility kit." t) |
(autoload 'overlay-get "overlay" "Overlay compatibility kit." t) |
393 |
(autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t) |
(autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t) |
394 |
|
|
395 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
396 |
;* The minor mode declaration. */ |
;;* The minor mode declaration. */ |
397 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
398 |
(defvar flyspell-mouse-map |
(defvar flyspell-mouse-map |
399 |
(let ((map (make-sparse-keymap))) |
(let ((map (make-sparse-keymap))) |
400 |
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2]) |
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2]) |
421 |
(defvar flyspell-dash-local-dictionary nil) |
(defvar flyspell-dash-local-dictionary nil) |
422 |
(make-variable-buffer-local 'flyspell-dash-local-dictionary) |
(make-variable-buffer-local 'flyspell-dash-local-dictionary) |
423 |
|
|
424 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
425 |
;* Highlighting */ |
;;* Highlighting */ |
426 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
427 |
(defface flyspell-incorrect |
(defface flyspell-incorrect |
428 |
'((((class color)) (:foreground "OrangeRed" :bold t :underline t)) |
'((((class color)) (:foreground "OrangeRed" :bold t :underline t)) |
429 |
(t (:bold t))) |
(t (:bold t))) |
443 |
|
|
444 |
(defvar flyspell-overlay nil) |
(defvar flyspell-overlay nil) |
445 |
|
|
446 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
447 |
;* flyspell-mode ... */ |
;;* flyspell-mode ... */ |
448 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
449 |
;;;###autoload(defvar flyspell-mode nil) |
;;;###autoload(defvar flyspell-mode nil) |
450 |
;;;###autoload |
;;;###autoload |
451 |
(define-minor-mode flyspell-mode |
(define-minor-mode flyspell-mode |
483 |
(flyspell-mode-on) |
(flyspell-mode-on) |
484 |
(flyspell-mode-off))) |
(flyspell-mode-off))) |
485 |
|
|
486 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
487 |
;* flyspell-buffers ... */ |
;;* flyspell-buffers ... */ |
488 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
489 |
;* For remembering buffers running flyspell */ |
;;* For remembering buffers running flyspell */ |
490 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
491 |
(defvar flyspell-buffers nil) |
(defvar flyspell-buffers nil) |
492 |
|
|
493 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
494 |
;* flyspell-minibuffer-p ... */ |
;;* flyspell-minibuffer-p ... */ |
495 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
496 |
(defun flyspell-minibuffer-p (buffer) |
(defun flyspell-minibuffer-p (buffer) |
497 |
"Is BUFFER a minibuffer?" |
"Is BUFFER a minibuffer?" |
498 |
(let ((ws (get-buffer-window-list buffer t))) |
(let ((ws (get-buffer-window-list buffer t))) |
499 |
(and (consp ws) (window-minibuffer-p (car ws))))) |
(and (consp ws) (window-minibuffer-p (car ws))))) |
500 |
|
|
501 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
502 |
;* flyspell-accept-buffer-local-defs ... */ |
;;* flyspell-accept-buffer-local-defs ... */ |
503 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
504 |
(defun flyspell-accept-buffer-local-defs () |
(defun flyspell-accept-buffer-local-defs () |
505 |
;; strange problem. If buffer in current window has font-lock turned on, |
;; strange problem. If buffer in current window has font-lock turned on, |
506 |
;; but SET-BUFFER was called to point to an invisible buffer, this ispell |
;; but SET-BUFFER was called to point to an invisible buffer, this ispell |
507 |
;; call will reset the buffer to the buffer in the current window. However, |
;; call will reset the buffer to the buffer in the current window. However, |
508 |
;; it only happens at startup (fix by Albert L. Ting). |
;; it only happens at startup (fix by Albert L. Ting). |
509 |
(let ((buf (current-buffer))) |
(save-current-buffer |
510 |
(ispell-accept-buffer-local-defs) |
(ispell-accept-buffer-local-defs)) |
|
(set-buffer buf)) |
|
511 |
(if (not (and (eq flyspell-dash-dictionary ispell-dictionary) |
(if (not (and (eq flyspell-dash-dictionary ispell-dictionary) |
512 |
(eq flyspell-dash-local-dictionary ispell-local-dictionary))) |
(eq flyspell-dash-local-dictionary ispell-local-dictionary))) |
513 |
;; The dictionary has changed |
;; The dictionary has changed |
519 |
(setq flyspell-consider-dash-as-word-delimiter-flag t) |
(setq flyspell-consider-dash-as-word-delimiter-flag t) |
520 |
(setq flyspell-consider-dash-as-word-delimiter-flag nil))))) |
(setq flyspell-consider-dash-as-word-delimiter-flag nil))))) |
521 |
|
|
522 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
523 |
;* flyspell-mode-on ... */ |
;;* flyspell-mode-on ... */ |
524 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
525 |
(defun flyspell-mode-on () |
(defun flyspell-mode-on () |
526 |
"Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." |
"Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." |
527 |
(ispell-maybe-find-aspell-dictionaries) |
(ispell-maybe-find-aspell-dictionaries) |
564 |
;; we end with the flyspell hooks |
;; we end with the flyspell hooks |
565 |
(run-hooks 'flyspell-mode-hook)) |
(run-hooks 'flyspell-mode-hook)) |
566 |
|
|
567 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
568 |
;* flyspell-delay-commands ... */ |
;;* flyspell-delay-commands ... */ |
569 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
570 |
(defun flyspell-delay-commands () |
(defun flyspell-delay-commands () |
571 |
"Install the standard set of Flyspell delayed commands." |
"Install the standard set of Flyspell delayed commands." |
572 |
(mapcar 'flyspell-delay-command flyspell-default-delayed-commands) |
(mapcar 'flyspell-delay-command flyspell-default-delayed-commands) |
573 |
(mapcar 'flyspell-delay-command flyspell-delayed-commands)) |
(mapcar 'flyspell-delay-command flyspell-delayed-commands)) |
574 |
|
|
575 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
576 |
;* flyspell-delay-command ... */ |
;;* flyspell-delay-command ... */ |
577 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
578 |
(defun flyspell-delay-command (command) |
(defun flyspell-delay-command (command) |
579 |
"Set COMMAND to be delayed, for Flyspell. |
"Set COMMAND to be delayed, for Flyspell. |
580 |
When flyspell `post-command-hook' is invoked because a delayed command |
When flyspell `post-command-hook' is invoked because a delayed command |
583 |
(interactive "SDelay Flyspell after Command: ") |
(interactive "SDelay Flyspell after Command: ") |
584 |
(put command 'flyspell-delayed t)) |
(put command 'flyspell-delayed t)) |
585 |
|
|
586 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
587 |
;* flyspell-deplacement-commands ... */ |
;;* flyspell-deplacement-commands ... */ |
588 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
589 |
(defun flyspell-deplacement-commands () |
(defun flyspell-deplacement-commands () |
590 |
"Install the standard set of Flyspell deplacement commands." |
"Install the standard set of Flyspell deplacement commands." |
591 |
(mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands) |
(mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands) |
592 |
(mapcar 'flyspell-deplacement-command flyspell-deplacement-commands)) |
(mapcar 'flyspell-deplacement-command flyspell-deplacement-commands)) |
593 |
|
|
594 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
595 |
;* flyspell-deplacement-command ... */ |
;;* flyspell-deplacement-command ... */ |
596 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
597 |
(defun flyspell-deplacement-command (command) |
(defun flyspell-deplacement-command (command) |
598 |
"Set COMMAND that implement cursor movements, for Flyspell. |
"Set COMMAND that implement cursor movements, for Flyspell. |
599 |
When flyspell `post-command-hook' is invoked because of a deplacement command |
When flyspell `post-command-hook' is invoked because of a deplacement command |
602 |
(interactive "SDeplacement Flyspell after Command: ") |
(interactive "SDeplacement Flyspell after Command: ") |
603 |
(put command 'flyspell-deplacement t)) |
(put command 'flyspell-deplacement t)) |
604 |
|
|
605 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
606 |
;* flyspell-word-cache ... */ |
;;* flyspell-word-cache ... */ |
607 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
608 |
(defvar flyspell-word-cache-start nil) |
(defvar flyspell-word-cache-start nil) |
609 |
(defvar flyspell-word-cache-end nil) |
(defvar flyspell-word-cache-end nil) |
610 |
(defvar flyspell-word-cache-word nil) |
(defvar flyspell-word-cache-word nil) |
614 |
(make-variable-buffer-local 'flyspell-word-cache-word) |
(make-variable-buffer-local 'flyspell-word-cache-word) |
615 |
(make-variable-buffer-local 'flyspell-word-cache-result) |
(make-variable-buffer-local 'flyspell-word-cache-result) |
616 |
|
|
617 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
618 |
;* The flyspell pre-hook, store the current position. In the */ |
;;* The flyspell pre-hook, store the current position. In the */ |
619 |
;* post command hook, we will check, if the word at this position */ |
;;* post command hook, we will check, if the word at this position */ |
620 |
;* has to be spell checked. */ |
;;* has to be spell checked. */ |
621 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
622 |
(defvar flyspell-pre-buffer nil) |
(defvar flyspell-pre-buffer nil) |
623 |
(defvar flyspell-pre-point nil) |
(defvar flyspell-pre-point nil) |
624 |
(defvar flyspell-pre-column nil) |
(defvar flyspell-pre-column nil) |
625 |
(defvar flyspell-pre-pre-buffer nil) |
(defvar flyspell-pre-pre-buffer nil) |
626 |
(defvar flyspell-pre-pre-point nil) |
(defvar flyspell-pre-pre-point nil) |
627 |
|
|
628 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
629 |
;* flyspell-previous-command ... */ |
;;* flyspell-previous-command ... */ |
630 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
631 |
(defvar flyspell-previous-command nil |
(defvar flyspell-previous-command nil |
632 |
"The last interactive command checked by Flyspell.") |
"The last interactive command checked by Flyspell.") |
633 |
|
|
634 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
635 |
;* flyspell-pre-command-hook ... */ |
;;* flyspell-pre-command-hook ... */ |
636 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
637 |
(defun flyspell-pre-command-hook () |
(defun flyspell-pre-command-hook () |
638 |
"Save the current buffer and point for Flyspell's post-command hook." |
"Save the current buffer and point for Flyspell's post-command hook." |
639 |
(interactive) |
(interactive) |
641 |
(setq flyspell-pre-point (point)) |
(setq flyspell-pre-point (point)) |
642 |
(setq flyspell-pre-column (current-column))) |
(setq flyspell-pre-column (current-column))) |
643 |
|
|
644 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
645 |
;* flyspell-mode-off ... */ |
;;* flyspell-mode-off ... */ |
646 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
647 |
;;;###autoload |
;;;###autoload |
648 |
(defun flyspell-mode-off () |
(defun flyspell-mode-off () |
649 |
"Turn Flyspell mode off." |
"Turn Flyspell mode off." |
660 |
;; we mark the mode as killed |
;; we mark the mode as killed |
661 |
(setq flyspell-mode nil)) |
(setq flyspell-mode nil)) |
662 |
|
|
663 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
664 |
;* flyspell-check-pre-word-p ... */ |
;;* flyspell-check-pre-word-p ... */ |
665 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
666 |
(defun flyspell-check-pre-word-p () |
(defun flyspell-check-pre-word-p () |
667 |
"Return non-nil if we should check the word before point. |
"Return non-nil if we should check the word before point. |
668 |
More precisely, it applies to the word that was before point |
More precisely, it applies to the word that was before point |
698 |
(or (< flyspell-pre-point flyspell-word-cache-start) |
(or (< flyspell-pre-point flyspell-word-cache-start) |
699 |
(> flyspell-pre-point flyspell-word-cache-end))))) |
(> flyspell-pre-point flyspell-word-cache-end))))) |
700 |
|
|
701 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
702 |
;* The flyspell after-change-hook, store the change position. In */ |
;;* The flyspell after-change-hook, store the change position. In */ |
703 |
;* the post command hook, we will check, if the word at this */ |
;;* the post command hook, we will check, if the word at this */ |
704 |
;* position has to be spell checked. */ |
;;* position has to be spell checked. */ |
705 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
706 |
(defvar flyspell-changes nil) |
(defvar flyspell-changes nil) |
707 |
|
|
708 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
709 |
;* flyspell-after-change-function ... */ |
;;* flyspell-after-change-function ... */ |
710 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
711 |
(defun flyspell-after-change-function (start stop len) |
(defun flyspell-after-change-function (start stop len) |
712 |
"Save the current buffer and point for Flyspell's post-command hook." |
"Save the current buffer and point for Flyspell's post-command hook." |
713 |
(interactive) |
(interactive) |
714 |
(setq flyspell-changes (cons (cons start stop) flyspell-changes))) |
(setq flyspell-changes (cons (cons start stop) flyspell-changes))) |
715 |
|
|
716 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
717 |
;* flyspell-check-changed-word-p ... */ |
;;* flyspell-check-changed-word-p ... */ |
718 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
719 |
(defun flyspell-check-changed-word-p (start stop) |
(defun flyspell-check-changed-word-p (start stop) |
720 |
"Return t when the changed word has to be checked. |
"Return t when the changed word has to be checked. |
721 |
The answer depends of several criteria. |
The answer depends of several criteria. |
733 |
(t |
(t |
734 |
t))) |
t))) |
735 |
|
|
736 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
737 |
;* flyspell-check-word-p ... */ |
;;* flyspell-check-word-p ... */ |
738 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
739 |
(defun flyspell-check-word-p () |
(defun flyspell-check-word-p () |
740 |
"Return t when the word at `point' has to be checked. |
"Return t when the word at `point' has to be checked. |
741 |
The answer depends of several criteria. |
The answer depends of several criteria. |
765 |
(t t))) |
(t t))) |
766 |
(t t))) |
(t t))) |
767 |
|
|
768 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
769 |
;* flyspell-debug-signal-no-check ... */ |
;;* flyspell-debug-signal-no-check ... */ |
770 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
771 |
(defun flyspell-debug-signal-no-check (msg obj) |
(defun flyspell-debug-signal-no-check (msg obj) |
772 |
(setq debug-on-error t) |
(setq debug-on-error t) |
773 |
(save-excursion |
(with-current-buffer (get-buffer-create "*flyspell-debug*") |
774 |
(let ((buffer (get-buffer-create "*flyspell-debug*"))) |
(erase-buffer) |
775 |
(set-buffer buffer) |
(insert "NO-CHECK:\n") |
776 |
(erase-buffer) |
(insert (format " %S : %S\n" msg obj)))) |
777 |
(insert "NO-CHECK:\n") |
|
778 |
(insert (format " %S : %S\n" msg obj))))) |
;;*---------------------------------------------------------------------*/ |
779 |
|
;;* flyspell-debug-signal-pre-word-checked ... */ |
780 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
|
;* flyspell-debug-signal-pre-word-checked ... */ |
|
|
;*---------------------------------------------------------------------*/ |
|
781 |
(defun flyspell-debug-signal-pre-word-checked () |
(defun flyspell-debug-signal-pre-word-checked () |
782 |
(setq debug-on-error t) |
(setq debug-on-error t) |
783 |
(save-excursion |
(with-current-buffer (get-buffer-create "*flyspell-debug*") |
784 |
(let ((buffer (get-buffer-create "*flyspell-debug*"))) |
(insert "PRE-WORD:\n") |
785 |
(set-buffer buffer) |
(insert (format " pre-point : %S\n" flyspell-pre-point)) |
786 |
(insert "PRE-WORD:\n") |
(insert (format " pre-buffer : %S\n" flyspell-pre-buffer)) |
787 |
(insert (format " pre-point : %S\n" flyspell-pre-point)) |
(insert (format " cache-start: %S\n" flyspell-word-cache-start)) |
788 |
(insert (format " pre-buffer : %S\n" flyspell-pre-buffer)) |
(insert (format " cache-end : %S\n" flyspell-word-cache-end)) |
789 |
(insert (format " cache-start: %S\n" flyspell-word-cache-start)) |
(goto-char (point-max)))) |
790 |
(insert (format " cache-end : %S\n" flyspell-word-cache-end)) |
|
791 |
(goto-char (point-max))))) |
;;*---------------------------------------------------------------------*/ |
792 |
|
;;* flyspell-debug-signal-word-checked ... */ |
793 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
|
;* flyspell-debug-signal-word-checked ... */ |
|
|
;*---------------------------------------------------------------------*/ |
|
794 |
(defun flyspell-debug-signal-word-checked () |
(defun flyspell-debug-signal-word-checked () |
795 |
(setq debug-on-error t) |
(setq debug-on-error t) |
796 |
(save-excursion |
(let ((oldbuf (current-buffer)) |
797 |
(let ((oldbuf (current-buffer)) |
(point (point))) |
798 |
(buffer (get-buffer-create "*flyspell-debug*")) |
(with-current-buffer (get-buffer-create "*flyspell-debug*") |
|
(point (point))) |
|
|
(set-buffer buffer) |
|
799 |
(insert "WORD:\n") |
(insert "WORD:\n") |
800 |
(insert (format " this-cmd : %S\n" this-command)) |
(insert (format " this-cmd : %S\n" this-command)) |
801 |
(insert (format " delayed : %S\n" (and (symbolp this-command) |
(insert (format " delayed : %S\n" (and (symbolp this-command) |
802 |
(get this-command 'flyspell-delayed)))) |
(get this-command 'flyspell-delayed)))) |
803 |
(insert (format " point : %S\n" point)) |
(insert (format " point : %S\n" point)) |
804 |
(insert (format " prev-char : [%c] %S\n" |
(insert (format " prev-char : [%c] %S\n" |
805 |
(progn |
(with-current-buffer oldbuf |
|
(set-buffer oldbuf) |
|
806 |
(let ((c (if (> (point) (point-min)) |
(let ((c (if (> (point) (point-min)) |
807 |
(save-excursion |
(save-excursion |
808 |
(backward-char 1) |
(backward-char 1) |
809 |
(char-after (point))) |
(char-after (point))) |
810 |
? ))) |
? ))) |
|
(set-buffer buffer) |
|
811 |
c)) |
c)) |
812 |
(progn |
(with-current-buffer oldbuf |
|
(set-buffer oldbuf) |
|
813 |
(let ((c (if (> (point) (point-min)) |
(let ((c (if (> (point) (point-min)) |
814 |
(save-excursion |
(save-excursion |
815 |
(backward-char 1) |
(backward-char 1) |
816 |
(and (and (looking-at (flyspell-get-not-casechars)) 1) |
(and (and (looking-at (flyspell-get-not-casechars)) 1) |
817 |
(and (or flyspell-consider-dash-as-word-delimiter-flag |
(and (or flyspell-consider-dash-as-word-delimiter-flag |
818 |
(not (looking-at "\\-"))) 2)))))) |
(not (looking-at "\\-"))) 2)))))) |
|
(set-buffer buffer) |
|
819 |
c)))) |
c)))) |
820 |
(insert (format " because : %S\n" |
(insert (format " because : %S\n" |
821 |
(cond |
(cond |
824 |
;; the current command is not delayed, that |
;; the current command is not delayed, that |
825 |
;; is that we must check the word now |
;; is that we must check the word now |
826 |
'not-delayed) |
'not-delayed) |
827 |
((progn |
((with-current-buffer oldbuf |
|
(set-buffer oldbuf) |
|
828 |
(let ((c (if (> (point) (point-min)) |
(let ((c (if (> (point) (point-min)) |
829 |
(save-excursion |
(save-excursion |
830 |
(backward-char 1) |
(backward-char 1) |
831 |
(and (looking-at (flyspell-get-not-casechars)) |
(and (looking-at (flyspell-get-not-casechars)) |
832 |
(or flyspell-consider-dash-as-word-delimiter-flag |
(or flyspell-consider-dash-as-word-delimiter-flag |
833 |
(not (looking-at "\\-")))))))) |
(not (looking-at "\\-")))))))) |
|
(set-buffer buffer) |
|
834 |
c)) |
c)) |
835 |
;; yes because we have reached or typed a word delimiter. |
;; yes because we have reached or typed a word delimiter. |
836 |
'separator) |
'separator) |
841 |
'sit-for)))) |
'sit-for)))) |
842 |
(goto-char (point-max))))) |
(goto-char (point-max))))) |
843 |
|
|
844 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
845 |
;* flyspell-debug-signal-changed-checked ... */ |
;;* flyspell-debug-signal-changed-checked ... */ |
846 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
847 |
(defun flyspell-debug-signal-changed-checked () |
(defun flyspell-debug-signal-changed-checked () |
848 |
(setq debug-on-error t) |
(setq debug-on-error t) |
849 |
(save-excursion |
(let ((point (point))) |
850 |
(let ((buffer (get-buffer-create "*flyspell-debug*")) |
(with-current-buffer (get-buffer-create "*flyspell-debug*") |
|
(point (point))) |
|
|
(set-buffer buffer) |
|
851 |
(insert "CHANGED WORD:\n") |
(insert "CHANGED WORD:\n") |
852 |
(insert (format " point : %S\n" point)) |
(insert (format " point : %S\n" point)) |
853 |
(goto-char (point-max))))) |
(goto-char (point-max))))) |
854 |
|
|
855 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
856 |
;* flyspell-post-command-hook ... */ |
;;* flyspell-post-command-hook ... */ |
857 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
858 |
;* It is possible that we check several words: */ |
;;* It is possible that we check several words: */ |
859 |
;* 1- the current word is checked if the predicate */ |
;;* 1- the current word is checked if the predicate */ |
860 |
;* FLYSPELL-CHECK-WORD-P is true */ |
;;* FLYSPELL-CHECK-WORD-P is true */ |
861 |
;* 2- the word that used to be the current word before the */ |
;;* 2- the word that used to be the current word before the */ |
862 |
;* THIS-COMMAND is checked if: */ |
;;* THIS-COMMAND is checked if: */ |
863 |
;* a- the previous word is different from the current word */ |
;;* a- the previous word is different from the current word */ |
864 |
;* b- the previous word as not just been checked by the */ |
;;* b- the previous word as not just been checked by the */ |
865 |
;* previous FLYSPELL-POST-COMMAND-HOOK */ |
;;* previous FLYSPELL-POST-COMMAND-HOOK */ |
866 |
;* 3- the words changed by the THIS-COMMAND that are neither the */ |
;;* 3- the words changed by the THIS-COMMAND that are neither the */ |
867 |
;* previous word nor the current word */ |
;;* previous word nor the current word */ |
868 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
869 |
(defun flyspell-post-command-hook () |
(defun flyspell-post-command-hook () |
870 |
"The `post-command-hook' used by flyspell to check a word in-the-fly." |
"The `post-command-hook' used by flyspell to check a word in-the-fly." |
871 |
(interactive) |
(interactive) |
873 |
;; Prevent anything we do from affecting the mark. |
;; Prevent anything we do from affecting the mark. |
874 |
deactivate-mark) |
deactivate-mark) |
875 |
(if (flyspell-check-pre-word-p) |
(if (flyspell-check-pre-word-p) |
876 |
(save-excursion |
(with-current-buffer flyspell-pre-buffer |
877 |
'(flyspell-debug-signal-pre-word-checked) |
'(flyspell-debug-signal-pre-word-checked) |
|
(set-buffer flyspell-pre-buffer) |
|
878 |
(save-excursion |
(save-excursion |
879 |
(goto-char flyspell-pre-point) |
(goto-char flyspell-pre-point) |
880 |
(flyspell-word)))) |
(flyspell-word)))) |
910 |
(setq flyspell-changes (cdr flyspell-changes)))) |
(setq flyspell-changes (cdr flyspell-changes)))) |
911 |
(setq flyspell-previous-command command))) |
(setq flyspell-previous-command command))) |
912 |
|
|
913 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
914 |
;* flyspell-notify-misspell ... */ |
;;* flyspell-notify-misspell ... */ |
915 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
916 |
(defun flyspell-notify-misspell (start end word poss) |
(defun flyspell-notify-misspell (word poss) |
917 |
(let ((replacements (if (stringp poss) |
(let ((replacements (if (stringp poss) |
918 |
poss |
poss |
919 |
(if flyspell-sort-corrections |
(if flyspell-sort-corrections |
922 |
(if flyspell-issue-message-flag |
(if flyspell-issue-message-flag |
923 |
(message "misspelling `%s' %S" word replacements)))) |
(message "misspelling `%s' %S" word replacements)))) |
924 |
|
|
925 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
926 |
;* flyspell-word-search-backward ... */ |
;;* flyspell-word-search-backward ... */ |
927 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
928 |
(defun flyspell-word-search-backward (word bound) |
(defun flyspell-word-search-backward (word bound) |
929 |
(save-excursion |
(save-excursion |
930 |
(let ((r '()) |
(let ((r '()) |
936 |
(goto-char p)))) |
(goto-char p)))) |
937 |
r))) |
r))) |
938 |
|
|
939 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
940 |
;* flyspell-word-search-forward ... */ |
;;* flyspell-word-search-forward ... */ |
941 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
942 |
(defun flyspell-word-search-forward (word bound) |
(defun flyspell-word-search-forward (word bound) |
943 |
(save-excursion |
(save-excursion |
944 |
(let ((r '()) |
(let ((r '()) |
950 |
(goto-char (1+ p))))) |
(goto-char (1+ p))))) |
951 |
r))) |
r))) |
952 |
|
|
953 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
954 |
;* flyspell-word ... */ |
;;* flyspell-word ... */ |
955 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
956 |
(defun flyspell-word (&optional following) |
(defun flyspell-word (&optional following) |
957 |
"Spell check a word." |
"Spell check a word." |
958 |
(interactive (list ispell-following-word)) |
(interactive (list ispell-following-word)) |
960 |
;; use the correct dictionary |
;; use the correct dictionary |
961 |
(flyspell-accept-buffer-local-defs) |
(flyspell-accept-buffer-local-defs) |
962 |
(let* ((cursor-location (point)) |
(let* ((cursor-location (point)) |
963 |
(flyspell-word (flyspell-get-word following)) |
(flyspell-word (flyspell-get-word following)) |
964 |
start end poss word) |
start end poss word) |
965 |
(if (or (eq flyspell-word nil) |
(if (or (eq flyspell-word nil) |
966 |
(and (fboundp flyspell-generic-check-word-p) |
(and (fboundp flyspell-generic-check-word-p) |
967 |
(not (funcall flyspell-generic-check-word-p)))) |
(not (funcall flyspell-generic-check-word-p)))) |
1004 |
(setq flyspell-word-cache-end end) |
(setq flyspell-word-cache-end end) |
1005 |
(setq flyspell-word-cache-word word) |
(setq flyspell-word-cache-word word) |
1006 |
;; now check spelling of word. |
;; now check spelling of word. |
1007 |
(process-send-string ispell-process "%\n") |
(ispell-send-string "%\n") |
1008 |
;; put in verbose mode |
;; put in verbose mode |
1009 |
(process-send-string ispell-process |
(ispell-send-string (concat "^" word "\n")) |
|
(concat "^" word "\n")) |
|
1010 |
;; we mark the ispell process so it can be killed |
;; we mark the ispell process so it can be killed |
1011 |
;; when emacs is exited without query |
;; when emacs is exited without query |
1012 |
(set-process-query-on-exit-flag ispell-process nil) |
(set-process-query-on-exit-flag ispell-process nil) |
1013 |
;; wait until ispell has processed word |
;; Wait until ispell has processed word. Since this code is often |
1014 |
(while (progn |
;; executed rom post-command-hook but the ispell process may not |
1015 |
(accept-process-output ispell-process) |
;; be responsive, it's important to make sure we re-enable C-g. |
1016 |
(not (string= "" (car ispell-filter))))) |
(with-local-quit |
1017 |
;; (process-send-string ispell-process "!\n") |
(while (progn |
1018 |
|
(accept-process-output ispell-process) |
1019 |
|
(not (string= "" (car ispell-filter)))))) |
1020 |
|
;; (ispell-send-string "!\n") |
1021 |
;; back to terse mode. |
;; back to terse mode. |
1022 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1023 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1080 |
(if flyspell-highlight-flag |
(if flyspell-highlight-flag |
1081 |
(flyspell-highlight-incorrect-region |
(flyspell-highlight-incorrect-region |
1082 |
start end poss) |
start end poss) |
1083 |
(flyspell-notify-misspell start end word poss)) |
(flyspell-notify-misspell word poss)) |
1084 |
nil)))) |
nil)))) |
1085 |
;; return to original location |
;; return to original location |
1086 |
(goto-char cursor-location) |
(goto-char cursor-location) |
1087 |
(if ispell-quit (setq ispell-quit nil)) |
(if ispell-quit (setq ispell-quit nil)) |
1088 |
res)))))))) |
res)))))))) |
1089 |
|
|
1090 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1091 |
;* flyspell-tex-math-initialized ... */ |
;;* flyspell-tex-math-initialized ... */ |
1092 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1093 |
(defvar flyspell-tex-math-initialized nil) |
(defvar flyspell-tex-math-initialized nil) |
1094 |
|
|
1095 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1096 |
;* flyspell-math-tex-command-p ... */ |
;;* flyspell-math-tex-command-p ... */ |
1097 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
1098 |
;* This function uses the texmathp package to check if (point) */ |
;;* This function uses the texmathp package to check if (point) */ |
1099 |
;* is within a tex command. In order to avoid using */ |
;;* is within a tex command. In order to avoid using */ |
1100 |
;* condition-case each time we use the variable */ |
;;* condition-case each time we use the variable */ |
1101 |
;* flyspell-tex-math-initialized to make a special case the first */ |
;;* flyspell-tex-math-initialized to make a special case the first */ |
1102 |
;* time that function is called. */ |
;;* time that function is called. */ |
1103 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1104 |
(defun flyspell-math-tex-command-p () |
(defun flyspell-math-tex-command-p () |
1105 |
(when (fboundp 'texmathp) |
(when (fboundp 'texmathp) |
1106 |
(cond |
(cond |
1118 |
(setq flyspell-tex-math-initialized 'error) |
(setq flyspell-tex-math-initialized 'error) |
1119 |
nil))))))) |
nil))))))) |
1120 |
|
|
1121 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1122 |
;* flyspell-tex-command-p ... */ |
;;* flyspell-tex-command-p ... */ |
1123 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1124 |
(defun flyspell-tex-command-p (word) |
(defun flyspell-tex-command-p (word) |
1125 |
"Return t if WORD is a TeX command." |
"Return t if WORD is a TeX command." |
1126 |
(or (save-excursion |
(or (save-excursion |
1132 |
(>= (match-end 0) b)))))) |
(>= (match-end 0) b)))))) |
1133 |
(flyspell-math-tex-command-p))) |
(flyspell-math-tex-command-p))) |
1134 |
|
|
1135 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1136 |
;* flyspell-casechars-cache ... */ |
;;* flyspell-casechars-cache ... */ |
1137 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1138 |
(defvar flyspell-casechars-cache nil) |
(defvar flyspell-casechars-cache nil) |
1139 |
(defvar flyspell-ispell-casechars-cache nil) |
(defvar flyspell-ispell-casechars-cache nil) |
1140 |
(make-variable-buffer-local 'flyspell-casechars-cache) |
(make-variable-buffer-local 'flyspell-casechars-cache) |
1141 |
(make-variable-buffer-local 'flyspell-ispell-casechars-cache) |
(make-variable-buffer-local 'flyspell-ispell-casechars-cache) |
1142 |
|
|
1143 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1144 |
;* flyspell-get-casechars ... */ |
;;* flyspell-get-casechars ... */ |
1145 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1146 |
(defun flyspell-get-casechars () |
(defun flyspell-get-casechars () |
1147 |
"This function builds a string that is the regexp of word chars. |
"This function builds a string that is the regexp of word chars. |
1148 |
In order to avoid one useless string construction, |
In order to avoid one useless string construction, |
1162 |
(setq flyspell-casechars-cache ispell-casechars) |
(setq flyspell-casechars-cache ispell-casechars) |
1163 |
flyspell-casechars-cache)))) |
flyspell-casechars-cache)))) |
1164 |
|
|
1165 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1166 |
;* flyspell-get-not-casechars-cache ... */ |
;;* flyspell-get-not-casechars-cache ... */ |
1167 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1168 |
(defvar flyspell-not-casechars-cache nil) |
(defvar flyspell-not-casechars-cache nil) |
1169 |
(defvar flyspell-ispell-not-casechars-cache nil) |
(defvar flyspell-ispell-not-casechars-cache nil) |
1170 |
(make-variable-buffer-local 'flyspell-not-casechars-cache) |
(make-variable-buffer-local 'flyspell-not-casechars-cache) |
1171 |
(make-variable-buffer-local 'flyspell-ispell-not-casechars-cache) |
(make-variable-buffer-local 'flyspell-ispell-not-casechars-cache) |
1172 |
|
|
1173 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1174 |
;* flyspell-get-not-casechars ... */ |
;;* flyspell-get-not-casechars ... */ |
1175 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1176 |
(defun flyspell-get-not-casechars () |
(defun flyspell-get-not-casechars () |
1177 |
"This function builds a string that is the regexp of non-word chars." |
"This function builds a string that is the regexp of non-word chars." |
1178 |
(let ((ispell-not-casechars (ispell-get-not-casechars))) |
(let ((ispell-not-casechars (ispell-get-not-casechars))) |
1190 |
(setq flyspell-not-casechars-cache ispell-not-casechars) |
(setq flyspell-not-casechars-cache ispell-not-casechars) |
1191 |
flyspell-not-casechars-cache)))) |
flyspell-not-casechars-cache)))) |
1192 |
|
|
1193 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1194 |
;* flyspell-get-word ... */ |
;;* flyspell-get-word ... */ |
1195 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1196 |
(defun flyspell-get-word (following &optional extra-otherchars) |
(defun flyspell-get-word (following &optional extra-otherchars) |
1197 |
"Return the word for spell-checking according to Ispell syntax. |
"Return the word for spell-checking according to Ispell syntax. |
1198 |
If optional argument FOLLOWING is non-nil or if `flyspell-following-word' |
If optional argument FOLLOWING is non-nil or if `flyspell-following-word' |
1253 |
word (buffer-substring-no-properties start end)) |
word (buffer-substring-no-properties start end)) |
1254 |
(list word start end))))) |
(list word start end))))) |
1255 |
|
|
1256 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1257 |
;* flyspell-small-region ... */ |
;;* flyspell-small-region ... */ |
1258 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1259 |
(defun flyspell-small-region (beg end) |
(defun flyspell-small-region (beg end) |
1260 |
"Flyspell text between BEG and END." |
"Flyspell text between BEG and END." |
1261 |
(save-excursion |
(save-excursion |
1282 |
(if flyspell-issue-message-flag (message "Spell Checking completed.")) |
(if flyspell-issue-message-flag (message "Spell Checking completed.")) |
1283 |
(flyspell-word))) |
(flyspell-word))) |
1284 |
|
|
1285 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1286 |
;* flyspell-external-ispell-process ... */ |
;;* flyspell-external-ispell-process ... */ |
1287 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1288 |
(defvar flyspell-external-ispell-process '() |
(defvar flyspell-external-ispell-process '() |
1289 |
"The external Flyspell Ispell process.") |
"The external Flyspell Ispell process.") |
1290 |
|
|
1291 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1292 |
;* flyspell-external-ispell-buffer ... */ |
;;* flyspell-external-ispell-buffer ... */ |
1293 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1294 |
(defvar flyspell-external-ispell-buffer '()) |
(defvar flyspell-external-ispell-buffer '()) |
1295 |
(defvar flyspell-large-region-buffer '()) |
(defvar flyspell-large-region-buffer '()) |
1296 |
(defvar flyspell-large-region-beg (point-min)) |
(defvar flyspell-large-region-beg (point-min)) |
1297 |
(defvar flyspell-large-region-end (point-max)) |
(defvar flyspell-large-region-end (point-max)) |
1298 |
|
|
1299 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1300 |
;* flyspell-external-point-words ... */ |
;;* flyspell-external-point-words ... */ |
1301 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1302 |
(defun flyspell-external-point-words () |
(defun flyspell-external-point-words () |
1303 |
"Mark words from a buffer listing incorrect words in order of appearance. |
"Mark words from a buffer listing incorrect words in order of appearance. |
1304 |
The list of incorrect words should be in `flyspell-external-ispell-buffer'. |
The list of incorrect words should be in `flyspell-external-ispell-buffer'. |
1349 |
(kill-buffer flyspell-external-ispell-buffer) |
(kill-buffer flyspell-external-ispell-buffer) |
1350 |
(setq flyspell-external-ispell-buffer nil)) |
(setq flyspell-external-ispell-buffer nil)) |
1351 |
|
|
1352 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1353 |
;* flyspell-process-localwords ... */ |
;;* flyspell-process-localwords ... */ |
1354 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
1355 |
;* This function is used to prevent marking of words explicitly */ |
;;* This function is used to prevent marking of words explicitly */ |
1356 |
;* declared correct. */ |
;;* declared correct. */ |
1357 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1358 |
(defun flyspell-process-localwords (misspellings-buffer) |
(defun flyspell-process-localwords (misspellings-buffer) |
1359 |
(let (localwords |
(let (localwords |
1360 |
(ispell-casechars (ispell-get-casechars))) |
(ispell-casechars (ispell-get-casechars))) |
1387 |
(while (re-search-forward regexp nil t) |
(while (re-search-forward regexp nil t) |
1388 |
(delete-region (match-beginning 0) (match-end 0))))))))) |
(delete-region (match-beginning 0) (match-end 0))))))))) |
1389 |
|
|
1390 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1391 |
;* flyspell-large-region ... */ |
;;* flyspell-large-region ... */ |
1392 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1393 |
(defun flyspell-large-region (beg end) |
(defun flyspell-large-region (beg end) |
1394 |
(let* ((curbuf (current-buffer)) |
(let* ((curbuf (current-buffer)) |
1395 |
(buffer (get-buffer-create "*flyspell-region*"))) |
(buffer (get-buffer-create "*flyspell-region*"))) |
1437 |
(flyspell-external-point-words)) |
(flyspell-external-point-words)) |
1438 |
(error "Can't check region..."))))) |
(error "Can't check region..."))))) |
1439 |
|
|
1440 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1441 |
;* flyspell-region ... */ |
;;* flyspell-region ... */ |
1442 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
1443 |
;* Because `ispell -a' is too slow, it is not possible to use */ |
;;* Because `ispell -a' is too slow, it is not possible to use */ |
1444 |
;* it on large region. Then, when ispell is invoked on a large */ |
;;* it on large region. Then, when ispell is invoked on a large */ |
1445 |
;* text region, a new `ispell -l' process is spawned. The */ |
;;* text region, a new `ispell -l' process is spawned. The */ |
1446 |
;* pointed out words are then searched in the region a checked with */ |
;;* pointed out words are then searched in the region a checked with */ |
1447 |
;* regular flyspell means. */ |
;;* regular flyspell means. */ |
1448 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1449 |
;;;###autoload |
;;;###autoload |
1450 |
(defun flyspell-region (beg end) |
(defun flyspell-region (beg end) |
1451 |
"Flyspell text between BEG and END." |
"Flyspell text between BEG and END." |
1461 |
(flyspell-large-region beg end) |
(flyspell-large-region beg end) |
1462 |
(flyspell-small-region beg end))))) |
(flyspell-small-region beg end))))) |
1463 |
|
|
1464 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1465 |
;* flyspell-buffer ... */ |
;;* flyspell-buffer ... */ |
1466 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1467 |
;;;###autoload |
;;;###autoload |
1468 |
(defun flyspell-buffer () |
(defun flyspell-buffer () |
1469 |
"Flyspell whole buffer." |
"Flyspell whole buffer." |
1470 |
(interactive) |
(interactive) |
1471 |
(flyspell-region (point-min) (point-max))) |
(flyspell-region (point-min) (point-max))) |
1472 |
|
|
1473 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1474 |
;* old next error position ... */ |
;;* old next error position ... */ |
1475 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1476 |
(defvar flyspell-old-buffer-error nil) |
(defvar flyspell-old-buffer-error nil) |
1477 |
(defvar flyspell-old-pos-error nil) |
(defvar flyspell-old-pos-error nil) |
1478 |
|
|
1479 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1480 |
;* flyspell-goto-next-error ... */ |
;;* flyspell-goto-next-error ... */ |
1481 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1482 |
(defun flyspell-goto-next-error () |
(defun flyspell-goto-next-error () |
1483 |
"Go to the next previously detected error. |
"Go to the next previously detected error. |
1484 |
In general FLYSPELL-GOTO-NEXT-ERROR must be used after |
In general FLYSPELL-GOTO-NEXT-ERROR must be used after |
1513 |
(if (= pos max) |
(if (= pos max) |
1514 |
(message "No more miss-spelled word!")))) |
(message "No more miss-spelled word!")))) |
1515 |
|
|
1516 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1517 |
;* flyspell-overlay-p ... */ |
;;* flyspell-overlay-p ... */ |
1518 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1519 |
(defun flyspell-overlay-p (o) |
(defun flyspell-overlay-p (o) |
1520 |
"A predicate that return true iff O is an overlay used by flyspell." |
"A predicate that return true iff O is an overlay used by flyspell." |
1521 |
(and (overlayp o) (overlay-get o 'flyspell-overlay))) |
(and (overlayp o) (overlay-get o 'flyspell-overlay))) |
1522 |
|
|
1523 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1524 |
;* flyspell-delete-region-overlays, flyspell-delete-all-overlays */ |
;;* flyspell-delete-region-overlays, flyspell-delete-all-overlays */ |
1525 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
1526 |
;* Remove overlays introduced by flyspell. */ |
;;* Remove overlays introduced by flyspell. */ |
1527 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1528 |
(defun flyspell-delete-region-overlays (beg end) |
(defun flyspell-delete-region-overlays (beg end) |
1529 |
"Delete overlays used by flyspell in a given region." |
"Delete overlays used by flyspell in a given region." |
1530 |
(remove-overlays beg end 'flyspell-overlay t)) |
(remove-overlays beg end 'flyspell-overlay t)) |
1534 |
"Delete all the overlays used by flyspell." |
"Delete all the overlays used by flyspell." |
1535 |
(flyspell-delete-region-overlays (point-min) (point-max))) |
(flyspell-delete-region-overlays (point-min) (point-max))) |
1536 |
|
|
1537 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1538 |
;* flyspell-unhighlight-at ... */ |
;;* flyspell-unhighlight-at ... */ |
1539 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1540 |
(defun flyspell-unhighlight-at (pos) |
(defun flyspell-unhighlight-at (pos) |
1541 |
"Remove the flyspell overlay that are located at POS." |
"Remove the flyspell overlay that are located at POS." |
1542 |
(if flyspell-persistent-highlight |
(if flyspell-persistent-highlight |
1546 |
(delete-overlay (car overlays))) |
(delete-overlay (car overlays))) |
1547 |
(setq overlays (cdr overlays)))) |
(setq overlays (cdr overlays)))) |
1548 |
(if (flyspell-overlay-p flyspell-overlay) |
(if (flyspell-overlay-p flyspell-overlay) |
1549 |
(delete-overlay flyspell-overlay)))) |
(delete-overlay flyspell-overlay)))) |
1550 |
|
|
1551 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1552 |
;* flyspell-properties-at-p ... */ |
;;* flyspell-properties-at-p ... */ |
1553 |
;* ------------------------------------------------------------- */ |
;;* ------------------------------------------------------------- */ |
1554 |
;* Is there an highlight properties at position pos? */ |
;;* Is there an highlight properties at position pos? */ |
1555 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1556 |
(defun flyspell-properties-at-p (pos) |
(defun flyspell-properties-at-p (pos) |
1557 |
"Return t if there is a text property at POS, not counting `local-map'. |
"Return t if there is a text property at POS, not counting `local-map'. |
1558 |
If variable `flyspell-highlight-properties' is set to nil, |
If variable `flyspell-highlight-properties' is set to nil, |
1566 |
(setq keep nil))) |
(setq keep nil))) |
1567 |
(consp prop))) |
(consp prop))) |
1568 |
|
|
1569 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1570 |
;* make-flyspell-overlay ... */ |
;;* make-flyspell-overlay ... */ |
1571 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1572 |
(defun make-flyspell-overlay (beg end face mouse-face) |
(defun make-flyspell-overlay (beg end face mouse-face) |
1573 |
"Allocate an overlay to highlight an incorrect word. |
"Allocate an overlay to highlight an incorrect word. |
1574 |
BEG and END specify the range in the buffer of that word. |
BEG and END specify the range in the buffer of that word. |
1575 |
FACE and MOUSE-FACE specify the `face' and `mouse-face' properties |
FACE and MOUSE-FACE specify the `face' and `mouse-face' properties |
1576 |
for the overlay." |
for the overlay." |
1577 |
(let ((flyspell-overlay (make-overlay beg end nil t nil))) |
(let ((overlay (make-overlay beg end nil t nil))) |
1578 |
(overlay-put flyspell-overlay 'face face) |
(overlay-put overlay 'face face) |
1579 |
(overlay-put flyspell-overlay 'mouse-face mouse-face) |
(overlay-put overlay 'mouse-face mouse-face) |
1580 |
(overlay-put flyspell-overlay 'flyspell-overlay t) |
(overlay-put overlay 'flyspell-overlay t) |
1581 |
(overlay-put flyspell-overlay 'evaporate t) |
(overlay-put overlay 'evaporate t) |
1582 |
(overlay-put flyspell-overlay 'help-echo "mouse-2: correct word at point") |
(overlay-put overlay 'help-echo "mouse-2: correct word at point") |
1583 |
(overlay-put flyspell-overlay 'keymap flyspell-mouse-map) |
(overlay-put overlay 'keymap flyspell-mouse-map) |
1584 |
(when (eq face 'flyspell-incorrect) |
(when (eq face 'flyspell-incorrect) |
1585 |
(and (stringp flyspell-before-incorrect-word-string) |
(and (stringp flyspell-before-incorrect-word-string) |
1586 |
(overlay-put flyspell-overlay 'before-string |
(overlay-put overlay 'before-string |
1587 |
flyspell-before-incorrect-word-string)) |
flyspell-before-incorrect-word-string)) |
1588 |
(and (stringp flyspell-after-incorrect-word-string) |
(and (stringp flyspell-after-incorrect-word-string) |
1589 |
(overlay-put flyspell-overlay 'after-string |
(overlay-put overlay 'after-string |
1590 |
flyspell-after-incorrect-word-string))) |
flyspell-after-incorrect-word-string))) |
1591 |
flyspell-overlay)) |
overlay)) |
1592 |
|
|
1593 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1594 |
;* flyspell-highlight-incorrect-region ... */ |
;;* flyspell-highlight-incorrect-region ... */ |
1595 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1596 |
(defun flyspell-highlight-incorrect-region (beg end poss) |
(defun flyspell-highlight-incorrect-region (beg end poss) |
1597 |
"Set up an overlay on a misspelled word, in the buffer from BEG to END. |
"Set up an overlay on a misspelled word, in the buffer from BEG to END. |
1598 |
POSS is usually a list of possible spelling/correction lists, |
POSS is usually a list of possible spelling/correction lists, |
1614 |
(delete-overlay (car os))) |
(delete-overlay (car os))) |
1615 |
(setq os (cdr os))))) |
(setq os (cdr os))))) |
1616 |
;; we cleanup current overlay at the same position |
;; we cleanup current overlay at the same position |
1617 |
(if (and (not flyspell-persistent-highlight) |
(flyspell-unhighlight-at beg) |
|
(overlayp flyspell-overlay)) |
|
|
(delete-overlay flyspell-overlay) |
|
|
(let ((os (overlays-at beg))) |
|
|
(while (consp os) |
|
|
(if (flyspell-overlay-p (car os)) |
|
|
(delete-overlay (car os))) |
|
|
(setq os (cdr os))))) |
|
1618 |
;; now we can use a new overlay |
;; now we can use a new overlay |
1619 |
(setq flyspell-overlay |
(setq flyspell-overlay |
1620 |
(make-flyspell-overlay |
(make-flyspell-overlay |
1621 |
beg end 'flyspell-incorrect 'highlight))))))) |
beg end 'flyspell-incorrect 'highlight))))))) |
1622 |
|
|
1623 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1624 |
;* flyspell-highlight-duplicate-region ... */ |
;;* flyspell-highlight-duplicate-region ... */ |
1625 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1626 |
(defun flyspell-highlight-duplicate-region (beg end poss) |
(defun flyspell-highlight-duplicate-region (beg end poss) |
1627 |
"Set up an overlay on a duplicate misspelled word, in the buffer from BEG to END. |
"Set up an overlay on a duplicate misspelled word, in the buffer from BEG to END. |
1628 |
POSS is a list of possible spelling/correction lists, |
POSS is a list of possible spelling/correction lists, |
1634 |
(not (flyspell-properties-at-p beg))) |
(not (flyspell-properties-at-p beg))) |
1635 |
(progn |
(progn |
1636 |
;; we cleanup current overlay at the same position |
;; we cleanup current overlay at the same position |
1637 |
(if (and (not flyspell-persistent-highlight) |
(flyspell-unhighlight-at beg) |
|
(overlayp flyspell-overlay)) |
|
|
(delete-overlay flyspell-overlay) |
|
|
(let ((overlays (overlays-at beg))) |
|
|
(while (consp overlays) |
|
|
(if (flyspell-overlay-p (car overlays)) |
|
|
(delete-overlay (car overlays))) |
|
|
(setq overlays (cdr overlays))))) |
|
1638 |
;; now we can use a new overlay |
;; now we can use a new overlay |
1639 |
(setq flyspell-overlay |
(setq flyspell-overlay |
1640 |
(make-flyspell-overlay beg end |
(make-flyspell-overlay beg end |
1641 |
'flyspell-duplicate |
'flyspell-duplicate |
1642 |
'highlight))))))) |
'highlight))))))) |
1643 |
|
|
1644 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1645 |
;* flyspell-auto-correct-cache ... */ |
;;* flyspell-auto-correct-cache ... */ |
1646 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1647 |
(defvar flyspell-auto-correct-pos nil) |
(defvar flyspell-auto-correct-pos nil) |
1648 |
(defvar flyspell-auto-correct-region nil) |
(defvar flyspell-auto-correct-region nil) |
1649 |
(defvar flyspell-auto-correct-ring nil) |
(defvar flyspell-auto-correct-ring nil) |
1653 |
(make-variable-buffer-local 'flyspell-auto-correct-ring) |
(make-variable-buffer-local 'flyspell-auto-correct-ring) |
1654 |
(make-variable-buffer-local 'flyspell-auto-correct-word) |
(make-variable-buffer-local 'flyspell-auto-correct-word) |
1655 |
|
|
1656 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1657 |
;* flyspell-check-previous-highlighted-word ... */ |
;;* flyspell-check-previous-highlighted-word ... */ |
1658 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1659 |
(defun flyspell-check-previous-highlighted-word (&optional arg) |
(defun flyspell-check-previous-highlighted-word (&optional arg) |
1660 |
"Correct the closer misspelled word. |
"Correct the closer misspelled word. |
1661 |
This function scans a mis-spelled word before the cursor. If it finds one |
This function scans a mis-spelled word before the cursor. If it finds one |
1676 |
(while (consp ovs) |
(while (consp ovs) |
1677 |
(setq ov (car ovs)) |
(setq ov (car ovs)) |
1678 |
(setq ovs (cdr ovs)) |
(setq ovs (cdr ovs)) |
1679 |
(if (and (overlay-get ov 'flyspell-overlay) |
(if (and (flyspell-overlay-p ov) |
1680 |
(= 0 (setq arg (1- arg)))) |
(= 0 (setq arg (1- arg)))) |
1681 |
(throw 'exit t))))))) |
(throw 'exit t))))))) |
1682 |
(save-excursion |
(save-excursion |
1684 |
(ispell-word)) |
(ispell-word)) |
1685 |
(error "No word to correct before point")))) |
(error "No word to correct before point")))) |
1686 |
|
|
1687 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1688 |
;* flyspell-display-next-corrections ... */ |
;;* flyspell-display-next-corrections ... */ |
1689 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1690 |
(defun flyspell-display-next-corrections (corrections) |
(defun flyspell-display-next-corrections (corrections) |
1691 |
(let ((string "Corrections:") |
(let ((string "Corrections:") |
1692 |
(l corrections) |
(l corrections) |
1707 |
(display-message 'no-log string) |
(display-message 'no-log string) |
1708 |
(message "%s" string)))) |
(message "%s" string)))) |
1709 |
|
|
1710 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1711 |
;* flyspell-abbrev-table ... */ |
;;* flyspell-abbrev-table ... */ |
1712 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1713 |
(defun flyspell-abbrev-table () |
(defun flyspell-abbrev-table () |
1714 |
(if flyspell-use-global-abbrev-table-p |
(if flyspell-use-global-abbrev-table-p |
1715 |
global-abbrev-table |
global-abbrev-table |
1716 |
(or local-abbrev-table global-abbrev-table))) |
(or local-abbrev-table global-abbrev-table))) |
1717 |
|
|
1718 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1719 |
;* flyspell-define-abbrev ... */ |
;;* flyspell-define-abbrev ... */ |
1720 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1721 |
(defun flyspell-define-abbrev (name expansion) |
(defun flyspell-define-abbrev (name expansion) |
1722 |
(let ((table (flyspell-abbrev-table))) |
(let ((table (flyspell-abbrev-table))) |
1723 |
(when table |
(when table |
1724 |
(define-abbrev table name expansion)))) |
(define-abbrev table name expansion)))) |
1725 |
|
|
1726 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1727 |
;* flyspell-auto-correct-word ... */ |
;;* flyspell-auto-correct-word ... */ |
1728 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1729 |
(defun flyspell-auto-correct-word () |
(defun flyspell-auto-correct-word () |
1730 |
"Correct the current word. |
"Correct the current word. |
1731 |
This command proposes various successive corrections for the current word." |
This command proposes various successive corrections for the current word." |
1767 |
poss) |
poss) |
1768 |
(setq flyspell-auto-correct-word word) |
(setq flyspell-auto-correct-word word) |
1769 |
;; now check spelling of word. |
;; now check spelling of word. |
1770 |
(process-send-string ispell-process "%\n") ;put in verbose mode |
(ispell-send-string "%\n") ;put in verbose mode |
1771 |
(process-send-string ispell-process (concat "^" word "\n")) |
(ispell-send-string (concat "^" word "\n")) |
1772 |
;; wait until ispell has processed word |
;; wait until ispell has processed word. |
1773 |
(while (progn |
(while (progn |
1774 |
(accept-process-output ispell-process) |
(accept-process-output ispell-process) |
1775 |
(not (string= "" (car ispell-filter))))) |
(not (string= "" (car ispell-filter))))) |
1776 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1777 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1778 |
(setq poss (ispell-parse-output (car ispell-filter)))) |
(setq poss (ispell-parse-output (car ispell-filter)))) |
1825 |
(setq flyspell-auto-correct-pos (point)) |
(setq flyspell-auto-correct-pos (point)) |
1826 |
(ispell-pdict-save t))))))) |
(ispell-pdict-save t))))))) |
1827 |
|
|
1828 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1829 |
;* flyspell-auto-correct-previous-pos ... */ |
;;* flyspell-auto-correct-previous-pos ... */ |
1830 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1831 |
(defvar flyspell-auto-correct-previous-pos nil |
(defvar flyspell-auto-correct-previous-pos nil |
1832 |
"Holds the start of the first incorrect word before point.") |
"Holds the start of the first incorrect word before point.") |
1833 |
|
|
1834 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1835 |
;* flyspell-auto-correct-previous-hook ... */ |
;;* flyspell-auto-correct-previous-hook ... */ |
1836 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1837 |
(defun flyspell-auto-correct-previous-hook () |
(defun flyspell-auto-correct-previous-hook () |
1838 |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
"Hook to track successive calls to `flyspell-auto-correct-previous-word'. |
1839 |
Sets `flyspell-auto-correct-previous-pos' to nil" |
Sets `flyspell-auto-correct-previous-pos' to nil" |
1842 |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
(unless (eq this-command (function flyspell-auto-correct-previous-word)) |
1843 |
(setq flyspell-auto-correct-previous-pos nil))) |
(setq flyspell-auto-correct-previous-pos nil))) |
1844 |
|
|
1845 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1846 |
;* flyspell-auto-correct-previous-word ... */ |
;;* flyspell-auto-correct-previous-word ... */ |
1847 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1848 |
(defun flyspell-auto-correct-previous-word (position) |
(defun flyspell-auto-correct-previous-word (position) |
1849 |
"*Auto correct the first mispelled word that occurs before point. |
"Auto correct the first mispelled word that occurs before point. |
1850 |
But don't look beyond what's visible on the screen." |
But don't look beyond what's visible on the screen." |
1851 |
(interactive "d") |
(interactive "d") |
1852 |
|
|
1896 |
;; the point may have moved so reset this |
;; the point may have moved so reset this |
1897 |
(setq flyspell-auto-correct-previous-pos (point)))))))) |
(setq flyspell-auto-correct-previous-pos (point)))))))) |
1898 |
|
|
1899 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1900 |
;* flyspell-correct-word ... */ |
;;* flyspell-correct-word ... */ |
1901 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1902 |
(defun flyspell-correct-word (event) |
(defun flyspell-correct-word (event) |
1903 |
"Pop up a menu of possible corrections for a misspelled word. |
"Pop up a menu of possible corrections for a misspelled word. |
1904 |
The word checked is the word at the mouse position." |
The word checked is the word at the mouse position." |
1916 |
(word (car word)) |
(word (car word)) |
1917 |
poss) |
poss) |
1918 |
;; now check spelling of word. |
;; now check spelling of word. |
1919 |
(process-send-string ispell-process "%\n") ;put in verbose mode |
(ispell-send-string "%\n") ;put in verbose mode |
1920 |
(process-send-string ispell-process (concat "^" word "\n")) |
(ispell-send-string (concat "^" word "\n")) |
1921 |
;; wait until ispell has processed word |
;; wait until ispell has processed word |
1922 |
(while (progn |
(while (progn |
1923 |
(accept-process-output ispell-process) |
(accept-process-output ispell-process) |
1924 |
(not (string= "" (car ispell-filter))))) |
(not (string= "" (car ispell-filter))))) |
1925 |
(setq ispell-filter (cdr ispell-filter)) |
(setq ispell-filter (cdr ispell-filter)) |
1926 |
(if (consp ispell-filter) |
(if (consp ispell-filter) |
1927 |
(setq poss (ispell-parse-output (car ispell-filter)))) |
(setq poss (ispell-parse-output (car ispell-filter)))) |
1934 |
(error "Ispell: error in Ispell process")) |
(error "Ispell: error in Ispell process")) |
1935 |
((featurep 'xemacs) |
((featurep 'xemacs) |
1936 |
(flyspell-xemacs-popup |
(flyspell-xemacs-popup |
1937 |
event poss word cursor-location start end save)) |
poss word cursor-location start end save)) |
1938 |
(t |
(t |
1939 |
;; The word is incorrect, we have to propose a replacement. |
;; The word is incorrect, we have to propose a replacement. |
1940 |
(flyspell-do-correct (flyspell-emacs-popup event poss word) |
(flyspell-do-correct (flyspell-emacs-popup event poss word) |
1941 |
poss word cursor-location start end save))) |
poss word cursor-location start end save))) |
1942 |
(ispell-pdict-save t)))))) |
(ispell-pdict-save t)))))) |
1943 |
|
|
1944 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1945 |
;* flyspell-do-correct ... */ |
;;* flyspell-do-correct ... */ |
1946 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1947 |
(defun flyspell-do-correct (replace poss word cursor-location start end save) |
(defun flyspell-do-correct (replace poss word cursor-location start end save) |
1948 |
"The popup menu callback." |
"The popup menu callback." |
1949 |
;; Originally, the XEmacs code didn't do the (goto-char save) here and did |
;; Originally, the XEmacs code didn't do the (goto-char save) here and did |
1992 |
(goto-char save) |
(goto-char save) |
1993 |
nil))) |
nil))) |
1994 |
|
|
1995 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1996 |
;* flyspell-ajust-cursor-point ... */ |
;;* flyspell-ajust-cursor-point ... */ |
1997 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
1998 |
(defun flyspell-ajust-cursor-point (save cursor-location old-max) |
(defun flyspell-ajust-cursor-point (save cursor-location old-max) |
1999 |
(if (>= save cursor-location) |
(if (>= save cursor-location) |
2000 |
(let ((new-pos (+ save (- (point-max) old-max)))) |
(let ((new-pos (+ save (- (point-max) old-max)))) |
2006 |
(t new-pos)))) |
(t new-pos)))) |
2007 |
(goto-char save))) |
(goto-char save))) |
2008 |
|
|
2009 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2010 |
;* flyspell-emacs-popup ... */ |
;;* flyspell-emacs-popup ... */ |
2011 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2012 |
(defun flyspell-emacs-popup (event poss word) |
(defun flyspell-emacs-popup (event poss word) |
2013 |
"The Emacs popup menu." |
"The Emacs popup menu." |
2014 |
(if (not event) |
(if (not event) |
2048 |
ispell-dictionary)) |
ispell-dictionary)) |
2049 |
menu))))) |
menu))))) |
2050 |
|
|
2051 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2052 |
;* flyspell-xemacs-popup ... */ |
;;* flyspell-xemacs-popup ... */ |
2053 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2054 |
(defun flyspell-xemacs-popup (event poss word cursor-location start end save) |
(defun flyspell-xemacs-popup (poss word cursor-location start end save) |
2055 |
"The XEmacs popup menu." |
"The XEmacs popup menu." |
2056 |
(let* ((corrects (if flyspell-sort-corrections |
(let* ((corrects (if flyspell-sort-corrections |
2057 |
(sort (car (cdr (cdr poss))) 'string<) |
(sort (car (cdr (cdr poss))) 'string<) |
2121 |
ispell-dictionary)) |
ispell-dictionary)) |
2122 |
menu)))) |
menu)))) |
2123 |
|
|
2124 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2125 |
;* Some example functions for real autocorrecting */ |
;;* Some example functions for real autocorrecting */ |
2126 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2127 |
(defun flyspell-maybe-correct-transposition (beg end poss) |
(defun flyspell-maybe-correct-transposition (beg end poss) |
2128 |
"Check replacements for transposed characters. |
"Check replacements for transposed characters. |
2129 |
|
|
2180 |
(setq i (1+ i)))) |
(setq i (1+ i)))) |
2181 |
nil))) |
nil))) |
2182 |
|
|
2183 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2184 |
;* flyspell-already-abbrevp ... */ |
;;* flyspell-already-abbrevp ... */ |
2185 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2186 |
(defun flyspell-already-abbrevp (table word) |
(defun flyspell-already-abbrevp (table word) |
2187 |
(let ((sym (abbrev-symbol word table))) |
(let ((sym (abbrev-symbol word table))) |
2188 |
(and sym (symbolp sym)))) |
(and sym (symbolp sym)))) |
2189 |
|
|
2190 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2191 |
;* flyspell-change-abbrev ... */ |
;;* flyspell-change-abbrev ... */ |
2192 |
;*---------------------------------------------------------------------*/ |
;;*---------------------------------------------------------------------*/ |
2193 |
(defun flyspell-change-abbrev (table old new) |
(defun flyspell-change-abbrev (table old new) |
2194 |
(set (abbrev-symbol old table) new)) |
(set (abbrev-symbol old table) new)) |
2195 |
|
|