automatically checking your spelling






When I'm typing fast, it's easy to make spelling mistakes (as you may have
noticed reading Emacs-Fu). It's not so much that I don't know how to write
things, but sometimes there seems to be a bit of a disconnect between brain
and fingers.



One tool that helps me to make fewer mistakes is automatic spelling checking, and in particular on-the-fly spelling checking. Spell-checking in
emacs is taken care of by the ispell-package. Traditionally, this was a way
to interface emacs with the ispell-program on Unix, but nowadays it's often
used with other programs, such as aspell.



aspell is GNU's intended replacement for ispell, and has been for a long
time. In the meantime, other spelling checkers have come up; in the Free
Software world, the most prominent one is probably hunspell, which is used by
e.g. Mozilla and OpenOffice. As I said, Emacs supports all of those; I'm using
aspell, which works well for me. To use aspell for spelling-checking, I
have the following in my .emacs:




(setq ispell-program-name "aspell"
ispell-extra-args '("--sug-mode=ultra"))




Please consult the aspell documentation for the details.



You can spell-check your text with ispell-buffer and friends, which are also
available through the menu (Tools/Spell Checking/...). This works fine, but
it makes spelling checking a separate step you have to go through and you may
forget. So, I like to do the spelling-checking on-the-fly, that is, while I
am typing. This can be done using flyspell-mode (you can also use
flyspell-prog-mode, to do spell checking inside comments in computer
programs, but I find that a bit over the top).



When flyspell-mode is enabled, it will mark
misspelt
eh misspelled words by painting them in a different color while you are typing --
the common way many word processing programs do it. A common way to enable
flyspell-mode is to put it the the mode-hook for the modes where you want
to use it. For example, to enable flyspell-mode for all your org-mode
buffers, you can add something like the following to your .emacs:




(add-hook 'org-mode-hook
(lambda()
(flyspell-mode 1)))




Note, you can use the middle mouse button to get alternatives for a misspelled
word.




By default, it uses the English dictionary, but it's easy to switch to another
using M-x ispell-change-dictionary. To make it easier, I have defined the
C-c N key binding to activate Dutch-language ("nederlands") spelling
checking, and update the buffer.




(global-set-key (kbd "C-c N") 
(lambda()(interactive)
(ispell-change-dictionary "nederlands")
(flyspell-buffer)))





Now, there's another category of mistakes – their-they're-there, its-it's
or to-too-two that require a spelling checker that's a bit smarter. There
are some free implementations in OpenOffice and Abiword; it'd be interesting
to see if those could be integrated with emacs as well.



Now, laugh about the sweet irony of the spelling errors that I failed to
notice :)


No comments:

Post a Comment

Followers

Popular Posts