priner / micro-aspell-plugin

Spellchecker plugin for Micro editor
MIT License
15 stars 5 forks source link

Support for multiple simultaneous dictionaries? #7

Closed flber closed 3 years ago

flber commented 3 years ago

This is more of a feature request than an issue, but it would be fantastic if support for multiple simultaneous dictionaries were added. I often find myself writing in more than one language in a single file, which results in lots of "misspelled" words. I know that aspell supports this through the use of the --extra-dicts option, and it would be very useful to have that implemented in this plugin. If not I'd be happy to take a look into implementing it myself, but I figured I should bring it up first. Any help would be appreciated!

priner commented 3 years ago

You can already pass arbitrary options to Aspell from this plugin with aspell.args setting.

But unfortunately it seems that Aspell doesn't support multiple languages with --extra-dicts GNUAspell/aspell/issues/448, the --extra-dicts options only works if both dictionaries are from the same language, e.g. American/British english or something like that.

One possible solution for you could be to make your own multi-language dictionary https://unix.stackexchange.com/questions/341714/use-multi-language-dictionary-with-aspell.

Theoretically the plugin could call Aspell twice with different languages and then try to merge them somehow, but I don't think it's a good idea. How would you merge suggestions? What if the reported misspells don't line up? (this can happen when the word contains apostrophes)? I don't think this is the way to go.

Hunspell can do this (it takes comma separated list of dictionaries instead of just one), and it wouldn't be hard to modify this plugin to work with it instead of Aspell, the output has the exact same format. The command line options have all slightly different names but that's pretty much it. There are three reasons why I chose Aspell when I made this plugin, it's significantly faster, it handles apostrophes better and it has markdown mode (especially the markdown mode).

It might be worthwhile to make it a configurable option to use Hunspell, some also say that it gives better suggestions. Leaving it to the user to make the trade-off themselves seems like the right way to me. I unfortunately named this plugin "aspell-plugin" which will be quite confusing if it'll support both, but whatever. Anyway I am not going to do that myself in the near future, as I'm quite busy now. Feel free to take a look into it if you want.

flber commented 3 years ago

Hmm, interesting. It seems as though the least complicated solution might be to do the equivalent of cat document.txt | aspell --lang=en list | aspell --lang=nb list | sort -u, which first checks a document, then passes the list of misspelled words to another language, and finally returns that list. However, it's been a while since I've written Lua, so I'm still unsure how I'd implement that... We'll see how it goes though, and I'll submit a pull request if I get something working.

flber commented 3 years ago

Ah well. The way I'm doing it now is that mildly hacky method of joining two dictionaries, which works okay. As I don't have a better solution for the time being, I'll mark this as closed.