Does anyone have a working setup for hunspell and Emacs? Simply setting ispell-program-name to hunspell doesn’t work, the output (when using flyspell, for example) looks like below:
-> UTF-8 encoding error. Missing continuation byte in 0. character position: - 9631: word not found
(my files are usually encoded in UTF-8)
I’ve seen a few different setups, but they’ve all failed in one way or another. If the encoding works like it should it usually has problems finding the right dictionary.
Anyone with a working solution? It would be nice to be able to switch between two dictionaries (the default should be the swedish dictionary, and the secondary english), but having anything running would be even better.
If you are getting that UTF-8 encoding error, then it means that the
hunspellprocess is getting run with an argument specifying some other encoding. When I check my process list, for example, I see this child process to Emacs once it has started up:The
ispell-get-coding-systemfunction is what decides which encoding to use, which it does by examining the bigispell-dictionary-alistvariable that seems to list every language known to Emacs. The function normally grabs the last symbol off of the entry that matches the language you want to check. For some reason that I did not bother to figure out, this list hasiso-8859-1for English — instead of, you know, paying attention to the encoding in your actual buffer. I know, it seems to make no sense. But we carry on.You would think that you could override this by setting your own value for the variable
ispell-dictionary-alistand useutf-8as the last of the eight parameters:But I could never get this setting to actually work, whether or not I did a
(load-library "ispell")first in my.emacs, or whether I did it inside of one of those:Either way, if I started up a fresh Emacs and entered
*scratch*and typedispell-dictionary-alistand pressed Control-J, then the huge original list thatispellcreates would come up. Every time.So I decided to do an end-run around the entire problem of this huge list and simply rewrite the
ispell-get-coding-systemfunction to always returnutf-8. Sure, this will bite me the next time that I open a file that is really iniso-8859-1, but I never do that anyway, right?To implement this successfully in my
.emacsfile (well,~/.emacs.d/init.elbut that takes so much typing for a Stack Overflow answer) required this code:I now have
hunspellup and working like a champ! Unfortunately the whole reason I went through getting it working was in the hopes that its dictionary was vastly larger than aspell’s but I see that it’s highlighting some of the same words. Oh well, I’ll try another approach. I basically want a spell checker that can be loaded up with the/usr/share/dict/american-english-hugedictionary that is available on Ubuntu, butaspelldied in many ways when I tried to expand its horizons. Maybe I will be luckier withhunspell— we will see.