From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Agustin Martin Newsgroups: gmane.emacs.devel Subject: Possible patch for Localwords handling in flyspell flyspell-large-region Date: Mon, 17 Oct 2005 19:03:11 +0200 Message-ID: <20051017170311.GA4327@agmartin.aq.upm.es> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="LZvS9be/3tNcYl/X" X-Trace: sea.gmane.org 1129568934 5540 80.91.229.2 (17 Oct 2005 17:08:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 17 Oct 2005 17:08:54 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 17 19:08:42 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ERYRR-0001Fk-Jz for ged-emacs-devel@m.gmane.org; Mon, 17 Oct 2005 19:06:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ERYRR-0000Pl-06 for ged-emacs-devel@m.gmane.org; Mon, 17 Oct 2005 13:06:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ERYRE-0000Pf-SW for emacs-devel@gnu.org; Mon, 17 Oct 2005 13:06:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ERYRE-0000PT-1t for emacs-devel@gnu.org; Mon, 17 Oct 2005 13:06:16 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ERYRD-0000PQ-2f for emacs-devel@gnu.org; Mon, 17 Oct 2005 13:06:15 -0400 Original-Received: from [138.100.4.49] (helo=edison.ccupm.upm.es) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ERYRC-0006tI-O4 for emacs-devel@gnu.org; Mon, 17 Oct 2005 13:06:15 -0400 Original-Received: from debian ([138.100.247.74]) by edison.ccupm.upm.es (8.12.10/8.12.10) with ESMTP id j9HH680u002559; Mon, 17 Oct 2005 19:06:11 +0200 Original-Received: by debian (Postfix, from userid 1000) id DC03317FA8; Mon, 17 Oct 2005 19:03:11 +0200 (CEST) Original-To: emacs devel mailing list Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at hispalinux.es X-UIDL: %~N!!9#F"!4hV"!S)c"! User-Agent: Mutt/1.5.9i X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:44197 Archived-At: --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --LZvS9be/3tNcYl/X Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="flyspell.el.emacs-cvs-patch" --- 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..."))))) ;*---------------------------------------------------------------------*/ --LZvS9be/3tNcYl/X Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --LZvS9be/3tNcYl/X--