paradigm / SkyBison

Vim plugin to expedite use of cmdline commands
73 stars 9 forks source link

SkyBison fails to call :nohlsearch #17

Open alpha123 opened 10 years ago

alpha123 commented 10 years ago

Steps to reproduce:

For some reason, it fails to un-highlight the search. :nohl works just fine from ex mode, so I assume SkyBison fails to actually call the command somehow.

jamessan commented 10 years ago

Isn't this just the fact that :nohl has no effect when called in a function? Although, adding

if a:cmdline =~# '^[: ]*noh\%[lsearch]'
    let v:hlsearch = 0
endif

to s:RunCommandAndQuit doesn't help either. I did notice something else while looking at this. I'll file an issue for that.

paradigm commented 10 years ago

I was not able to come up with any way to effectively do :nohl in a function. As :help :nohl points out, autocmds are also not a viable solution. Trying to do it indirectly with something like v:hlsearch doesn't work either, as jamessan pointed out. However, SkyBison only really runs into this at the very end of what it does. We can leverage feedkeys() to run something after SkyBison's function ends. For example, change line 31 (execute a:cmdline) in the current version to:

call feedkeys(":") . a:cmdline . "\<cr>", "n")

The "n" flag is necessary for situations such as alpha123's so it does not call SkyBison again.

I've been bitten in the past by using feedkeys() without fully thinking things through, so I don't want to jump to doing this without some thought and experimentation. However, a quick test with the instructions above seems to work. Some potential issues with this:

While I think this is a terrible idea, another avenue which might work is to make SkyBison a :command instead of a function under-the-hood. A really long, ugly command with lots of pipes that heavily abuses :execute. I'd like to exhaust options like feedkeys() before pursuing this, but it may be worth mentioning and thinking about.