* Possible patch for Localwords handling in flyspell flyspell-large-region
@ 2005-10-17 17:03 Agustin Martin
0 siblings, 0 replies; only message in thread
From: Agustin Martin @ 2005-10-17 17:03 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
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
[-- Attachment #2: flyspell.el.emacs-cvs-patch --]
[-- Type: text/plain, Size: 2706 bytes --]
--- 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...")))))
;*---------------------------------------------------------------------*/
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-17 17:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-17 17:03 Possible patch for Localwords handling in flyspell flyspell-large-region Agustin Martin
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).