greduan
greduan

Reputation: 4938

VimL: Function to cancel loading of plugin

Maybe the question title is not too specific. So let me explain:

This is for this GitHub fork, for the numbertoggle Vim plugin. Please check the structure of my fork, to understand what I mean.

What I need is a way to deactivate it, after it's been loaded. In other words, completely erase it off the charts if that function is called.

In other, other words. If the plugin is called, and I do :call NumberToggleOff() then it will disable it and act as Vim would normally function.

What would be a good way to achieve this? I've tried several methods, but none works.

Thanks for your help!

Upvotes: 0

Views: 119

Answers (1)

ZyX
ZyX

Reputation: 53604

Normally it can be done by surrounding autocommands by

augroup NumberToggle
    …
augroup END

and remembering {lhs} of the mapping. To disable it you then do

let s:plugin_lhs=exists('g:NumberToggleTrigger') ? g:NumberToggleTrigger : '<C-n>'
let g:numbertoggle={}
function! g:numbertoggle.unload()
    augroup NumberToggle
        autocmd!
    augroup END
    augroup! NumberToggle
    execute 'nunmap' s:plugin_lhs
    delfunction NumberToggle
    delfunction UpdateMode
    delfunction FocusGained
    delfunction FocusLost
    delfunction InsertLeave
    delfunction InsertEnter
    unlet g:numbertoggle
    unlet g:loaded_numbertoggle
    unlet g:insertmode g:focus
    unlet s:plugin_lhs
endfunction
" Then do :call g:numbertoggle.unload()
" Loading is done by resourcing numbertoggle

It would be much better if instead of using a bunch of delfunction calls you convert all function names to g:numbertoggle.toggle, g:numbertoggle.update, … and just leave unlet g:numbertoggle.

It completely undoes effect of the plugin, not just disables it.

Upvotes: 2

Related Questions