minad / jinx

🪄 Enchanted Spell Checker
GNU General Public License v3.0
432 stars 21 forks source link

Jinx can't find the dictionary on Windows Emacs #10

Closed Eason0210 closed 1 year ago

Eason0210 commented 1 year ago

Hi @minad,

Jinx works well on macOS, but on Windows Emacs 30.0.50, I got this error:

Jinx: No dictionaries available for ‘jinx-languages’ = "en_US"

My configuration

(use-package jinx
  :bind ("C-," . jinx-correct)
  :hook (after-init . global-jinx-mode)
  :custom (jinx-languages "en_US"))

I tried to eval (mapcar #'jinx--mod-dict (ensure-list "en_US")) and got nil

I install enchant with mingw64(msys2):

pacman -S mingw64/mingw-w64-x86_64-enchant
pacman -S mingw-w64-x86_64-hunspell-en

And get the results as below:

MINGW64 ~
$ enchant-lsmod-2
aspell (Aspell Provider)
hunspell (Hunspell Provider)
nuspell (Nuspell Provider)
voikko (Voikko Provider)

MINGW64 ~
$ enchant-lsmod-2 -list-dicts
en (aspell)
en_AG (hunspell)
en_AU (aspell)
en_BS (hunspell)
en_BW (hunspell)
en_BZ (hunspell)
en_CA (aspell)
en_DK (hunspell)
en_GB (aspell)
en_GH (hunspell)
en_HK (hunspell)
en_IE (hunspell)
en_IN (hunspell)
en_JM (hunspell)
en_NA (hunspell)
en_NG (hunspell)
en_NZ (hunspell)
en_PH (hunspell)
en_SG (hunspell)
en_TT (hunspell)
en_US (aspell)
en_ZA (hunspell)
en_ZW (hunspell)

MINGW64 ~
$ enchant-2 -d en_US -a
@(#) International Ispell Version 3.1.20 (but really Enchant 2.3.4)
Egnlish
& Egnlish 4 0: English, Englisher, Unleash, Unlatch

And I can confirm that my flyspell config works well with enchant

(use-package flyspell
  :diminish
  :hook ((prog-mode . flyspell-prog-mode)
         (flyspell-mode . (lambda ()
                            (dolist (key '("C-;" "C-."))
                              (unbind-key key flyspell-mode-map)))))
  :custom
  (flyspell-issue-message-flag nil)
  (ispell-program-name "enchant-2")
  (ispell-dictionary "english"))

enchant configuration in "C:\Users\<username>\AppData\Local\enchant\enchant.ordering" is:

*:nuspell,aspell,hunspell
en:nuspell,aspell,hunspell
en_US:nuspell,aspell,hunspell

Do you have any suggestions?

minad commented 1 year ago

No idea, since I don't use Windows. It is weird that enchant-2 when invoked directly works, but not when used as library. Let me know if you figure something out. Windows is currently unsupported, also because of the module compilation.

swamijee commented 1 year ago

Leaving this comment here so others can figure out how to get the compilation working on Windows.

I was able to get the compilation working as expected by installing both enchant and package config in mingw64(msys2). Ensure that you have the path set correctly so emacs can actually run package config while installing the package.

https://packages.msys2.org/package/mingw-w64-x86_64-pkg-config https://packages.msys2.org/package/mingw-w64-x86_64-enchant

I also had to standalone install the required dictionaries manually (aspell-en, hunspell-en etc).

Like @minad and @Eason0210 have pointed out, the enchant executable works standalone. It's the library that keeps crashing emacs for me.

I have a hunch that this may be related to https://github.com/AbiWord/enchant/issues/198.

My plan is to write a standalone c function to check if the library can be reliably accessed.

Posting here so people who have better experience with enchant can point out what is going wrong. I'll continue to debug and post updates here if any.

minad commented 1 year ago

@swamijee Thanks for investigating. I am sure you can compile the module and libenchant in such a way that it can be loaded reliably. I suppose the enchant binary also loads the enchant.dll? For the record, on Linux I had zero crashes due to jinx-mod.so or libenchant.

jcalve commented 1 year ago

@swamijee I was able to install and build jinx but it does not detect any dictionaries, did you manage to make it work?

Ypot commented 1 year ago

For the record, I confirm jinx is launched by previously:

Now I must configure dictionaries, etc. but I received no error about dictionaries, it just detects every word as incorrect

Suposedly would be these dictionaries installed?

$ hunspell -D
SEARCH PATH:
.;C:/msys64/mingw64/bin/;Z:\USER\dict_data\Software\Hunspell\share\hunspell;C:/msys64/mingw64/share/
hunspell;C:/msys64/mingw64/share/myspell;C:/msys64/mingw64/share/myspell/dicts;C:/msys64;%USERPROFIL
E%/Application Data/OpenOffice.org 2/user/wordbook;C:/msys64/mingw64/share/dict/ooo;
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
Z:\USER\dict_data\Software\Hunspell\share\hunspell/en_GB
Z:\USER\dict_data\Software\Hunspell\share\hunspell/en_US
Z:\USER\dict_data\Software\Hunspell\share\hunspell/es
Z:\USER\dict_data\Software\Hunspell\share\hunspell/hyph_es
LOADED DICTIONARY:
Z:\USER\dict_data\Software\Hunspell\share\hunspell/es.aff
Z:\USER\dict_data\Software\Hunspell\share\hunspell/es.dic
brownts commented 1 month ago

Although this issue is closed, I didn't see any resolution on it. I installed jinx over the weekend and ran into this issue. I was however able to work around the issue. The following are the steps I took.

I installed the necessary packages in MSYS2 (enchant, Aspell English dictionary, etc.):

pacman -S mingw-w64-x86_64-pkg-config
pacman -S mingw-w64-x86_64-enchant
pacman -S mingw-w64-x86_64-aspell-en
pacman -S mingw-w64-x86_64-gcc

Added the binary directory to the path: C:/msys64/mingw64/bin

With all of this in place, I was able to successfully compile jinx-mod.c but had the same issue as those above where no dictionaries were detected. With some experimenting I was able to determine that the DLLs in the mingw64/bin directory were being located correctly, but it appeared those libraries couldn't find the other libraries and data they use in the "lib" directory (i.e., C:/msys64/mingw64/lib). I'm not sure if it's a relocation issue or difference in paths between Windows and MSYS2, but it does work if you add the "lib" directories to your emacs installation (it will find the "lib" directory relative to your emacs executable's "bin" directory). I therefore symlinked the enchant and aspell (you may need to do this for other spell checkers if you use them) "lib" directories into my emacs installation and then it correctly found the dictionaries.

mklink /D C:\emacs\29.2\lib\aspell-0.60 C:\msys64\mingw64\lib\aspell-0.60
mklink /D C:\emacs\29.2\lib\enchant-2 C:\msys64\mingw64\lib\enchant-2

msys2/MINGW-packages#11443 seems to be describing this issue too along with confirming that it works relative to your executable location.