Reverse ability stopped working
Closed this issue ยท 4 comments
Reverse ability stopped working after #bb71ada.
Did I miss something since last update? ๐
Example
let g:switchQuotes = [
\ {
\ '''\(.\{-}\)''': '"\1"',
\ '"\(.\{-}\)"': '''\1''',
\ '`\(.\{-}\)`': '''\1'''
\ }
\]
" old
nnoremap <silent> ! :<C-u>silent! call switch#Switch(g:switchQuotes, {'reverse': 1})<CR>
" new (?)
nnoremap <silent> ! :<C-u>silent! call switch#Switch({'definitions': g:switchQuotes}, {'reverse': 1})<CR>
Result
Quotes are changed once and the pattern/mapping completely stops working.
PS. Please, add silent
to switch#Switch
by default. Thank you for such a useful plugin!
Yes, there was an API change in the switch#Switch
usage. I'm sorry it wasn't communicated better, but I couldn't think of how to do that, and didn't know if it would even affect many people :).
I added some more documentation on the function in "advanced usage", so maybe that will help people figure it out. In your case, the way you would use the new mapping is:
nnoremap <silent> ! :<C-u>silent! call switch#Switch({'definitions': g:switchQuotes, 'reverse': 1})<CR>
Bear in mind, though, reversing would never work with this particular definition anyway. I explain this in more detail here, if you'd like to read about it: #42 (comment)
It would be a good idea to remove the silent!
in the front of the function as well. The <silent>
on the mapping should be enough. If nothing else, you should use silent
instead of silent!
, because the bang version also hides any errors. This means that, instead of immediately getting an error with a backtrace, the plugin would just seem to "not work", and that can be harder to debug.
I've added a <silent>
on the default mapping, it's a good point. Could you check if it works as you expected it to?
Thanks for the quick reply.
I use the silent
flag to hide the message: "1 substitution on 1 line". (<silent>
won't help here)
{'definitions': g:switchQuotes, 'reverse': 1}
I've already tried this and got the same result, but now I removed silent
flag:
Error detected while processing function switch#Switch[18]..switch#util#FlatMap[3]..switch#mapping#Process[2]..<SNR>64_ProcessListMapping:
line 11:
E15: Invalid expression: '\C\V'.first.'\m'
first
{'Replace': function('switch#mapping#Replace'), 'Match': function('switch#mapping#Match'), 'definitions': {'"\(.\{-}\)"': '''\1'''}}
Ah, found it now. Sorry, I should have tested the change better. It was a matter of an object being mutated accidentally. I pushed a fix.
I don't get the "1 substitution on 1 line" message, but it might be a matter of settings. I've added the silent
on the built-in call to switch#Switch()
. Could you check to see if this fixes the issue for you?
(imho) silent
is only needed here.
Now everything works fine.
Thank you for taking care!