gopher.vim icon indicating copy to clipboard operation
gopher.vim copied to clipboard

Key not present in dictionary

Open tommyknows opened this issue 5 years ago • 7 comments

Hi,

When opening a second .go file, I get the error message:

Key not present in Dictionary: _popup

This is caused by the code here: https://github.com/arp242/gopher.vim/blob/8934106626845fcb06bdd8dbc6a18d657af1c073/ftplugin/go.vim#L94

And the issue is fixed by uncommenting the specified line (obviously not a real solution).

Not quite sure if this is something related to my config / setup or an actual bug in the code. I'd be happy to provide any information necessary to debug this further.

Thanks!

tommyknows avatar Jul 06 '20 11:07 tommyknows

Not sure why this is happening, it should always be added from the defaults here: https://github.com/arp242/gopher.vim/blob/8934106626845fcb06bdd8dbc6a18d657af1c073/autoload/gopher/init.vim#L79

Did you configure g:gopher_map in your vimrc file? And which Vim version are you using? You can get an overview of all settings and some other useful information with :GoDiag (and :GoDiag! to copy to clipboard, if your Vim build supports it) inside a ft=go buffer; it would be helpful if you could add that information, and I can take a further look.

arp242 avatar Jul 06 '20 17:07 arp242

Thanks for the quick help! With the help of :GoDiag, I was able to figure out that the key is present when opening the first file, but gone when opening the second.

This has led me to investigate my gopher_map setting, which I actually change! The issue is that I changed the g:gopher_map by setting:

let g:gopher_map = {'_nmap_prefix': '<Leader>', '_imap_prefix': '<C-g>' }

in my ~/.vim/ftplugin/go.vim file.

This somehow works (e.g. this gets merged with the default values) when opening the first file, but overwrites everything when opening the second file... Is that because the plugin is not loaded again, while the ftplugin/go.vim is?

BTW: Using vim 8.2.

Thanks again!

Edit: it works when i set the specific keys in the dict instead of setting the whole dict.

tommyknows avatar Jul 06 '20 18:07 tommyknows

Hm, I can't reproduce it by adding that g:gopher_map setting; everything seems to work as expected. Which sequence of commands are you using exactly? Perhaps I'm doing something different? It might also help share your complete settings.

arp242 avatar Jul 07 '20 00:07 arp242

I'm able to "reproduce" it by adding the line:

let g:gopher_map = {'_nmap_prefix': '<Leader>', '_imap_prefix': '<C-g>' }

to my ~/.vim/ftplugin/go.vim file.

It works fine when using ~/.vimrc instead. What seems to be the takeaway here (and the explanation I currently think is correct): When opening the first .go file, the plugin (through ~/.vimrc)and the g:gopher_map setting (through ftplugin/go.vim) get loaded. When opening the second file, because the filetype is go again, it reloads ftplugin/go.vim (for the current buffer) which then overwrites the g:gopher_map setting.

This can be fixed by either:

  • adding the g:gopher_map setting to ~/.vimrc instead, it works as expected as it only gets loaded once when opening vim.
  • only overwriting specific keys by using let g:gopher_map._nmap_prefix = '<Leader>' instead

tommyknows avatar Jul 07 '20 05:07 tommyknows

Ah right; checking for existence before (re-)defining it should work too I think:

if !exists('g:gopher_map')
    let g:gopher_map = [..]
endif

I can look at making this more predictable; one thing I've been wanting to do is have buffer-local overrides for all the config settings, which requires changing the way this works anyway.

arp242 avatar Jul 07 '20 05:07 arp242

Adding the above code snippet (with the adjusted assignment) doesn't work - it seems like the variable already exists when loading the syntax file.

Nevertheless, with let g:gopher_map._nmap_prefix = '<Leader>' I found a solution that is more than good enough for me! Thanks for your help 😄

tommyknows avatar Jul 07 '20 05:07 tommyknows

Cheers, glad the immediate issue is solved for you.

I'll re-open this because it's something I do want to make sure gets fixed. You can unsubscribe if you don't any any further notifications 😅

arp242 avatar Jul 07 '20 06:07 arp242