📜 ⬆️ ⬇️

Emacs and Hunspell: Normal Spell Checker


Hunspell is the most promising free spell checker application available today. It is built in by default in programs like Firefox and OpenOffice. Dictionaries for it are by far the largest among analogs. But with Emacs, it's not so easy to make friends with him.


Install hunspell


First of all, you have to assemble Hunspell manually, since there are not many dependencies. To do this, you need to go here and download the tarball with the source code.

cd /tmp wget 'http://hunspell.cvs.sourceforge.net/viewvc/hunspell/hunspell/?view=tar' -O hunspell.tgz tar -xzf hunspell.tgz cd hunspell 

')
Now we have the source code for Hunspell, which nevertheless will not work with Emacs, and in order to make it work we need a patch written by some Nikolai Sushchenko. For which he thanks a lot. Just in case I bring a patch here.

Patch
 --- src/tools/hunspell.cxx~0 2011-01-21 19:01:29.000000000 +0200 +++ src/tools/hunspell.cxx 2013-02-07 10:11:54.443610900 +0200 @@ -710,13 +748,22 @@ if (pos >= 0) { fflush(stdout); } else { char ** wlst = NULL; - int ns = pMS[d]->suggest(&wlst, token); + int byte_offset = parser->get_tokenpos() + pos; + int char_offset = 0; + if (strcmp(io_enc, "UTF-8") == 0) { + for (int i = 0; i < byte_offset; i++) { + if ((buf[i] & 0xc0) != 0x80) + char_offset++; + } + } else { + char_offset = byte_offset; + } + int ns = pMS[d]->suggest(&wlst, chenc(token, io_enc, dic_enc[d])); if (ns == 0) { - fprintf(stdout,"# %s %d", token, - parser->get_tokenpos() + pos); + fprintf(stdout,"# %s %d", token, char_offset); } else { fprintf(stdout,"& %s %d %d: ", token, ns, - parser->get_tokenpos() + pos); + char_offset); fprintf(stdout,"%s", chenc(wlst[0], dic_enc[d], io_enc)); } for (int j = 1; j < ns; j++) { @@ -745,13 +792,23 @@ if (pos >= 0) { if (root) free(root); } else { char ** wlst = NULL; + int byte_offset = parser->get_tokenpos() + pos; + int char_offset = 0; + if (strcmp(io_enc, "UTF-8") == 0) { + for (int i = 0; i < byte_offset; i++) { + if ((buf[i] & 0xc0) != 0x80) + char_offset++; + } + } else { + char_offset = byte_offset; + } int ns = pMS[d]->suggest(&wlst, chenc(token, io_enc, dic_enc[d])); if (ns == 0) { fprintf(stdout,"# %s %d", chenc(token, io_enc, ui_enc), - parser->get_tokenpos() + pos); + char_offset); } else { fprintf(stdout,"& %s %d %d: ", chenc(token, io_enc, ui_enc), ns, - parser->get_tokenpos() + pos); + char_offset); fprintf(stdout,"%s", chenc(wlst[0], dic_enc[d], ui_enc)); } for (int j = 1; j < ns; j++) { 


Save the patch to the /tmp/hunspell/emacs_patch.patch file. Now we apply it:

  cd /tmp/hunspell patch src/tools/hunspell.cxx emacs_patch.patch 


Everything is ready for assembly. The default prefix is ​​/ usr / local /, so there’s no conflict with the standard hunspell of your distribution.

  ./configure make sudo make install 



Installation of dictionaries


You need to install the standard hunspell dictionaries, in our case English and Russian:

  sudo apt-get install hunspell hunspell-en-us hunspell-ru 



Emacs setup


In .emacs, add the following to the end of the file:

 ;;     (setq ispell-local-dictionary-alist '(("russian" "[]" "[^]" "[-]" nil ("-d" "ru_RU") nil utf-8) ("english" "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-d" "en_US") nil iso-8859-1))) ;;  aspell  hunspell (setq ispell-really-aspell nil ispell-really-hunspell t) ;;      hunspell (setq ispell-program-name "/usr/local/bin/hunspell") 


Everything, now spelling in Russian and English will work through the usual ispell-buffer and flyspell-mode.

Source: https://habr.com/ru/post/215055/


All Articles