-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathflyspell-1.7n.el
2443 lines (2280 loc) · 96.1 KB
/
flyspell-1.7n.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; <pre>
;;; flyspell.el --- on-the-fly spell checker
;; Copyright (C) 1998, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
;; Author: Manuel Serrano <Manuel.Serrano@sophia.inria.fr>
;; Version: 1.7n
;; Keywords: convenience
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;; Flyspell is a minor Emacs mode performing on-the-fly spelling
;; checking.
;;
;; To enable Flyspell minor mode, type M-x flyspell-mode.
;; This applies only to the current buffer.
;;
;; To enable Flyspell in text representing computer programs, type
;; M-x flyspell-prog-mode.
;; In that mode only text inside comments is checked.
;;
;; Note: consider setting the variable ispell-parser to `tex' to
;; avoid TeX command checking; use `(setq ispell-parser 'tex)'.
;;
;; Some user variables control the behavior of flyspell. They are
;; those defined under the `User variables' comment.
;;; Code:
(require 'ispell)
;*---------------------------------------------------------------------*/
;* Group ... */
;*---------------------------------------------------------------------*/
(defgroup flyspell nil
"Spell checking on the fly."
:tag "FlySpell"
:prefix "flyspell-"
:group 'ispell
:group 'processes)
;*---------------------------------------------------------------------*/
;* Which emacs are we currently running */
;*---------------------------------------------------------------------*/
(defvar flyspell-emacs
(cond
((string-match "XEmacs" emacs-version)
'xemacs)
(t
'emacs))
"The type of Emacs we are currently running.")
(defvar flyspell-use-local-map
(or (eq flyspell-emacs 'xemacs)
(not (string< emacs-version "20"))))
;*---------------------------------------------------------------------*/
;* User configuration ... */
;*---------------------------------------------------------------------*/
(defcustom flyspell-highlight-flag t
"*How Flyspell should indicate misspelled words.
Non-nil means use highlight, nil means use minibuffer messages."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-mark-duplications-flag t
"*Non-nil means Flyspell reports a repeated word as an error."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-sort-corrections nil
"*Non-nil means, sort the corrections alphabetically before popping them."
:group 'flyspell
:version "21.1"
:type 'boolean)
(defcustom flyspell-duplicate-distance -1
"*The maximum distance for finding duplicates of unrecognized words.
This applies to the feature that when a word is not found in the dictionary,
if the same spelling occurs elsewhere in the buffer,
Flyspell uses a different face (`flyspell-duplicate-face') to highlight it.
This variable specifies how far to search to find such a duplicate.
-1 means no limit (search the whole buffer).
0 means do not search for duplicate unrecognized spellings."
:group 'flyspell
:version "21.1"
:type 'number)
(defcustom flyspell-delay 3
"*The number of seconds to wait before checking, after a \"delayed\" command."
:group 'flyspell
:type 'number)
(defcustom flyspell-persistent-highlight t
"*Non-nil means misspelled words remain highlighted until corrected.
If this variable is nil, only the most recently detected misspelled word
is highlighted."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-highlight-properties t
"*Non-nil means highlight incorrect words even if a property exists for this word."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-default-delayed-commands
'(self-insert-command
delete-backward-char
backward-or-forward-delete-char
delete-char
scrollbar-vertical-drag
backward-delete-char-untabify)
"The standard list of delayed commands for Flyspell.
See `flyspell-delayed-commands'."
:group 'flyspell
:version "21.1"
:type '(repeat (symbol)))
(defcustom flyspell-delayed-commands nil
"List of commands that are \"delayed\" for Flyspell mode.
After these commands, Flyspell checking is delayed for a short time,
whose length is specified by `flyspell-delay'."
:group 'flyspell
:type '(repeat (symbol)))
(defcustom flyspell-default-deplacement-commands
'(next-line
previous-line
scroll-up
scroll-down)
"The standard list of deplacement commands for Flyspell.
See `flyspell-deplacement-commands'."
:group 'flyspell
:version "21.1"
:type '(repeat (symbol)))
(defcustom flyspell-default-ignored-commands
'(fill-paragraph)
"The standard list of ignored commands for Flyspell.
See `flyspell-delayed-commands'."
:group 'flyspell
:version "21.3"
:type '(repeat (symbol)))
(defcustom flyspell-ignored-commands nil
"List of commands that are \"ignored\" for Flyspell mode.
The changes in the text made by these commands are ignored. This list is meant for commands that change text in a way that does not affect individual words, such as `fill-paragraph'."
:group 'flyspell
:version "21.3"
:type '(repeat (symbol)))
(defcustom flyspell-deplacement-commands nil
"List of commands that are \"deplacement\" for Flyspell mode.
After these commands, Flyspell checking is performed only if the previous
command was not the very same command."
:group 'flyspell
:version "21.1"
:type '(repeat (symbol)))
(defcustom flyspell-issue-welcome-flag t
"*Non-nil means that Flyspell should display a welcome message when started."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-issue-message-flag t
"*Non-nil means that Flyspell emits messages when checking words."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-incorrect-hook nil
"*List of functions to be called when incorrect words are encountered.
Each function is given three arguments: the beginning and the end
of the incorrect region. The third is either the symbol 'doublon' or the list
of possible corrections as returned by 'ispell-parse-output'.
If any of the functions return non-Nil, the word is not highlighted as
incorrect."
:group 'flyspell
:version "21.1"
:type 'hook)
(defcustom flyspell-default-dictionary nil
"A string that is the name of the default dictionary.
This is passed to the `ispell-change-dictionary' when flyspell is started.
If the variable `ispell-local-dictionary' or `ispell-dictionary' is non-nil
when flyspell is started, the value of that variable is used instead
of `flyspell-default-dictionary' to select the default dictionary.
Otherwise, if `flyspell-default-dictionary' is nil, it means to use
Ispell's ultimate default dictionary."
:group 'flyspell
:version "21.1"
:type '(choice string (const :tag "Default" nil)))
(defcustom flyspell-tex-command-regexp
"\\(\\(begin\\|end\\)[ \t]*{\\|\\(cite[a-z*]*\\|label\\|ref\\|eqref\\|usepackage\\|documentclass\\)[ \t]*\\(\\[[^]]*\\]\\)?{[^{}]*\\)"
"A string that is the regular expression that matches TeX commands."
:group 'flyspell
:version "21.1"
:type 'string)
(defcustom flyspell-check-tex-math-command nil
"*Non nil means check even inside TeX math environment.
TeX math environments are discovered by the TEXMATHP that implemented
inside the texmathp.el Emacs package. That package may be found at:
http://strw.leidenuniv.nl/~dominik/Tools"
:group 'flyspell
:type 'boolean)
(defcustom flyspell-dictionaries-that-consider-dash-as-word-delimiter
'("francais" "deutsch8" "norsk")
"List of dictionary names that consider `-' as word delimiter."
:group 'flyspell
:version "21.1"
:type '(repeat (string)))
(defcustom flyspell-abbrev-p
nil
"*If non-nil, add correction to abbreviation table."
:group 'flyspell
:version "21.1"
:type 'boolean)
(defcustom flyspell-use-global-abbrev-table-p
nil
"*If non-nil, prefer global abbrev table to local abbrev table."
:group 'flyspell
:version "21.1"
:type 'boolean)
;;;###autoload
(defcustom flyspell-mode-line-string " Fly"
"*String displayed on the modeline when flyspell is active.
Set this to nil if you don't want a modeline indicator."
:group 'flyspell
:type '(choice string (const :tag "None" nil)))
(defcustom flyspell-large-region 1000
"*The threshold that determines if a region is small.
The `flyspell-region' function is invoked if the region is small, the
word are checked one after the other using regular flyspell check
means. If the region is large, a new Ispell process is spawned to get
speed.
if flyspell-large-region is nil, regions are treated as small."
:group 'flyspell
:version "21.1"
:type '(choice number boolean))
(defcustom flyspell-insert-function (function insert)
"*Function for inserting word by flyspell upon correction."
:group 'flyspell
:type 'function)
(defcustom flyspell-before-incorrect-word-string nil
"String used to indicate an incorrect word starting."
:group 'flyspell
:type '(choice string (const nil)))
(defcustom flyspell-after-incorrect-word-string nil
"String used to indicate an incorrect word ending."
:group 'flyspell
:type '(choice string (const nil)))
(defcustom flyspell-use-meta-tab t
"*Non-nil means that flyspell uses META-TAB to correct word."
:group 'flyspell
:type 'boolean)
(defcustom flyspell-auto-correct-binding
(cond
((eq flyspell-emacs 'xemacs)
[(control \;)])
(t
[?\C-\;]))
"The key binding for flyspell auto correction."
:group 'flyspell)
;*---------------------------------------------------------------------*/
;* Mode specific options */
;* ------------------------------------------------------------- */
;* Mode specific options enable users to disable flyspell on */
;* certain word depending of the emacs mode. For instance, when */
;* using flyspell with mail-mode add the following expression */
;* in your .emacs file: */
;* (add-hook 'mail-mode */
;* '(lambda () (setq flyspell-generic-check-word-p */
;* 'mail-mode-flyspell-verify))) */
;*---------------------------------------------------------------------*/
(defvar flyspell-generic-check-word-p nil
"Function providing per-mode customization over which words are flyspelled.
Returns t to continue checking, nil otherwise.
Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate'
property of the major mode name.")
(make-variable-buffer-local 'flyspell-generic-check-word-p)
;*--- mail mode -------------------------------------------------------*/
(put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
(put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
(defun mail-mode-flyspell-verify ()
"This function is used for `flyspell-generic-check-word-p' in Mail mode."
(let ((header-end (save-excursion
(goto-char (point-min))
(re-search-forward
(concat "^"
(regexp-quote mail-header-separator)
"$")
nil t)
(point)))
(signature-begin (save-excursion
(goto-char (point-max))
(re-search-backward message-signature-separator
nil t)
(point))))
(cond ((< (point) header-end)
(and (save-excursion (beginning-of-line)
(looking-at "^Subject:"))
(> (point) (match-end 0))))
((> (point) signature-begin)
nil)
(t
(save-excursion
(beginning-of-line)
(not (looking-at "[>}|]\\|To:")))))))
;*--- texinfo mode ----------------------------------------------------*/
(put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify)
(defun texinfo-mode-flyspell-verify ()
"This function is used for `flyspell-generic-check-word-p' in Texinfo mode."
(save-excursion
(forward-word -1)
(not (looking-at "@"))))
;*--- tex mode --------------------------------------------------------*/
(put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify)
(defun tex-mode-flyspell-verify ()
"This function is used for `flyspell-generic-check-word-p' in LaTeX mode."
(and
(not (save-excursion
(re-search-backward "^[ \t]*%%%[ \t]+Local" (point-min) t)))
(not (save-excursion
(let ((this (point-marker))
(e (progn (end-of-line) (point-marker))))
(beginning-of-line)
(if (re-search-forward "\\\\\\(cite\\|label\\|ref\\){[^}]*}" e t)
(and (>= this (match-beginning 0))
(<= this (match-end 0)) )))))))
;*--- sgml mode -------------------------------------------------------*/
(put 'sgml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
(put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)
(defun sgml-mode-flyspell-verify ()
"This function is used for `flyspell-generic-check-word-p' in SGML mode."
(not (save-excursion
(let ((this (point-marker))
(s (progn (beginning-of-line) (point-marker)))
(e (progn (end-of-line) (point-marker))))
(or (progn
(goto-char this)
(and (re-search-forward "[^<]*>" e t)
(= (match-beginning 0) this)))
(progn
(goto-char this)
(and (re-search-backward "<[^>]*" s t)
(= (match-end 0) this)))
(and (progn
(goto-char this)
(and (re-search-forward "[^&]*;" e t)
(= (match-beginning 0) this)))
(progn
(goto-char this)
(and (re-search-backward "&[^;]*" s t)
(= (match-end 0) this)))))))))
;*---------------------------------------------------------------------*/
;* Programming mode */
;*---------------------------------------------------------------------*/
(defvar flyspell-prog-text-faces
'(font-lock-string-face font-lock-comment-face font-lock-doc-face)
"Faces corresponding to text in programming-mode buffers.")
(defun flyspell-generic-progmode-verify ()
"Used for `flyspell-generic-check-word-p' in programming modes."
(let ((f (get-text-property (point) 'face)))
(memq f flyspell-prog-text-faces)))
;;;###autoload
(defun flyspell-prog-mode ()
"Turn on `flyspell-mode' for comments and strings."
(interactive)
(setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify)
(flyspell-mode 1)
(run-hooks 'flyspell-prog-mode-hook))
;*---------------------------------------------------------------------*/
;* Overlay compatibility */
;*---------------------------------------------------------------------*/
(autoload 'make-overlay "overlay" "Overlay compatibility kit." t)
(autoload 'overlayp "overlay" "Overlay compatibility kit." t)
(autoload 'overlays-in "overlay" "Overlay compatibility kit." t)
(autoload 'delete-overlay "overlay" "Overlay compatibility kit." t)
(autoload 'overlays-at "overlay" "Overlay compatibility kit." t)
(autoload 'overlay-put "overlay" "Overlay compatibility kit." t)
(autoload 'overlay-get "overlay" "Overlay compatibility kit." t)
(autoload 'previous-overlay-change "overlay" "Overlay compatibility kit." t)
;*---------------------------------------------------------------------*/
;* The minor mode declaration. */
;*---------------------------------------------------------------------*/
(eval-when-compile (defvar flyspell-local-mouse-map))
;;;###autoload
(defvar flyspell-mode nil)
(make-variable-buffer-local 'flyspell-mode)
(defvar flyspell-mouse-map
(let ((map (make-sparse-keymap)))
(if flyspell-use-meta-tab
(define-key map "\M-\t" #'flyspell-auto-correct-word))
(define-key map (if (featurep 'xemacs) [button2] [down-mouse-2])
#'flyspell-correct-word)
(if (not (featurep 'xemacs))
(define-key map [(shift down-mouse-2)] #'flyspell-correct-word))
(define-key map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
(define-key map [(control \,)] 'flyspell-goto-next-error)
(define-key map [(control \.)] 'flyspell-auto-correct-word)
map))
;;;###autoload
(defvar flyspell-mode-map (make-sparse-keymap))
;; mouse, keyboard bindings and misc definition
(when (or (assoc 'flyspell-mode minor-mode-map-alist)
(setq minor-mode-map-alist
(cons (cons 'flyspell-mode flyspell-mode-map)
minor-mode-map-alist)))
(if flyspell-use-meta-tab
(define-key flyspell-mode-map "\M-\t" 'flyspell-auto-correct-word))
(cond
((eq flyspell-emacs 'xemacs)
(define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
(define-key flyspell-mode-map [(control \,)] 'flyspell-goto-next-error)
(define-key flyspell-mode-map [(control \.)] 'flyspell-auto-correct-word))
(flyspell-use-local-map
(define-key flyspell-mode-map flyspell-auto-correct-binding 'flyspell-auto-correct-previous-word)
(define-key flyspell-mode-map [?\C-\,] 'flyspell-goto-next-error)
(define-key flyspell-mode-map [?\C-\.] 'flyspell-auto-correct-word))))
;; the name of the overlay property that defines the keymap
(defvar flyspell-overlay-keymap-property-name 'keymap)
;; dash character machinery
(defvar flyspell-consider-dash-as-word-delimiter-flag nil
"*Non-nil means that the `-' char is considered as a word delimiter.")
(make-variable-buffer-local 'flyspell-consider-dash-as-word-delimiter-flag)
(defvar flyspell-dash-dictionary nil)
(make-variable-buffer-local 'flyspell-dash-dictionary)
(defvar flyspell-dash-local-dictionary nil)
(make-variable-buffer-local 'flyspell-dash-local-dictionary)
;*---------------------------------------------------------------------*/
;* Highlighting */
;*---------------------------------------------------------------------*/
(defface flyspell-incorrect-face
(if (eq flyspell-emacs 'xemacs)
'((((class color)) (:foreground "OrangeRed" :bold t :underline t))
(t (:bold t)))
'((((class color)) (:foreground "OrangeRed" :weight bold :underline t))
(t (:weight bold))))
"Face used for marking a misspelled word in Flyspell."
:group 'flyspell)
(defface flyspell-duplicate-face
(if (eq flyspell-emacs 'xemacs)
'((((class color)) (:foreground "Gold3" :bold t :underline t))
(t (:bold t)))
'((((class color)) (:foreground "Gold3" :weight bold :underline t))
(t (:weight bold))))
"Face used for marking a misspelled word that appears twice in the buffer.
See also `flyspell-duplicate-distance'."
:group 'flyspell)
(defvar flyspell-overlay nil)
;*---------------------------------------------------------------------*/
;* flyspell-mode ... */
;*---------------------------------------------------------------------*/
;;;###autoload
(defun flyspell-mode (&optional arg)
"Minor mode performing on-the-fly spelling checking.
Ispell is automatically spawned on background for each entered words.
The default flyspell behavior is to highlight incorrect words.
With no argument, this command toggles Flyspell mode.
With a prefix argument ARG, turn Flyspell minor mode on iff ARG is positive.
Bindings:
\\[ispell-word]: correct words (using Ispell).
\\[flyspell-auto-correct-word]: automatically correct word.
\\[flyspell-auto-correct-previous-word]: automatically correct the last misspelled word.
\\[flyspell-correct-word] (or down-mouse-2): popup correct words.
Hooks:
This runs `flyspell-mode-hook' after flyspell is entered.
Remark:
`flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
valid. For instance, a personal dictionary can be used by
invoking `ispell-change-dictionary'.
Consider using the `ispell-parser' to check your text. For instance
consider adding:
\(add-hook 'tex-mode-hook (function (lambda () (setq ispell-parser 'tex))))
in your .emacs file.
\\[flyspell-region] checks all words inside a region.
\\[flyspell-buffer] checks the whole buffer."
(interactive "P")
(let ((old-flyspell-mode flyspell-mode))
;; Mark the mode as on or off.
(setq flyspell-mode (not (or (and (null arg) flyspell-mode)
(<= (prefix-numeric-value arg) 0))))
;; Do the real work.
(unless (eq flyspell-mode old-flyspell-mode)
(if flyspell-mode
(flyspell-mode-on)
(flyspell-mode-off))
;; Force modeline redisplay.
(set-buffer-modified-p (buffer-modified-p)))))
;*---------------------------------------------------------------------*/
;* Autoloading */
;*---------------------------------------------------------------------*/
;;;###autoload
(if (fboundp 'add-minor-mode)
(add-minor-mode 'flyspell-mode
'flyspell-mode-line-string
flyspell-mode-map
nil
'flyspell-mode)
(or (assoc 'flyspell-mode minor-mode-alist)
(setq minor-mode-alist
(cons '(flyspell-mode flyspell-mode-line-string)
minor-mode-alist)))
(or (assoc 'flyspell-mode minor-mode-map-alist)
(setq minor-mode-map-alist
(cons (cons 'flyspell-mode flyspell-mode-map)
minor-mode-map-alist))))
;*---------------------------------------------------------------------*/
;* flyspell-buffers ... */
;* ------------------------------------------------------------- */
;* For remembering buffers running flyspell */
;*---------------------------------------------------------------------*/
(defvar flyspell-buffers nil)
;*---------------------------------------------------------------------*/
;* flyspell-minibuffer-p ... */
;*---------------------------------------------------------------------*/
(defun flyspell-minibuffer-p (buffer)
"Is BUFFER a minibuffer?"
(let ((ws (get-buffer-window-list buffer t)))
(and (consp ws) (window-minibuffer-p (car ws)))))
;*---------------------------------------------------------------------*/
;* flyspell-version ... */
;*---------------------------------------------------------------------*/
;;;###autoload
(defun flyspell-version ()
"The flyspell version"
(interactive)
"1.7n")
;*---------------------------------------------------------------------*/
;* flyspell-accept-buffer-local-defs ... */
;*---------------------------------------------------------------------*/
(defun flyspell-accept-buffer-local-defs ()
;; strange problem. If buffer in current window has font-lock turned on,
;; but SET-BUFFER was called to point to an invisible buffer, this ispell
;; call will reset the buffer to the buffer in the current window. However,
;; it only happens at startup (fix by Albert L. Ting).
(let ((buf (current-buffer)))
(ispell-accept-buffer-local-defs)
(set-buffer buf))
(if (not (and (eq flyspell-dash-dictionary ispell-dictionary)
(eq flyspell-dash-local-dictionary ispell-local-dictionary)))
;; the dictionary has changed
(progn
(setq flyspell-dash-dictionary ispell-dictionary)
(setq flyspell-dash-local-dictionary ispell-local-dictionary)
(if (member (or ispell-local-dictionary ispell-dictionary)
flyspell-dictionaries-that-consider-dash-as-word-delimiter)
(setq flyspell-consider-dash-as-word-delimiter-flag t)
(setq flyspell-consider-dash-as-word-delimiter-flag nil)))))
;*---------------------------------------------------------------------*/
;* flyspell-mode-on ... */
;*---------------------------------------------------------------------*/
(defun flyspell-mode-on ()
"Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead."
(setq ispell-highlight-face 'flyspell-incorrect-face)
;; local dictionaries setup
(ispell-change-dictionary
(or ispell-local-dictionary ispell-dictionary flyspell-default-dictionary))
;; we have to force ispell to accept the local definition or
;; otherwise it could be too late, the local dictionary may
;; be forgotten!
(flyspell-accept-buffer-local-defs)
;; we put the `flyspell-delayed' property on some commands
(flyspell-delay-commands)
;; we put the `flyspell-deplacement' property on some commands
(flyspell-deplacement-commands)
;; we put the `flyspell-ignored' property on some commands
(flyspell-ignore-commands)
;; we bound flyspell action to post-command hook
(if (eq flyspell-emacs 'xemacs)
(make-local-hook 'post-command-hook))
(add-hook 'post-command-hook (function flyspell-post-command-hook) t t)
;; we bound flyspell action to pre-command hook
(if (eq flyspell-emacs 'xemacs)
(make-local-hook 'pre-command-hook))
(add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t)
;; we bound flyspell action to after-change hook
(make-local-variable 'after-change-functions)
(setq after-change-functions
(cons 'flyspell-after-change-function after-change-functions))
;; set flyspell-generic-check-word-p based on the major mode
(let ((mode-predicate (get major-mode 'flyspell-mode-predicate)))
(if mode-predicate
(setq flyspell-generic-check-word-p mode-predicate)))
;; work around the fact that the `local-map' text-property replaces the
;; buffer's local map rather than shadowing it.
(set (make-local-variable 'flyspell-mouse-map)
(let ((map (copy-keymap flyspell-mouse-map)))
(set-keymap-parent map (current-local-map))
(if (and (eq flyspell-emacs 'emacs)
(not (string< emacs-version "20")))
(define-key map '[tool-bar] nil))
map))
(set (make-local-variable 'flyspell-mode-map)
(let ((map (copy-keymap flyspell-mode-map)))
(set-keymap-parent map (current-local-map))
(if (and (eq flyspell-emacs 'emacs)
(not (string< emacs-version "20")))
(define-key map '[tool-bar] nil))
map))
;; the welcome message
(if (and flyspell-issue-message-flag
flyspell-issue-welcome-flag
(interactive-p))
(let ((binding (where-is-internal 'flyspell-auto-correct-word
nil 'non-ascii)))
(message
(if binding
(format "Welcome to flyspell. Use %s or Mouse-2 to correct words."
(key-description binding))
"Welcome to flyspell. Use Mouse-2 to correct words."))))
;; we end with the flyspell hooks
(run-hooks 'flyspell-mode-hook))
;*---------------------------------------------------------------------*/
;* flyspell-delay-commands ... */
;*---------------------------------------------------------------------*/
(defun flyspell-delay-commands ()
"Install the standard set of Flyspell delayed commands."
(mapcar 'flyspell-delay-command flyspell-default-delayed-commands)
(mapcar 'flyspell-delay-command flyspell-delayed-commands))
;*---------------------------------------------------------------------*/
;* flyspell-delay-command ... */
;*---------------------------------------------------------------------*/
(defun flyspell-delay-command (command)
"Set COMMAND to be delayed, for Flyspell.
When flyspell `post-command-hook' is invoked because a delayed command
as been used the current word is not immediately checked.
It will be checked only after `flyspell-delay' seconds."
(interactive "SDelay Flyspell after Command: ")
(put command 'flyspell-delayed t))
;*---------------------------------------------------------------------*/
;* flyspell-deplacement-commands ... */
;*---------------------------------------------------------------------*/
(defun flyspell-deplacement-commands ()
"Install the standard set of Flyspell deplacement commands."
(mapcar 'flyspell-deplacement-command flyspell-default-deplacement-commands)
(mapcar 'flyspell-deplacement-command flyspell-deplacement-commands))
;*---------------------------------------------------------------------*/
;* flyspell-deplacement-command ... */
;*---------------------------------------------------------------------*/
(defun flyspell-deplacement-command (command)
"Set COMMAND that implement cursor movements, for Flyspell.
When flyspell `post-command-hook' is invoked because of a deplacement command
as been used the current word is checked only if the previous command was
not the very same deplacement command."
(interactive "SDeplacement Flyspell after Command: ")
(put command 'flyspell-deplacement t))
;*---------------------------------------------------------------------*/
;* flyspell-ignore-commands ... */
;*---------------------------------------------------------------------*/
(defun flyspell-ignore-commands ()
"Install the standard set of Flyspell ignored commands."
(mapcar 'flyspell-ignore-command flyspell-default-ignored-commands)
(mapcar 'flyspell-ignore-command flyspell-ignored-commands))
;*---------------------------------------------------------------------*/
;* flyspell-ignore-command ... */
;*---------------------------------------------------------------------*/
(defun flyspell-ignore-command (command)
"Set COMMAND to be ignored, for Flyspell.
When flyspell `post-command-hook' is invoked because of an
ignored command having been used, the changes in the text made by
that command are ignored. This feature is meant for commands that
change text in a way that does not affect individual words, such
as `fill-paragraph'."
(interactive "SMake Flyspell ignore changes made by Command: ")
(put command 'flyspell-ignored t))
;*---------------------------------------------------------------------*/
;* flyspell-word-cache ... */
;*---------------------------------------------------------------------*/
(defvar flyspell-word-cache-start nil)
(defvar flyspell-word-cache-end nil)
(defvar flyspell-word-cache-word nil)
(defvar flyspell-word-cache-result '_)
(make-variable-buffer-local 'flyspell-word-cache-start)
(make-variable-buffer-local 'flyspell-word-cache-end)
(make-variable-buffer-local 'flyspell-word-cache-word)
(make-variable-buffer-local 'flyspell-word-cache-result)
;*---------------------------------------------------------------------*/
;* The flyspell pre-hook, store the current position. In the */
;* post command hook, we will check, if the word at this position */
;* has to be spell checked. */
;*---------------------------------------------------------------------*/
(defvar flyspell-pre-buffer nil)
(defvar flyspell-pre-point nil)
(defvar flyspell-pre-column nil)
(defvar flyspell-pre-pre-buffer nil)
(defvar flyspell-pre-pre-point nil)
;*---------------------------------------------------------------------*/
;* flyspell-previous-command ... */
;*---------------------------------------------------------------------*/
(defvar flyspell-previous-command nil
"The last interactive command checked by Flyspell.")
;*---------------------------------------------------------------------*/
;* flyspell-pre-command-hook ... */
;*---------------------------------------------------------------------*/
(defun flyspell-pre-command-hook ()
"Save the current buffer and point for Flyspell's post-command hook."
(interactive)
(setq flyspell-pre-buffer (current-buffer))
(setq flyspell-pre-point (point))
(setq flyspell-pre-column (current-column)))
;*---------------------------------------------------------------------*/
;* flyspell-mode-off ... */
;*---------------------------------------------------------------------*/
;;;###autoload
(defun flyspell-mode-off ()
"Turn Flyspell mode off."
;; we remove the hooks
(remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
(remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
(setq after-change-functions (delq 'flyspell-after-change-function
after-change-functions))
;; we remove all the flyspell hilightings
(flyspell-delete-all-overlays)
;; we have to erase pre cache variables
(setq flyspell-pre-buffer nil)
(setq flyspell-pre-point nil)
;; we mark the mode as killed
(setq flyspell-mode nil))
;*---------------------------------------------------------------------*/
;* flyspell-check-pre-word-p ... */
;*---------------------------------------------------------------------*/
(defun flyspell-check-pre-word-p ()
"Return non-nil if we should check the word before point.
More precisely, it applies to the word that was before point
before the current command."
(cond
((or (not (numberp flyspell-pre-point))
(not (bufferp flyspell-pre-buffer))
(not (buffer-live-p flyspell-pre-buffer)))
nil)
((and (eq flyspell-pre-pre-point flyspell-pre-point)
(eq flyspell-pre-pre-buffer flyspell-pre-buffer))
nil)
((or (and (= flyspell-pre-point (- (point) 1))
(eq (char-syntax (char-after flyspell-pre-point)) ?w))
(= flyspell-pre-point (point))
(= flyspell-pre-point (+ (point) 1)))
nil)
((and (symbolp this-command)
(not executing-kbd-macro)
(or (get this-command 'flyspell-delayed)
(and (get this-command 'flyspell-deplacement)
(eq flyspell-previous-command this-command)))
(or (= (current-column) 0)
(= (current-column) flyspell-pre-column)
(eq (char-syntax (char-after flyspell-pre-point)) ?w)))
nil)
((not (eq (current-buffer) flyspell-pre-buffer))
t)
((not (and (numberp flyspell-word-cache-start)
(numberp flyspell-word-cache-end)))
t)
(t
(or (< flyspell-pre-point flyspell-word-cache-start)
(> flyspell-pre-point flyspell-word-cache-end)))))
;*---------------------------------------------------------------------*/
;* The flyspell after-change-hook, store the change position. In */
;* the post command hook, we will check, if the word at this */
;* position has to be spell checked. */
;*---------------------------------------------------------------------*/
(defvar flyspell-changes nil)
;*---------------------------------------------------------------------*/
;* flyspell-after-change-function ... */
;*---------------------------------------------------------------------*/
(defun flyspell-after-change-function (start stop len)
"Save the current buffer and point for Flyspell's post-command hook."
(interactive)
(unless (and (symbolp this-command) (get this-command 'flyspell-ignored))
(setq flyspell-changes (cons (cons start stop) flyspell-changes))))
;*---------------------------------------------------------------------*/
;* flyspell-check-changed-word-p ... */
;*---------------------------------------------------------------------*/
(defun flyspell-check-changed-word-p (start stop)
"Return t when the changed word has to be checked.
The answer depends of several criteria.
Mostly we check word delimiters."
(cond
((and (memq (char-after start) '(?\n ? )) (> stop start))
t)
((not (numberp flyspell-pre-point))
t)
((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
nil)
((let ((pos (point)))
(or (>= pos start) (<= pos stop) (= pos (1+ stop))))
nil)
(t
t)))
;*---------------------------------------------------------------------*/
;* flyspell-check-word-p ... */
;*---------------------------------------------------------------------*/
(defun flyspell-check-word-p ()
"Return t when the word at `point' has to be checked.
The answer depends of several criteria.
Mostly we check word delimiters."
(cond
((<= (- (point-max) 1) (point-min))
;; the buffer is not filled enough
nil)
((and (and (> (current-column) 0)
(not (eq (current-column) flyspell-pre-column)))
(save-excursion
(backward-char 1)
(and (looking-at (flyspell-get-not-casechars))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-"))))))
;; yes because we have reached or typed a word delimiter.
t)
((symbolp this-command)
(cond
((get this-command 'flyspell-deplacement)
(not (eq flyspell-previous-command this-command)))
((get this-command 'flyspell-delayed)
;; the current command is not delayed, that
;; is that we must check the word now
(if (or (fboundp 'about-xemacs) (featurep 'xemacs))
(sit-for flyspell-delay nil)
(sit-for flyspell-delay 0 nil)))
(t t)))
(t t)))
;*---------------------------------------------------------------------*/
;* flyspell-debug-signal-no-check ... */
;*---------------------------------------------------------------------*/
(defun flyspell-debug-signal-no-check (msg obj)
(setq debug-on-error t)
(save-excursion
(let ((buffer (get-buffer-create "*flyspell-debug*")))
(set-buffer buffer)
(erase-buffer)
(insert "NO-CHECK:\n")
(insert (format " %S : %S\n" msg obj)))))
;*---------------------------------------------------------------------*/
;* flyspell-debug-signal-pre-word-checked ... */
;*---------------------------------------------------------------------*/
(defun flyspell-debug-signal-pre-word-checked ()
(setq debug-on-error t)
(save-excursion
(let ((buffer (get-buffer-create "*flyspell-debug*")))
(set-buffer buffer)
(insert "PRE-WORD:\n")
(insert (format " pre-point : %S\n" flyspell-pre-point))
(insert (format " pre-buffer : %S\n" flyspell-pre-buffer))
(insert (format " cache-start: %S\n" flyspell-word-cache-start))
(insert (format " cache-end : %S\n" flyspell-word-cache-end))
(goto-char (point-max)))))
;*---------------------------------------------------------------------*/
;* flyspell-debug-signal-word-checked ... */
;*---------------------------------------------------------------------*/
(defun flyspell-debug-signal-word-checked ()
(setq debug-on-error t)
(save-excursion
(let ((oldbuf (current-buffer))
(buffer (get-buffer-create "*flyspell-debug*"))
(point (point)))
(set-buffer buffer)
(insert "WORD:\n")
(insert (format " this-cmd : %S\n" this-command))
(insert (format " delayed : %S\n" (and (symbolp this-command)
(get this-command 'flyspell-delayed))))
(insert (format " ignored : %S\n" (and (symbolp this-command)
(get this-command 'flyspell-ignored))))
(insert (format " point : %S\n" point))
(insert (format " prev-char : [%c] %S\n"
(progn
(set-buffer oldbuf)
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(char-after (point)))
? )))
(set-buffer buffer)
c))
(progn
(set-buffer oldbuf)
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(and (and (looking-at (flyspell-get-not-casechars)) 1)
(and (or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-"))) 2))))))
(set-buffer buffer)
c))))
(insert (format " because : %S\n"
(cond
((not (and (symbolp this-command)
(get this-command 'flyspell-delayed)))
;; the current command is not delayed, that
;; is that we must check the word now
'not-delayed)
((progn
(set-buffer oldbuf)
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(and (looking-at (flyspell-get-not-casechars))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-"))))))))
(set-buffer buffer)
c))
;; yes because we have reached or typed a word delimiter.
'separator)
((not (integerp flyspell-delay))
;; yes because the user had set up a no-delay configuration.
'no-delay)
(t
'sit-for))))
(goto-char (point-max)))))
;*---------------------------------------------------------------------*/
;* flyspell-debug-signal-changed-checked ... */
;*---------------------------------------------------------------------*/
(defun flyspell-debug-signal-changed-checked ()
(setq debug-on-error t)
(save-excursion
(let ((buffer (get-buffer-create "*flyspell-debug*"))
(point (point)))
(set-buffer buffer)