diff options
| author | Pavel Janík | 2002-02-02 15:56:45 +0000 |
|---|---|---|
| committer | Pavel Janík | 2002-02-02 15:56:45 +0000 |
| commit | 73194d6771a7eeb9e4022573131f7fdc573ec9c5 (patch) | |
| tree | 84375225759aa69a0c2c7efcda5ab71cb6cc07f8 | |
| parent | 901cd78b4a765c231f39a30ed930f6c6ac0c3b19 (diff) | |
| download | emacs-73194d6771a7eeb9e4022573131f7fdc573ec9c5.tar.gz emacs-73194d6771a7eeb9e4022573131f7fdc573ec9c5.zip | |
(flyspell-issue-message-flag): New user option.
(flyspell-mode-on, flyspell-notify-misspell)
(flyspell-small-region, flyspell-external-point-words)
(flyspell-large-region): Use it
(flyspell-before-incorrect-word-string)
(flyspell-after-incorrect-word-string): New user options.
(make-flyspell-overlay): Use them.
(flyspell-version): New function.
(flyspell-incorrect-face, flyspell-duplicate-face): Adapt face definitions
to use :weight.
(flyspell-insert-function): New user option.
(flyspell-auto-correct-word, flyspell-correct-word)
(flyspell-xemacs-correct): Use it.
(flyspell-define-abbrev): New function.
(flyspell-auto-correct-word, flyspell-correct-word)
(flyspell-xemacs-correct): Use it.
(make-flyspell-overlay): Use `evaporate' property.
(flyspell-auto-correct-word, flyspell-correct-word): Remove overlay.
(flyspell-emacs-popup): Use `session' instead of `accept'.
(flyspell-auto-correct-previous-pos): New variable.
(flyspell-auto-correct-previous-hook)
(flyspell-auto-correct-previous-word): New functions.
| -rw-r--r-- | lisp/textmodes/flyspell.el | 185 |
1 files changed, 149 insertions, 36 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index de303b7f0d8..1ff42279636 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; flyspell.el --- on-the-fly spell checker | 1 | ;;; flyspell.el --- on-the-fly spell checker |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998, 2000, 2001, 2002 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Manuel Serrano <Manuel.Serrano@unice.fr> | 5 | ;; Author: Manuel Serrano <Manuel.Serrano@unice.fr> |
| 6 | ;; Keywords: convenience | 6 | ;; Keywords: convenience |
| @@ -145,6 +145,11 @@ command was not the very same command." | |||
| 145 | :group 'flyspell | 145 | :group 'flyspell |
| 146 | :type 'boolean) | 146 | :type 'boolean) |
| 147 | 147 | ||
| 148 | (defcustom flyspell-issue-message-flag t | ||
| 149 | "*Non-nil means that Flyspell emits messages when checking words." | ||
| 150 | :group 'flyspell | ||
| 151 | :type 'boolean) | ||
| 152 | |||
| 148 | (defcustom flyspell-incorrect-hook nil | 153 | (defcustom flyspell-incorrect-hook nil |
| 149 | "*List of functions to be called when incorrect words are encountered. | 154 | "*List of functions to be called when incorrect words are encountered. |
| 150 | Each function is given three arguments: the beginning and the end | 155 | Each function is given three arguments: the beginning and the end |
| @@ -222,6 +227,22 @@ speed." | |||
| 222 | :version "21.1" | 227 | :version "21.1" |
| 223 | :type 'number) | 228 | :type 'number) |
| 224 | 229 | ||
| 230 | (defcustom flyspell-insert-function (function insert) | ||
| 231 | "*The function to be used when a word has to be inserted by flyspell | ||
| 232 | upon correction." | ||
| 233 | :group 'flyspell | ||
| 234 | :type 'function) | ||
| 235 | |||
| 236 | (defcustom flyspell-before-incorrect-word-string nil | ||
| 237 | "String used to indicate an incorrect word starting." | ||
| 238 | :group 'flyspell | ||
| 239 | :type '(choice string (const nil))) | ||
| 240 | |||
| 241 | (defcustom flyspell-after-incorrect-word-string nil | ||
| 242 | "String used to indicate an incorrect word ending." | ||
| 243 | :group 'flyspell | ||
| 244 | :type '(choice string (const nil))) | ||
| 245 | |||
| 225 | ;*---------------------------------------------------------------------*/ | 246 | ;*---------------------------------------------------------------------*/ |
| 226 | ;* Mode specific options */ | 247 | ;* Mode specific options */ |
| 227 | ;* ------------------------------------------------------------- */ | 248 | ;* ------------------------------------------------------------- */ |
| @@ -359,6 +380,8 @@ property of the major mode name.") | |||
| 359 | ;*---------------------------------------------------------------------*/ | 380 | ;*---------------------------------------------------------------------*/ |
| 360 | ;* The minor mode declaration. */ | 381 | ;* The minor mode declaration. */ |
| 361 | ;*---------------------------------------------------------------------*/ | 382 | ;*---------------------------------------------------------------------*/ |
| 383 | (eval-when-compile (defvar flyspell-local-mouse-map)) | ||
| 384 | |||
| 362 | (defvar flyspell-mode nil) | 385 | (defvar flyspell-mode nil) |
| 363 | (make-variable-buffer-local 'flyspell-mode) | 386 | (make-variable-buffer-local 'flyspell-mode) |
| 364 | 387 | ||
| @@ -399,14 +422,20 @@ property of the major mode name.") | |||
| 399 | ;* Highlighting */ | 422 | ;* Highlighting */ |
| 400 | ;*---------------------------------------------------------------------*/ | 423 | ;*---------------------------------------------------------------------*/ |
| 401 | (defface flyspell-incorrect-face | 424 | (defface flyspell-incorrect-face |
| 402 | '((((class color)) (:foreground "OrangeRed" :weight bold :underline t)) | 425 | (if (eq flyspell-emacs 'xemacs) |
| 403 | (t (:weight bold))) | 426 | '((((class color)) (:foreground "OrangeRed" :bold t :underline t)) |
| 427 | (t (:bold t))) | ||
| 428 | '((((class color)) (:foreground "OrangeRed" :weight bold :underline t)) | ||
| 429 | (t (:weight bold)))) | ||
| 404 | "Face used for marking a misspelled word in Flyspell." | 430 | "Face used for marking a misspelled word in Flyspell." |
| 405 | :group 'flyspell) | 431 | :group 'flyspell) |
| 406 | 432 | ||
| 407 | (defface flyspell-duplicate-face | 433 | (defface flyspell-duplicate-face |
| 408 | '((((class color)) (:foreground "Gold3" :weight bold :underline t)) | 434 | (if (eq flyspell-emacs 'xemacs) |
| 409 | (t (:weight bold))) | 435 | '((((class color)) (:foreground "Gold3" :bold t :underline t)) |
| 436 | (t (:bold t))) | ||
| 437 | '((((class color)) (:foreground "Gold3" :weight bold :underline t)) | ||
| 438 | (t (:weight bold)))) | ||
| 410 | "Face used for marking a misspelled word that appears twice in the buffer. | 439 | "Face used for marking a misspelled word that appears twice in the buffer. |
| 411 | See also `flyspell-duplicate-distance'." | 440 | See also `flyspell-duplicate-distance'." |
| 412 | :group 'flyspell) | 441 | :group 'flyspell) |
| @@ -483,6 +512,15 @@ in your .emacs file. | |||
| 483 | (and (consp ws) (window-minibuffer-p (car ws))))) | 512 | (and (consp ws) (window-minibuffer-p (car ws))))) |
| 484 | 513 | ||
| 485 | ;*---------------------------------------------------------------------*/ | 514 | ;*---------------------------------------------------------------------*/ |
| 515 | ;* flyspell-version ... */ | ||
| 516 | ;*---------------------------------------------------------------------*/ | ||
| 517 | ;;;###autoload | ||
| 518 | (defun flyspell-version () | ||
| 519 | "The flyspell version" | ||
| 520 | (interactive) | ||
| 521 | "1.6h") | ||
| 522 | |||
| 523 | ;*---------------------------------------------------------------------*/ | ||
| 486 | ;* flyspell-accept-buffer-local-defs ... */ | 524 | ;* flyspell-accept-buffer-local-defs ... */ |
| 487 | ;*---------------------------------------------------------------------*/ | 525 | ;*---------------------------------------------------------------------*/ |
| 488 | (defun flyspell-accept-buffer-local-defs () | 526 | (defun flyspell-accept-buffer-local-defs () |
| @@ -501,8 +539,6 @@ in your .emacs file. | |||
| 501 | ;*---------------------------------------------------------------------*/ | 539 | ;*---------------------------------------------------------------------*/ |
| 502 | ;* flyspell-mode-on ... */ | 540 | ;* flyspell-mode-on ... */ |
| 503 | ;*---------------------------------------------------------------------*/ | 541 | ;*---------------------------------------------------------------------*/ |
| 504 | (eval-when-compile (defvar flyspell-local-mouse-map)) | ||
| 505 | |||
| 506 | (defun flyspell-mode-on () | 542 | (defun flyspell-mode-on () |
| 507 | "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." | 543 | "Turn Flyspell mode on. Do not use this; use `flyspell-mode' instead." |
| 508 | (setq ispell-highlight-face 'flyspell-incorrect-face) | 544 | (setq ispell-highlight-face 'flyspell-incorrect-face) |
| @@ -530,7 +566,9 @@ in your .emacs file. | |||
| 530 | (if mode-predicate | 566 | (if mode-predicate |
| 531 | (setq flyspell-generic-check-word-p mode-predicate))) | 567 | (setq flyspell-generic-check-word-p mode-predicate))) |
| 532 | ;; the welcome message | 568 | ;; the welcome message |
| 533 | (if (and flyspell-issue-welcome-flag (interactive-p)) | 569 | (if (and flyspell-issue-message-flag |
| 570 | flyspell-issue-welcome-flag | ||
| 571 | (interactive-p)) | ||
| 534 | (let ((binding (where-is-internal 'flyspell-auto-correct-word | 572 | (let ((binding (where-is-internal 'flyspell-auto-correct-word |
| 535 | nil 'non-ascii))) | 573 | nil 'non-ascii))) |
| 536 | (message | 574 | (message |
| @@ -538,7 +576,6 @@ in your .emacs file. | |||
| 538 | (format "Welcome to flyspell. Use %s or Mouse-2 to correct words." | 576 | (format "Welcome to flyspell. Use %s or Mouse-2 to correct words." |
| 539 | (key-description binding)) | 577 | (key-description binding)) |
| 540 | "Welcome to flyspell. Use Mouse-2 to correct words.")))) | 578 | "Welcome to flyspell. Use Mouse-2 to correct words.")))) |
| 541 | |||
| 542 | ;; we end with the flyspell hooks | 579 | ;; we end with the flyspell hooks |
| 543 | (run-hooks 'flyspell-mode-hook)) | 580 | (run-hooks 'flyspell-mode-hook)) |
| 544 | 581 | ||
| @@ -907,7 +944,8 @@ Mostly we check word delimiters." | |||
| 907 | (if flyspell-sort-corrections | 944 | (if flyspell-sort-corrections |
| 908 | (sort (car (cdr (cdr poss))) 'string<) | 945 | (sort (car (cdr (cdr poss))) 'string<) |
| 909 | (car (cdr (cdr poss))))))) | 946 | (car (cdr (cdr poss))))))) |
| 910 | (message (format "mispelling `%s' %S" word replacements)))) | 947 | (if flyspell-issue-message-flag |
| 948 | (message (format "mispelling `%s' %S" word replacements))))) | ||
| 911 | 949 | ||
| 912 | ;*---------------------------------------------------------------------*/ | 950 | ;*---------------------------------------------------------------------*/ |
| 913 | ;* flyspell-word ... */ | 951 | ;* flyspell-word ... */ |
| @@ -1206,7 +1244,7 @@ Word syntax described by `ispell-dictionary-alist' (which see)." | |||
| 1206 | (goto-char beg) | 1244 | (goto-char beg) |
| 1207 | (let ((count 0)) | 1245 | (let ((count 0)) |
| 1208 | (while (< (point) end) | 1246 | (while (< (point) end) |
| 1209 | (if (= count 100) | 1247 | (if (and flyspell-issue-message-flag (= count 100)) |
| 1210 | (progn | 1248 | (progn |
| 1211 | (message "Spell Checking...%d%%" | 1249 | (message "Spell Checking...%d%%" |
| 1212 | (* 100 (/ (float (- (point) beg)) (- end beg)))) | 1250 | (* 100 (/ (float (- (point) beg)) (- end beg)))) |
| @@ -1219,7 +1257,7 @@ Word syntax described by `ispell-dictionary-alist' (which see)." | |||
| 1219 | (if (and (< (point) end) (> (point) (+ cur 1))) | 1257 | (if (and (< (point) end) (> (point) (+ cur 1))) |
| 1220 | (backward-char 1))))) | 1258 | (backward-char 1))))) |
| 1221 | (backward-char 1) | 1259 | (backward-char 1) |
| 1222 | (message "Spell Checking completed.") | 1260 | (if flyspell-issue-message-flag (message "Spell Checking completed.")) |
| 1223 | (flyspell-word))) | 1261 | (flyspell-word))) |
| 1224 | 1262 | ||
| 1225 | ;*---------------------------------------------------------------------*/ | 1263 | ;*---------------------------------------------------------------------*/ |
| @@ -1254,9 +1292,10 @@ Word syntax described by `ispell-dictionary-alist' (which see)." | |||
| 1254 | (goto-char (match-end 0)) | 1292 | (goto-char (match-end 0)) |
| 1255 | (set-buffer flyspell-large-region-buffer) | 1293 | (set-buffer flyspell-large-region-buffer) |
| 1256 | (goto-char flyspell-large-region-beg) | 1294 | (goto-char flyspell-large-region-beg) |
| 1257 | (message "Spell Checking...%d%% [%s]" | 1295 | (if flyspell-issue-message-flag |
| 1258 | (* 100 (/ (float (- (point) start)) size)) | 1296 | (message "Spell Checking...%d%% [%s]" |
| 1259 | word) | 1297 | (* 100 (/ (float (- (point) start)) size)) |
| 1298 | word)) | ||
| 1260 | (if (search-forward word flyspell-large-region-end t) | 1299 | (if (search-forward word flyspell-large-region-end t) |
| 1261 | (progn | 1300 | (progn |
| 1262 | (setq flyspell-large-region-beg (point)) | 1301 | (setq flyspell-large-region-beg (point)) |
| @@ -1265,7 +1304,7 @@ Word syntax described by `ispell-dictionary-alist' (which see)." | |||
| 1265 | (set-buffer buffer)) | 1304 | (set-buffer buffer)) |
| 1266 | (goto-char (point-max))))) | 1305 | (goto-char (point-max))))) |
| 1267 | ;; we are done | 1306 | ;; we are done |
| 1268 | (message "Spell Checking completed.") | 1307 | (if flyspell-issue-message-flag (message "Spell Checking completed.")) |
| 1269 | ;; ok, we are done with pointing out incorrect words, we just | 1308 | ;; ok, we are done with pointing out incorrect words, we just |
| 1270 | ;; have to kill the temporary buffer | 1309 | ;; have to kill the temporary buffer |
| 1271 | (kill-buffer flyspell-external-ispell-buffer) | 1310 | (kill-buffer flyspell-external-ispell-buffer) |
| @@ -1284,7 +1323,7 @@ Word syntax described by `ispell-dictionary-alist' (which see)." | |||
| 1284 | (set-buffer buffer) | 1323 | (set-buffer buffer) |
| 1285 | (erase-buffer) | 1324 | (erase-buffer) |
| 1286 | ;; this is done, we can start checking... | 1325 | ;; this is done, we can start checking... |
| 1287 | (message "Checking region...") | 1326 | (if flyspell-issue-message-flag (message "Checking region...")) |
| 1288 | (set-buffer curbuf) | 1327 | (set-buffer curbuf) |
| 1289 | (let ((c (apply 'call-process-region beg | 1328 | (let ((c (apply 'call-process-region beg |
| 1290 | end | 1329 | end |
| @@ -1454,10 +1493,18 @@ for the overlay." | |||
| 1454 | (overlay-put flyspell-overlay 'face face) | 1493 | (overlay-put flyspell-overlay 'face face) |
| 1455 | (overlay-put flyspell-overlay 'mouse-face mouse-face) | 1494 | (overlay-put flyspell-overlay 'mouse-face mouse-face) |
| 1456 | (overlay-put flyspell-overlay 'flyspell-overlay t) | 1495 | (overlay-put flyspell-overlay 'flyspell-overlay t) |
| 1496 | (overlay-put flyspell-overlay 'evaporate t) | ||
| 1457 | (if flyspell-use-local-map | 1497 | (if flyspell-use-local-map |
| 1458 | (overlay-put flyspell-overlay | 1498 | (overlay-put flyspell-overlay |
| 1459 | flyspell-overlay-keymap-property-name | 1499 | flyspell-overlay-keymap-property-name |
| 1460 | flyspell-mouse-map)) | 1500 | flyspell-mouse-map)) |
| 1501 | (when (eq face 'flyspell-incorrect-face) | ||
| 1502 | (and (stringp flyspell-before-incorrect-word-string) | ||
| 1503 | (overlay-put flyspell-overlay 'before-string | ||
| 1504 | flyspell-before-incorrect-word-string)) | ||
| 1505 | (and (stringp flyspell-after-incorrect-word-string) | ||
| 1506 | (overlay-put flyspell-overlay 'after-string | ||
| 1507 | flyspell-after-incorrect-word-string))) | ||
| 1461 | flyspell-overlay)) | 1508 | flyspell-overlay)) |
| 1462 | 1509 | ||
| 1463 | ;*---------------------------------------------------------------------*/ | 1510 | ;*---------------------------------------------------------------------*/ |
| @@ -1503,7 +1550,8 @@ for the overlay." | |||
| 1503 | ;; now we can use a new overlay | 1550 | ;; now we can use a new overlay |
| 1504 | (setq flyspell-overlay | 1551 | (setq flyspell-overlay |
| 1505 | (make-flyspell-overlay beg end | 1552 | (make-flyspell-overlay beg end |
| 1506 | 'flyspell-duplicate-face 'highlight))))) | 1553 | 'flyspell-duplicate-face |
| 1554 | 'highlight))))) | ||
| 1507 | 1555 | ||
| 1508 | ;*---------------------------------------------------------------------*/ | 1556 | ;*---------------------------------------------------------------------*/ |
| 1509 | ;* flyspell-auto-correct-cache ... */ | 1557 | ;* flyspell-auto-correct-cache ... */ |
| @@ -1581,6 +1629,14 @@ misspelled words backwards." | |||
| 1581 | local-abbrev-table)) | 1629 | local-abbrev-table)) |
| 1582 | 1630 | ||
| 1583 | ;*---------------------------------------------------------------------*/ | 1631 | ;*---------------------------------------------------------------------*/ |
| 1632 | ;* flyspell-define-abbrev ... */ | ||
| 1633 | ;*---------------------------------------------------------------------*/ | ||
| 1634 | (defun flyspell-define-abbrev (name expansion) | ||
| 1635 | (let ((table (flyspell-abbrev-table))) | ||
| 1636 | (when table | ||
| 1637 | (define-abbrev table name expansion)))) | ||
| 1638 | |||
| 1639 | ;*---------------------------------------------------------------------*/ | ||
| 1584 | ;* flyspell-auto-correct-word ... */ | 1640 | ;* flyspell-auto-correct-word ... */ |
| 1585 | ;*---------------------------------------------------------------------*/ | 1641 | ;*---------------------------------------------------------------------*/ |
| 1586 | (defun flyspell-auto-correct-word () | 1642 | (defun flyspell-auto-correct-word () |
| @@ -1596,6 +1652,7 @@ This command proposes various successive corrections for the current word." | |||
| 1596 | ;; we have already been using the function at the same location | 1652 | ;; we have already been using the function at the same location |
| 1597 | (let* ((start (car flyspell-auto-correct-region)) | 1653 | (let* ((start (car flyspell-auto-correct-region)) |
| 1598 | (len (cdr flyspell-auto-correct-region))) | 1654 | (len (cdr flyspell-auto-correct-region))) |
| 1655 | (flyspell-unhighlight-at start) | ||
| 1599 | (delete-region start (+ start len)) | 1656 | (delete-region start (+ start len)) |
| 1600 | (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) | 1657 | (setq flyspell-auto-correct-ring (cdr flyspell-auto-correct-ring)) |
| 1601 | (let* ((word (car flyspell-auto-correct-ring)) | 1658 | (let* ((word (car flyspell-auto-correct-ring)) |
| @@ -1608,9 +1665,8 @@ This command proposes various successive corrections for the current word." | |||
| 1608 | (flyspell-change-abbrev (flyspell-abbrev-table) | 1665 | (flyspell-change-abbrev (flyspell-abbrev-table) |
| 1609 | flyspell-auto-correct-word | 1666 | flyspell-auto-correct-word |
| 1610 | word) | 1667 | word) |
| 1611 | (define-abbrev (flyspell-abbrev-table) | 1668 | (flyspell-define-abbrev flyspell-auto-correct-word word))) |
| 1612 | flyspell-auto-correct-word word))) | 1669 | (funcall flyspell-insert-function word) |
| 1613 | (insert word) | ||
| 1614 | (flyspell-word) | 1670 | (flyspell-word) |
| 1615 | (flyspell-display-next-corrections flyspell-auto-correct-ring)) | 1671 | (flyspell-display-next-corrections flyspell-auto-correct-ring)) |
| 1616 | (flyspell-ajust-cursor-point pos (point) old-max) | 1672 | (flyspell-ajust-cursor-point pos (point) old-max) |
| @@ -1660,8 +1716,9 @@ This command proposes various successive corrections for the current word." | |||
| 1660 | (rplacd l (cons (car poss) replacements))) | 1716 | (rplacd l (cons (car poss) replacements))) |
| 1661 | (setq flyspell-auto-correct-ring | 1717 | (setq flyspell-auto-correct-ring |
| 1662 | replacements) | 1718 | replacements) |
| 1719 | (flyspell-unhighlight-at start) | ||
| 1663 | (delete-region start end) | 1720 | (delete-region start end) |
| 1664 | (insert new-word) | 1721 | (funcall flyspell-insert-function new-word) |
| 1665 | (if flyspell-abbrev-p | 1722 | (if flyspell-abbrev-p |
| 1666 | (if (flyspell-already-abbrevp | 1723 | (if (flyspell-already-abbrevp |
| 1667 | (flyspell-abbrev-table) word) | 1724 | (flyspell-abbrev-table) word) |
| @@ -1669,8 +1726,7 @@ This command proposes various successive corrections for the current word." | |||
| 1669 | (flyspell-abbrev-table) | 1726 | (flyspell-abbrev-table) |
| 1670 | word | 1727 | word |
| 1671 | new-word) | 1728 | new-word) |
| 1672 | (define-abbrev (flyspell-abbrev-table) | 1729 | (flyspell-define-abbrev word new-word))) |
| 1673 | word new-word))) | ||
| 1674 | (flyspell-word) | 1730 | (flyspell-word) |
| 1675 | (flyspell-display-next-corrections | 1731 | (flyspell-display-next-corrections |
| 1676 | (cons new-word flyspell-auto-correct-ring)) | 1732 | (cons new-word flyspell-auto-correct-ring)) |
| @@ -1681,6 +1737,66 @@ This command proposes various successive corrections for the current word." | |||
| 1681 | (ispell-pdict-save t))))) | 1737 | (ispell-pdict-save t))))) |
| 1682 | 1738 | ||
| 1683 | ;*---------------------------------------------------------------------*/ | 1739 | ;*---------------------------------------------------------------------*/ |
| 1740 | ;* flyspell-auto-correct-previous-pos ... */ | ||
| 1741 | ;*---------------------------------------------------------------------*/ | ||
| 1742 | (defvar flyspell-auto-correct-previous-pos nil | ||
| 1743 | "Holds the start of the first incorrect word before point.") | ||
| 1744 | |||
| 1745 | ;*---------------------------------------------------------------------*/ | ||
| 1746 | ;* flyspell-auto-correct-previous-hook ... */ | ||
| 1747 | ;*---------------------------------------------------------------------*/ | ||
| 1748 | (defun flyspell-auto-correct-previous-hook () | ||
| 1749 | "Hook to track successive calls to `flyspell-auto-correct-previous-word'. | ||
| 1750 | Sets flyspell-auto-correct-previous-pos to nil" | ||
| 1751 | (interactive) | ||
| 1752 | (remove-hook 'pre-command-hook (function flyspell-auto-correct-previous-hook) t) | ||
| 1753 | (unless (eq this-command (function flyspell-auto-correct-previous-word)) | ||
| 1754 | (setq flyspell-auto-correct-previous-pos nil))) | ||
| 1755 | |||
| 1756 | ;*---------------------------------------------------------------------*/ | ||
| 1757 | ;* flyspell-auto-correct-previous-word ... */ | ||
| 1758 | ;*---------------------------------------------------------------------*/ | ||
| 1759 | (defun flyspell-auto-correct-previous-word (position) | ||
| 1760 | "*Auto correct the first mispelled word that occurs before point." | ||
| 1761 | (interactive "d") | ||
| 1762 | |||
| 1763 | (add-hook 'pre-command-hook | ||
| 1764 | (function flyspell-auto-correct-previous-hook) t t) | ||
| 1765 | |||
| 1766 | (save-excursion | ||
| 1767 | (unless flyspell-auto-correct-previous-pos | ||
| 1768 | ;; only reset if a new overlay exists | ||
| 1769 | (setq flyspell-auto-correct-previous-pos nil) | ||
| 1770 | |||
| 1771 | (let ((overlay-list (overlays-in (point-min) position)) | ||
| 1772 | (new-overlay 'dummy-value)) | ||
| 1773 | |||
| 1774 | ;; search for previous (new) flyspell overlay | ||
| 1775 | (while (and new-overlay | ||
| 1776 | (or (not (flyspell-overlay-p new-overlay)) | ||
| 1777 | ;; check if its face has changed | ||
| 1778 | (not (eq (get-char-property | ||
| 1779 | (overlay-start new-overlay) 'face) | ||
| 1780 | 'flyspell-incorrect-face)))) | ||
| 1781 | (setq new-overlay (car-safe overlay-list)) | ||
| 1782 | (setq overlay-list (cdr-safe overlay-list))) | ||
| 1783 | |||
| 1784 | ;; if nothing new exits new-overlay should be nil | ||
| 1785 | (if new-overlay;; the length of the word may change so go to the start | ||
| 1786 | (setq flyspell-auto-correct-previous-pos | ||
| 1787 | (overlay-start new-overlay))))) | ||
| 1788 | |||
| 1789 | (when flyspell-auto-correct-previous-pos | ||
| 1790 | (save-excursion | ||
| 1791 | (goto-char flyspell-auto-correct-previous-pos) | ||
| 1792 | (let ((ispell-following-word t));; point is at start | ||
| 1793 | (if (numberp flyspell-auto-correct-previous-pos) | ||
| 1794 | (goto-char flyspell-auto-correct-previous-pos)) | ||
| 1795 | (flyspell-auto-correct-word)) | ||
| 1796 | ;; the point may have moved so reset this | ||
| 1797 | (setq flyspell-auto-correct-previous-pos (point)))))) | ||
| 1798 | |||
| 1799 | ;*---------------------------------------------------------------------*/ | ||
| 1684 | ;* flyspell-correct-word ... */ | 1800 | ;* flyspell-correct-word ... */ |
| 1685 | ;*---------------------------------------------------------------------*/ | 1801 | ;*---------------------------------------------------------------------*/ |
| 1686 | (defun flyspell-correct-word (event) | 1802 | (defun flyspell-correct-word (event) |
| @@ -1736,6 +1852,7 @@ The word checked is the word at the mouse position." | |||
| 1736 | (if (eq replace 'buffer) | 1852 | (if (eq replace 'buffer) |
| 1737 | (ispell-add-per-file-word-list word))) | 1853 | (ispell-add-per-file-word-list word))) |
| 1738 | (replace | 1854 | (replace |
| 1855 | (flyspell-unhighlight-at cursor-location) | ||
| 1739 | (let ((new-word (if (atom replace) | 1856 | (let ((new-word (if (atom replace) |
| 1740 | replace | 1857 | replace |
| 1741 | (car replace))) | 1858 | (car replace))) |
| @@ -1744,11 +1861,9 @@ The word checked is the word at the mouse position." | |||
| 1744 | (if (not (equal new-word (car poss))) | 1861 | (if (not (equal new-word (car poss))) |
| 1745 | (let ((old-max (point-max))) | 1862 | (let ((old-max (point-max))) |
| 1746 | (delete-region start end) | 1863 | (delete-region start end) |
| 1747 | (insert new-word) | 1864 | (funcall flyspell-insert-function new-word) |
| 1748 | (if flyspell-abbrev-p | 1865 | (if flyspell-abbrev-p |
| 1749 | (define-abbrev (flyspell-abbrev-table) | 1866 | (flyspell-define-abbrev word new-word)) |
| 1750 | word | ||
| 1751 | new-word)) | ||
| 1752 | (flyspell-ajust-cursor-point save | 1867 | (flyspell-ajust-cursor-point save |
| 1753 | cursor-location | 1868 | cursor-location |
| 1754 | old-max))))) | 1869 | old-max))))) |
| @@ -1792,11 +1907,9 @@ The word checked is the word at the mouse position." | |||
| 1792 | (progn | 1907 | (progn |
| 1793 | (delete-region start end) | 1908 | (delete-region start end) |
| 1794 | (goto-char start) | 1909 | (goto-char start) |
| 1795 | (insert new-word) | 1910 | (funcall flyspell-insert-function new-word) |
| 1796 | (if flyspell-abbrev-p | 1911 | (if flyspell-abbrev-p |
| 1797 | (define-abbrev (flyspell-abbrev-table) | 1912 | (flyspell-define-abbrev word new-word)))) |
| 1798 | word | ||
| 1799 | new-word)))) | ||
| 1800 | (flyspell-ajust-cursor-point save cursor-location old-max))))) | 1913 | (flyspell-ajust-cursor-point save cursor-location old-max))))) |
| 1801 | 1914 | ||
| 1802 | ;*---------------------------------------------------------------------*/ | 1915 | ;*---------------------------------------------------------------------*/ |
| @@ -1842,7 +1955,7 @@ The word checked is the word at the mouse position." | |||
| 1842 | (list | 1955 | (list |
| 1843 | (list (concat "Save affix: " (car affix)) | 1956 | (list (concat "Save affix: " (car affix)) |
| 1844 | 'save) | 1957 | 'save) |
| 1845 | '("Accept (session)" accept) | 1958 | '("Accept (session)" session) |
| 1846 | '("Accept (buffer)" buffer)) | 1959 | '("Accept (buffer)" buffer)) |
| 1847 | '(("Save word" save) | 1960 | '(("Save word" save) |
| 1848 | ("Accept (session)" session) | 1961 | ("Accept (session)" session) |