aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorStefan Monnier2005-11-28 16:44:37 +0000
committerStefan Monnier2005-11-28 16:44:37 +0000
commit6a99c272837ee61fa361007ffce3069feb704a32 (patch)
tree23fb2efbee8a41bb15785980e98886965c8bbee2 /lisp/textmodes
parente99c9adab079002460e74b5b4585db7599f1992d (diff)
downloademacs-6a99c272837ee61fa361007ffce3069feb704a32.tar.gz
emacs-6a99c272837ee61fa361007ffce3069feb704a32.zip
(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.
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/flyspell.el51
1 files changed, 27 insertions, 24 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index dd718e21ed9..a0f36f5f794 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -501,23 +501,29 @@ in your .emacs file.
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 ... */
@@ -543,9 +549,7 @@ in your .emacs file.
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
@@ -650,8 +654,7 @@ not the very same deplacement command."
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
@@ -704,14 +707,14 @@ before the current command."
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 ... */
@@ -899,7 +902,7 @@ Mostly we check word delimiters."
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)
@@ -1011,7 +1014,7 @@ Mostly we check word delimiters."
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