Hi, I am attaching a possible patch for handling localwords in flyspell-large-region function. The reason for this is as follows.
I have been using flyspell in a large file having a number of words declared valid in LocalWords for that file, and running flyspell-buffer is rather slow, because all mispellings given by 'ispell -l' are checked, even if they are declared as valid in LocalWords. I have been playing with a possible way to speed up the process, it essentially consists on removing valid words (declared in LocalWords) from the mispellings buffer that contains the 'ispell -l' output *before* they are checked by regular flyspell means. That is, a) Parse buffer being spellchecked and put words in LocalWords in a list. b) Remove from mispellings buffer lines that match elements of that list. c) Proceed as usual. I also needed to remove overlays in the region each time, otherwise when a word is added to LocalWords and flyspell-buffer run again, it would remain marked. LocalWords parsing code is stolen from ispell.el. I already submitted the patch to Manuel Serrano, and has been incorporated into flyspell-1.7j.el. I am attaching the patch as went finally into flyspell-1.7j.el, with a minor change to apply cleanly to emacs-cvs flyspell.el. Hope this is useful, [Please CC me on replies, I am not subscribed to emacs-devel] Cheers, -- Agustin
--- flyspell.el.orig 2005-10-17 01:48:04.000000000 +0200 +++ flyspell.el 2005-10-17 01:48:25.000000000 +0200 @@ -1362,6 +1362,46 @@ (setq flyspell-external-ispell-buffer nil)) ;*---------------------------------------------------------------------*/ +;* flyspell-process-localwords ... */ +;* ------------------------------------------------------------- */ +;* This function is used to prevent checking words declared */ +;* explictitly correct on large regions. */ +;*---------------------------------------------------------------------*/ +(defun flyspell-process-localwords () + "Parse Localwords in the buffer and remove them from the mispellings +buffer before flyspell attempts to check them." + (let (localwords + (current-buffer curbuf) + (mispellings-buffer buffer) + (ispell-casechars (ispell-get-casechars))) + ;; Get localwords from the original buffer + (save-excursion + (set-buffer current-buffer) + (flyspell-delete-all-overlays) + (beginning-of-buffer) + ;; Localwords parsing stolen form ispell.el + (while (search-forward ispell-words-keyword nil t) + (let ((end (save-excursion (end-of-line) (point))) + string) + ;; buffer-local words separated by a space, and can contain + ;; any character other than a space. Not rigorous enough. + (while (re-search-forward " *\\([^ ]+\\)" end t) + (setq string (buffer-substring-no-properties (match-beginning 1) + (match-end 1))) + ;; This can fail when string contains a word with illegal chars. + ;; Error handling needs to be added between ispell and emacs. + (if (and (< 1 (length string)) + (equal 0 (string-match ispell-casechars string))) + (setq localwords (add-to-list 'localwords string))))))) + ;; Remove localwords matches + (set-buffer mispellings-buffer) + (while localwords + (beginning-of-buffer) + (delete-matching-lines (concat "^" (car localwords) "$")) + (setq localwords (cdr localwords))) + (end-of-buffer))) + +;*---------------------------------------------------------------------*/ ;* flyspell-large-region ... */ ;*---------------------------------------------------------------------*/ (defun flyspell-large-region (beg end) @@ -1400,7 +1440,9 @@ (setq args (append args ispell-extra-args)) args)))) (if (eq c 0) - (flyspell-external-point-words) + (progn + (flyspell-process-localwords) + (flyspell-external-point-words)) (error "Can't check region..."))))) ;*---------------------------------------------------------------------*/
_______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel