potamides / pantran.nvim

Use your favorite machine translation engines without having to leave your favorite editor.
MIT License
289 stars 2 forks source link

setting default engine not working #2

Closed abenz1267 closed 2 years ago

abenz1267 commented 2 years ago

Hi,

i realized that setting the default_engine is not working anymore.

if has('pantran') then
    require('pantran').setup {
        default_engine = 'deepl', -- https://github.com/potamides/pantran.nvim/blob/main/doc/README.md does not have it under the "engines" key
        engines = {
            default_engine = 'deepl', -- github readme puts it here in the example
            deepl = {
                free_api = true
            }
        }
    }
end

Regards

potamides commented 2 years ago

Hi,

thanks for reporting this! The way the docs describe it should be the way to configure it, the readme (and the implementation) are wrong here. I'll fix that soon. That being said, your snippet should actually work. This minimal configuration works for me, where exactly do you experience issues?

require('pantran').setup{
    engines = {
        default_engine = 'deepl'
    }
}
abenz1267 commented 2 years ago

Hi,

i tested this both on neovim stable and nightly. I can select deepl via ge just fine. But the default engine setting doesn't work. I'm on Arch Linux if that matters.

Regards

potamides commented 2 years ago

Very strange. Could you share your config with me?

abenz1267 commented 2 years ago

Sure: https://github.com/abenz1267/nvim/blob/master/lua/utility/pantran.lua

potamides commented 2 years ago

I think this happens because you make pantran.nvim an optional package which only gets loaded when you invoke :Pantran. Because of this the guard has("pantran") fails as this hasn't happened yet and your setup code isn't called. When you replace

table.insert(PKGS, { 'potamides/pantran.nvim', cmd = 'Pantran' })

with

table.insert(PKGS, { 'potamides/pantran.nvim' })

does it work?

abenz1267 commented 2 years ago

If i make it a non-optional package, i get this error:

                     Error detected while processing /home/andrej/.local/share/nvim/site/pack/packer/start/pantran.nvim/plugin/pantran.vim:                 
line   18:                                                                                                                                                  
E174: Command already exists: add ! to replace it: Pantran lua require("pantran.command").parse(<line1>, <count>, unpack{<f-args>}) 
potamides commented 2 years ago

If i make it a non-optional package, i get this error:

This means that something defines the :Pantran command before the plugin itself is loaded.

In the end it wouldn't make much sense if it did, because WHEN the package gets loaded should be irrelevant for the default engine.

Yes that is true but I think the problem is not when it is loaded but that the setup code is not called because it is run when the plugin is not yet on the path and thus has('pantran') fails. When you make it optional could you run :lua =has("pantran"), then :Pantran, and then again :lua =has("pantran")? If I am not mistaken it should print false and then true

abenz1267 commented 2 years ago

If i make it a non-optional package, i get this error:

This means that something defines the :Pantran command before the plugin itself is loaded.

In the end it wouldn't make much sense if it did, because WHEN the package gets loaded should be irrelevant for the default engine.

Yes that is true but I think the problem is not when it is loaded but that the setup code is not called because it is run when the plugin is not yet on the path and thus has('pantran') fails. When you make it optional could you run :lua =has("pantran"), then :Pantran, and then again :lua =has("pantran")? If I am not mistaken it should print false and then true

Thank you a lot man, that's a general flaw in my config. I removed the plugin folder and deleted the packer one, re-installed everything and it works.

abenz1267 commented 2 years ago

btw, shouldn't lazy loading pantran work? I mean, it's not something you use often, so it'd be a perfect candidate for lazy loading, wouldn't it be? I have this now:

table.insert(PKGS, { 'potamides/pantran.nvim', opt = true, cmd = { 'Pantran' }, config = function()
    require('pantran').setup {
        engines = {
            default_engine = 'deepl',
            deepl = {
                free_api = true
            }
        }
    }
end })

Pantran loads, default_engine not.

abenz1267 commented 2 years ago

Hm, i just made it a non optional package, lua =has("pantran") reports true on initial start, default engine is wrong. i don't understand XD

Edit: i realized you updated the initialization of the default engine. fixed.

potamides commented 2 years ago

i realized you updated the initialization of the default engine. fixed.

Okay perfect! Btw, free_api = true is the default so you don't necessarily need to specify it explicitly.