Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key not present in dictionary #41

Open
tommyknows opened this issue Jul 6, 2020 · 7 comments
Open

Key not present in dictionary #41

tommyknows opened this issue Jul 6, 2020 · 7 comments

Comments

@tommyknows
Copy link

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:

if g:gopher_map['_popup']

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!

@arp242
Copy link
Owner

arp242 commented Jul 6, 2020

Not sure why this is happening, it should always be added from the defaults here:

let l:settings = {

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.

@tommyknows
Copy link
Author

tommyknows commented Jul 6, 2020

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.

@arp242
Copy link
Owner

arp242 commented Jul 7, 2020

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.

@tommyknows
Copy link
Author

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

@arp242
Copy link
Owner

arp242 commented Jul 7, 2020

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.

@tommyknows
Copy link
Author

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 😄

@arp242
Copy link
Owner

arp242 commented Jul 7, 2020

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 arp242 reopened this Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants