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

Suppress unmap errors at undo_ftplugin #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

grauwoelfchen
Copy link

This pull request suppresses errors relate to unmappings at unloading of this plugin.

The nmap/vmap both are currently set only if those mappings aren't set yet by others (with chesk of maparg(...) at L44 and L63). So, if these buffer local mappings are not set (I had another mapping for K), then errors like below occur when b:undo_ftplugin is evaluated, since they don't exist.

Error detected while processing BufRead Autocommands for "*.rkt"..function <SNR>55_RacketDetectHashLang[3]..FileType Autocommands 
for "*"..function <SNR>20_LoadFTPlugin:
line    3:
E31: No such mapping

I suppose these errors would be harmless (because buffer local mappings does not exist), but a bit annoying, so I've simply added silent! at here 😄

This change is needed because nmap/vmap are both conditionally set only if
those mappings aren't set yet by others. So, if these buffer local mappings are
not set, then an error occurs on unloading of this plugin, since they don't
exist. Let's suppress them.
@grauwoelfchen
Copy link
Author

I found this during an investigation of another issue at purescript-contrib/purescript-vim#91, because this unloading part seems to be unexpectedly? evaluated due to that when I just opened a Racket file.

@benknoble
Copy link
Contributor

Something similar is already achieved in https://github.com/benknoble/vim-racket/blob/1c02b65f30d01eb05049e0a3f1d7ddb84658457c/ftplugin/racket.vim#L64 which ships with latest Vim. I don't remember why execute is necessary but I'm fairly confident it is (possibly to do with separating from the commands that come after).

@grauwoelfchen
Copy link
Author

That's nice!

Speaking of execute, I also had an experiment unmapping them conditionally with if like below. Maybe that's a bit wordy, but it somehow worked even without silent!. This version didn't work without using those exucutes 🤔

let b:undo_ftplugin =
      \  "setl iskeyword< lispwords< lisp< comments< formatoptions<"
      \. "| setl makeprg< commentstring<"
      \. "| if maparg('K', 'n') ==# '<Plug>RacketDoc' \| execute 'nunmap <buffer> K' \| endif"
      \. "| if maparg('K', 'v') ==# '<Plug>RacketDoc' \| execute 'vunmap <buffer> K' \| endif"

Anyway, I agree with that. That would fairly be better to have it in a string for clear separation.
So I'll add executes here too. Thanks 🙋🏽‍♀️

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

Successfully merging this pull request may close these issues.

2 participants