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

SkyBison fails to call :nohlsearch #17

Open
alpha123 opened this issue Apr 24, 2014 · 2 comments
Open

SkyBison fails to call :nohlsearch #17

alpha123 opened this issue Apr 24, 2014 · 2 comments

Comments

@alpha123
Copy link

Steps to reproduce:

  • Install SkyBison (duh).

  • Add

    nnoremap : :<C-u>call SkyBison("")<CR>
    

    to your vimrc.

  • Reload your vimrc.

  • Use / to search for something.

  • Type :nohl (or :nohlsearch).

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
Copy link
Contributor

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
Copy link
Owner

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:

  • Can anyone think of a way that the "n" flag would keep SkyBison from using
    some mapping the user would want? I tried stuff like calling :normal with
    stuff I have mapped in a feedkeys with and without "n" but it seems to act
    the same.
  • Can anyone think possible user input which would result in an infinite loop,
    even with the "n" flag?

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.

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

No branches or pull requests

3 participants