bounceme / poppy.vim

vim port of highlightparentheses.el
25 stars 2 forks source link

Make it easier to add a mapping to toggle poppy state #1

Closed anntzer closed 7 years ago

anntzer commented 7 years ago

Thanks for your quick reply to my question on reddit :-)

I can add a mapping to switch poppy on with e.g.

nmap <leader>hp :au! CursorMoved * call PoppyInit()<cr>

but it would be even better if I could have the same mapping toogle it on and off. Thoughts?

bounceme commented 7 years ago

all I can think of tonight, untested:

let g:Poppy = -1
nmap <leader>hp :let g:Poppy = -g:Poppy \| exe 'au! CursorMoved *' . (g:Poppy>0 ? ' call PoppyInit()' :  '')<cr>

you may need to make a augroup or function

bounceme commented 7 years ago

sorry, now above is working. you should use a augroup with that mapping to not remove other plugins autocmds

anntzer commented 7 years ago

The example you give is not working, because the | need to be replaced by <bar>. But your suggestion led me to

augroup Poppy | autocmd! CursorMoved | augroup END
nmap <silent> <leader>hp :let g:poppy = -g:poppy <bar> exe 'au! Poppy CursorMoved *' . (g:poppy > 0 ? ' call PoppyInit()' : '') <cr>

which is nearly working.

A minor remaining issue is that turning off poppy-mode in such a way does not clear the currently highlighted parentheses.

bounceme commented 7 years ago

just add a call to clearmatches() or filter the w:poppies variable, calling matchdelete()

bounceme commented 7 years ago
augroup Poppy | autocmd! CursorMoved | augroup END
nmap <silent> <leader>hp :call clearmatches() \| let g:poppy = -g:poppy \| exe 'au! Poppy CursorMoved *' . (g:poppy > 0 ? ' call PoppyInit()' : '') <cr>