Emacs Spell Checker Problems

Perm url with updates: http://xahlee.org/emacs/emacs_spell_checker_problems.html

Emacs Spell Checker Problems

Xah Lee, 2010-05-25

This page discuss emacs's spell checking feature, its problems, and some practical tips.

flyspell-mode Problems

Emacs has a spell checking feature (flyspell-mode), that check spelling errors while you type, much like all other modern editors, word processors, email programs, or text box in browsers. However, emacs's spell checking feature is much worse than the spell checker in browsers or any commercial editor.

When you have flyspell-mode on, it slows down your editing noticeably. Normally, when you hold down “Ctrl+” (forward-word), the cursor moves fast across lines to the place you want. But with flyspell on, the cursor freezes, and when you release the key, the cursor shows in some other place. Essentially, the screen is not updated so often. This is just not workable.

Another problem is that if you open a document, with flyspell-mode on, it does not automatically check the spelling of all existing text. I think it only checks word at your cursor positions. (which explains why you can't move cursor fast across words.)

speck-mode

There is a alternative, called speck-mode, which i've been using since ~2007. Like other spell checking feature in commercial editors, it does its work in the background quietly when you are not doing anything. However, getting speck-mode setup isn't trivial, especially on Windows, because you have to install the spell checking engine. (one of ispell, aspell, hunspell) Basically, you need to be a emacs expert to get it to work.

Also, in most commercial software, the spell checker will eventually check the whole document, but speck-mode only checks texts that's visible portion of the window. I haven't looked into if it is possible to change this.

speck-mode, Great Code, Bad Everything Else

speck-mode's author is Martin Rudalics, who seems to have published a paper on Common Lisp in ACM back in 1989. (See: Distributed copying garbage collection (1986) by Martin Rudalics, at Source) So, apparently the guy seems to be a old lisper who knows what he's doing as far as the code goes. However, speck-mode is one of those mode that only few emacs people know or use. It lacks much documentation (it has none!). Me and David Capello have made the whole spelling system work with speck-mode in our ErgoEmacs distribution, out of the box. It worked, better than flyspell, but isn't perfect. And i haven't really put that much time into fixing issues. (See: issue 51, issue 56, issue 74. )

Today, doing some work on ErgoEmacs, i thought why not send a email to Martin and see if there's a new version. Indeed, there is, and he send it to me.

However, he told me that there even isn't a public location for the mode. The one that appears on emacswiki at emacswiki SpeckMode is from 2008-07-26. Gah!

Here's the latest version speck.el 2010-05-25.

I tried to incorporate this version into ErgoEmacs, but run into problems... gah. Will need to work on it, probably half a day. Here's the error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  intern(nil)
  (cond ((eq speck-engine ...) (intern speck-aspell-default-dictionary-name)) ((eq speck-engine ...) (intern speck-hunspell-default-dictionary-name)) ((eq speck-engine ...) (intern speck-ispell-default-dictionary-name)))
  (or speck-saved-dictionary (cond (... ...) (... ...) (... ...)))
  (setq speck-dictionary (or speck-saved-dictionary (cond ... ... ...)))
  (if (and (local-variable-p ...) speck-dictionary) nil (setq speck-dictionary (or speck-saved-dictionary ...)))
  (unless (and (local-variable-p ...) speck-dictionary) (setq speck-dictionary (or speck-saved-dictionary ...)))
  speck-activate()
  (if speck-mode (speck-activate) (speck-deactivate))
  (let ((last-message ...)) (setq speck-mode (cond ... ... ...)) (if speck-mode (speck-activate) (speck-deactivate)) (run-hooks (quote speck-mode-hook) (if speck-mode ... ...)) (if (called-interactively-p) (progn nil ...)))
  speck-mode(toggle)
  call-interactively(speck-mode t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)

OpenSource Spell-Checking Engines

Besides the bad quality of the spell checking feature, the open source spell checking engine ispell and aspell are also much inferior than commercial ones, lacking much words and commonly accepted spelling variations, with the exception of Hunspell.

See Wikipedia: Hunspell. It is based on MySpell, which is based on Ispell, and probably with input from Aspell. So, the Open Source spell checking engines roughly goes from Ispell→Aspell→Hunspell. Note that Hunspel is used by Firefox, Opera, Google Chrome, Apple Mac OS X.

See also: Problems of Open Source Dictionaries.

How to Always Have Spell Checker On

A little practical tip. By default, spell checker isn't even on. However, if you want it always on, you can put this code in your emacs init file:

(defun turn-spell-checking-on ()
  "Turn speck-mode or flyspell-mode on."
  ;; (speck-mode 1)
  (flyspell-mode 1)
  )

(add-hook 'text-mode-hook 'turn-spell-checking-on)

Also, there's the command flyspell-buffer that checks the whole file, but alas, it is slow. While it works, your emacs is frozen.

This article is written with respect to Emacs version 23.1.1 (2009-07-29)

Thanks to Martin Rudalics for speck-mode, for sending me the latest version and allowing me to post it, and answer some of my questions. David Capello did the work for getting hunspell engine to work in ErgoEmacs on Windows. Of course, thanks to flyspell author (Manuel Serrano), emacs developers, and the open source spell engine authors.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs