Skeleton237 · 2022-06-12 21:27
I am trying to set up hunspell for brazilian portuguese and I can't make it work.
When I run hunspell -d pt\_BR in a terminal it works properly, but inside emacs everytime I try to run flyspell mode I get the following error:
`Can’t find Hunspell dictionary with a .aff affix file`
​
I have tried everything on the following code snippet and nothing seems to work:
`(ispell-change-dictionary "pt_BR")`
`(setenv`
`"DICPATH"`
`(concat (getenv "HOME") "/Library/Spelling"))`
`(setq ispell-program-name "hunspell")`
`(setq ispell-local-dictionary "pt_BR")`
`(add-to-list`
`'ispell-local-dictionary-alist`
`'(("pt_BR" "[[:alpha:]]" "[^[:alpha]]" "[0-9']" t`
`("-d" "pt_BR") nil utf-8)))`
`(setq ispell-local-dictionary-alist`
`'(("pt_BR" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil nil nil utf-8)))`
​
My dictionary is located at $HOME/Library/Spelling/
​
Thanks in advance for the help.
rbslco · 2022-06-13 06:28
I had to mess around with flyspell myself before I finally got it working. It wasn’t a pleasant experience. From my notes, this is what worked for me on Arch, and still works on Debian, for English and Croatian languages.
First step was to actually install hunspell and the dictionaries. At the time, Arch didn’t have dictionaries for Croatian language, which is why I had to download them manually and copy them to the default hunspell dictionary location. Command `hunspell -D` showed me that the default location for dictionaries on my system was `/usr/share/hunspell` and thus I copied *hr_HR.aff* and *hr_HR.dic* files there. Keeping the dictionaries on a custom location didn’t work for me for some reason I can’t recall.
Below is my current working code.
(setq-default ispell-program-name "hunspell")
(setq ispell-local-dictionary-alist
'(("hr_HR" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "hr_HR") nil utf-8)
("en_GB" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_GB") nil utf-8)
))
(setq ispell-local-dictionary "hr_HR")
(setq ispell-current-dictionary "hr_HR")
(setq ispell-personal-dictionary "~/.emacs.d/misc/aspell.hr.pws")
(defun fd-switch-dictionary()
(interactive)
(let* ((dic ispell-current-dictionary)
(change (if (string= dic "hr_HR") "en_GB" "hr_HR")))
(ispell-change-dictionary change)
(message "Dictionary switched from %s to %s" dic change)
))
(global-set-key (kbd "<C-f7>") 'fd-switch-dictionary)
(global-set-key (kbd "<f7>") 'flyspell-mode)
(global-set-key (kbd "<M-f7>") 'flyspell-buffer)
redguardtoo · 2022-06-13 08:29
You could use below line to tell hunspell to check two dictionaries in one shot.
```
(setq ispell-local-dictionary-alist
'(("hr_HR" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "hr_HR,en_GB") nil utf-8)
))
rbslco · 2022-06-13 09:42
Thank you.
Skeleton237 · 2022-06-13 11:29
Thanks for your answer. It still does not work, I keep getting the same error. I moved the dictionary to the default hunspell dictionary location and tried your code (with the needed modifications for the languange). The weird part is that hunspell can find the dictionary when I call it through the terminal with `hunspell -d pt_BR` but somehow inside emacs it simply cannot find it. If it matters, my emacs version is 29.0.50 and I', also using arch.
redguardtoo · 2022-06-13 11:50
Delete all you own code, try below minimum setup,
```lisp
(setq ispell-program-name "hunspell")
(setq ispell-local-dictionary "pt_BR")
(setq ispell-local-dictionary-alist '(("pt_BR" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "pt_BR") nil utf-8)))
(setq ispell-hunspell-dictionary-alist ispell-local-dictionary-alist)
```
To test if you setup is working, run `M-x flyspell-buffer`.
Skeleton237 · 2022-06-13 12:43
Ok, I tried it on emacs -q and it actually worked, so something in my config is breaking it. Thanks a lot! I will now try to figure out what is wrong with my config.
​
Edit: This actually worked out of the box on my config for some reason, I simply do not know what was the problem before then. Thanks!
E3D3redit · 2022-06-13 14:48
Removing my personal dictionary solved my long struggling with spellcheck configuration. It seemed that my file used an old/depreciated format. Maybe this is something to try.