Mercurial > emacs
comparison lisp/textmodes/flyspell.el @ 67178:db5dfb03d180
(flyspell-last-buffer): New var.
(flyspell-accept-buffer-local-defs): Use it to avoid silly redundant work.
(flyspell-mode-on): Use add-hook for after-change-functions.
(flyspell-mode-off): Use remove-hook for after-change-functions.
(flyspell-changes): Make it buffer-local.
(flyspell-after-change-function): Make it non-interactive. Use push.
(flyspell-post-command-hook): Check input-pending-p while processing
the potentially long list of buffer changes.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 28 Nov 2005 16:44:37 +0000 |
parents | 29c20df6248f |
children | a52ff1637e2f |
comparison
equal
deleted
inserted
replaced
67177:e59c64acce36 | 67178:db5dfb03d180 |
---|---|
499 (and (consp ws) (window-minibuffer-p (car ws))))) | 499 (and (consp ws) (window-minibuffer-p (car ws))))) |
500 | 500 |
501 ;;*---------------------------------------------------------------------*/ | 501 ;;*---------------------------------------------------------------------*/ |
502 ;;* flyspell-accept-buffer-local-defs ... */ | 502 ;;* flyspell-accept-buffer-local-defs ... */ |
503 ;;*---------------------------------------------------------------------*/ | 503 ;;*---------------------------------------------------------------------*/ |
504 (defvar flyspell-last-buffer nil | |
505 "The buffer in which the last flyspell operation took place.") | |
506 | |
504 (defun flyspell-accept-buffer-local-defs () | 507 (defun flyspell-accept-buffer-local-defs () |
505 ;; strange problem. If buffer in current window has font-lock turned on, | 508 ;; When flyspell-word is used inside a loop (e.g. when processing |
506 ;; but SET-BUFFER was called to point to an invisible buffer, this ispell | 509 ;; flyspell-changes), the calls to `ispell-accept-buffer-local-defs' end |
507 ;; call will reset the buffer to the buffer in the current window. However, | 510 ;; up dwarfing everything else, so only do it when the buffer has changed. |
508 ;; it only happens at startup (fix by Albert L. Ting). | 511 (unless (eq flyspell-last-buffer (current-buffer)) |
509 (save-current-buffer | 512 (setq flyspell-last-buffer (current-buffer)) |
510 (ispell-accept-buffer-local-defs)) | 513 ;; Strange problem: If buffer in current window has font-lock turned on, |
511 (if (not (and (eq flyspell-dash-dictionary ispell-dictionary) | 514 ;; but SET-BUFFER was called to point to an invisible buffer, this ispell |
512 (eq flyspell-dash-local-dictionary ispell-local-dictionary))) | 515 ;; call will reset the buffer to the buffer in the current window. |
516 ;; However, it only happens at startup (fix by Albert L. Ting). | |
517 (save-current-buffer | |
518 (ispell-accept-buffer-local-defs)) | |
519 (unless (and (eq flyspell-dash-dictionary ispell-dictionary) | |
520 (eq flyspell-dash-local-dictionary ispell-local-dictionary)) | |
513 ;; The dictionary has changed | 521 ;; The dictionary has changed |
514 (progn | 522 (setq flyspell-dash-dictionary ispell-dictionary) |
515 (setq flyspell-dash-dictionary ispell-dictionary) | 523 (setq flyspell-dash-local-dictionary ispell-local-dictionary) |
516 (setq flyspell-dash-local-dictionary ispell-local-dictionary) | 524 (setq flyspell-consider-dash-as-word-delimiter-flag |
517 (if (member (or ispell-local-dictionary ispell-dictionary) | 525 (member (or ispell-local-dictionary ispell-dictionary) |
518 flyspell-dictionaries-that-consider-dash-as-word-delimiter) | 526 flyspell-dictionaries-that-consider-dash-as-word-delimiter))))) |
519 (setq flyspell-consider-dash-as-word-delimiter-flag t) | |
520 (setq flyspell-consider-dash-as-word-delimiter-flag nil))))) | |
521 | 527 |
522 ;;*---------------------------------------------------------------------*/ | 528 ;;*---------------------------------------------------------------------*/ |
523 ;;* flyspell-mode-on ... */ | 529 ;;* flyspell-mode-on ... */ |
524 ;;*---------------------------------------------------------------------*/ | 530 ;;*---------------------------------------------------------------------*/ |
525 (defun flyspell-mode-on () | 531 (defun flyspell-mode-on () |
541 ;; we bound flyspell action to post-command hook | 547 ;; we bound flyspell action to post-command hook |
542 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t) | 548 (add-hook 'post-command-hook (function flyspell-post-command-hook) t t) |
543 ;; we bound flyspell action to pre-command hook | 549 ;; we bound flyspell action to pre-command hook |
544 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t) | 550 (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t) |
545 ;; we bound flyspell action to after-change hook | 551 ;; we bound flyspell action to after-change hook |
546 (make-local-variable 'after-change-functions) | 552 (add-hook 'after-change-functions 'flyspell-after-change-function nil t) |
547 (setq after-change-functions | |
548 (cons 'flyspell-after-change-function after-change-functions)) | |
549 ;; set flyspell-generic-check-word-p based on the major mode | 553 ;; set flyspell-generic-check-word-p based on the major mode |
550 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) | 554 (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) |
551 (if mode-predicate | 555 (if mode-predicate |
552 (setq flyspell-generic-check-word-p mode-predicate))) | 556 (setq flyspell-generic-check-word-p mode-predicate))) |
553 ;; the welcome message | 557 ;; the welcome message |
648 (defun flyspell-mode-off () | 652 (defun flyspell-mode-off () |
649 "Turn Flyspell mode off." | 653 "Turn Flyspell mode off." |
650 ;; we remove the hooks | 654 ;; we remove the hooks |
651 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t) | 655 (remove-hook 'post-command-hook (function flyspell-post-command-hook) t) |
652 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t) | 656 (remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t) |
653 (setq after-change-functions (delq 'flyspell-after-change-function | 657 (remove-hook 'after-change-functions 'flyspell-after-change-function t) |
654 after-change-functions)) | |
655 ;; we remove all the flyspell hilightings | 658 ;; we remove all the flyspell hilightings |
656 (flyspell-delete-all-overlays) | 659 (flyspell-delete-all-overlays) |
657 ;; we have to erase pre cache variables | 660 ;; we have to erase pre cache variables |
658 (setq flyspell-pre-buffer nil) | 661 (setq flyspell-pre-buffer nil) |
659 (setq flyspell-pre-point nil) | 662 (setq flyspell-pre-point nil) |
702 ;;* The flyspell after-change-hook, store the change position. In */ | 705 ;;* The flyspell after-change-hook, store the change position. In */ |
703 ;;* the post command hook, we will check, if the word at this */ | 706 ;;* the post command hook, we will check, if the word at this */ |
704 ;;* position has to be spell checked. */ | 707 ;;* position has to be spell checked. */ |
705 ;;*---------------------------------------------------------------------*/ | 708 ;;*---------------------------------------------------------------------*/ |
706 (defvar flyspell-changes nil) | 709 (defvar flyspell-changes nil) |
710 (make-variable-buffer-local 'flyspell-changes) | |
707 | 711 |
708 ;;*---------------------------------------------------------------------*/ | 712 ;;*---------------------------------------------------------------------*/ |
709 ;;* flyspell-after-change-function ... */ | 713 ;;* flyspell-after-change-function ... */ |
710 ;;*---------------------------------------------------------------------*/ | 714 ;;*---------------------------------------------------------------------*/ |
711 (defun flyspell-after-change-function (start stop len) | 715 (defun flyspell-after-change-function (start stop len) |
712 "Save the current buffer and point for Flyspell's post-command hook." | 716 "Save the current buffer and point for Flyspell's post-command hook." |
713 (interactive) | 717 (push (cons start stop) flyspell-changes)) |
714 (setq flyspell-changes (cons (cons start stop) flyspell-changes))) | |
715 | 718 |
716 ;;*---------------------------------------------------------------------*/ | 719 ;;*---------------------------------------------------------------------*/ |
717 ;;* flyspell-check-changed-word-p ... */ | 720 ;;* flyspell-check-changed-word-p ... */ |
718 ;;*---------------------------------------------------------------------*/ | 721 ;;*---------------------------------------------------------------------*/ |
719 (defun flyspell-check-changed-word-p (start stop) | 722 (defun flyspell-check-changed-word-p (start stop) |
897 ;; we do not disable the ispell cache. | 900 ;; we do not disable the ispell cache. |
898 (if (and (symbolp this-command) (get this-command 'flyspell-delayed)) | 901 (if (and (symbolp this-command) (get this-command 'flyspell-delayed)) |
899 (progn | 902 (progn |
900 (setq flyspell-word-cache-end -1) | 903 (setq flyspell-word-cache-end -1) |
901 (setq flyspell-word-cache-result '_))))) | 904 (setq flyspell-word-cache-result '_))))) |
902 (while (consp flyspell-changes) | 905 (while (and (not (input-pending-p)) (consp flyspell-changes)) |
903 (let ((start (car (car flyspell-changes))) | 906 (let ((start (car (car flyspell-changes))) |
904 (stop (cdr (car flyspell-changes)))) | 907 (stop (cdr (car flyspell-changes)))) |
905 (if (flyspell-check-changed-word-p start stop) | 908 (if (flyspell-check-changed-word-p start stop) |
906 (save-excursion | 909 (save-excursion |
907 '(flyspell-debug-signal-changed-checked) | 910 '(flyspell-debug-signal-changed-checked) |
1009 (ispell-send-string (concat "^" word "\n")) | 1012 (ispell-send-string (concat "^" word "\n")) |
1010 ;; we mark the ispell process so it can be killed | 1013 ;; we mark the ispell process so it can be killed |
1011 ;; when emacs is exited without query | 1014 ;; when emacs is exited without query |
1012 (set-process-query-on-exit-flag ispell-process nil) | 1015 (set-process-query-on-exit-flag ispell-process nil) |
1013 ;; Wait until ispell has processed word. Since this code is often | 1016 ;; Wait until ispell has processed word. Since this code is often |
1014 ;; executed rom post-command-hook but the ispell process may not | 1017 ;; executed from post-command-hook but the ispell process may not |
1015 ;; be responsive, it's important to make sure we re-enable C-g. | 1018 ;; be responsive, it's important to make sure we re-enable C-g. |
1016 (with-local-quit | 1019 (with-local-quit |
1017 (while (progn | 1020 (while (progn |
1018 (accept-process-output ispell-process) | 1021 (accept-process-output ispell-process) |
1019 (not (string= "" (car ispell-filter)))))) | 1022 (not (string= "" (car ispell-filter)))))) |