gelguy / wilder.nvim

A more adventurous wildmenu
MIT License
1.36k stars 34 forks source link

python_search: bad escape \z at position 4 #108

Open jdhao opened 2 years ago

jdhao commented 2 years ago

Using the following config:

    call wilder#enable_cmdline_enter()
    set wildcharm=<Tab>
    cmap <expr> <Tab> wilder#in_context() ? wilder#next() : "\<Tab>"
    cmap <expr> <S-Tab> wilder#in_context() ? wilder#previous() : "\<S-Tab>"

    " only / and ? are enabled by default
    call wilder#set_option('modes', ['/', '?', ':'])

Then type /foo\zs, we get the following error/warning message from wilder.nvim:

python_search: bad escape \z at position 4

Note that \zs and \ze are both valid vim regex expressions.

gelguy commented 2 years ago

Apologies for the delay!

This technically isn't a bug - wilder#python_search_pipeline() expects the pattern to be a PCRE2 pattern. I don't attempt to do any translation of Vim's escaped characters/matched groups into PCRE2 the regex syntaxes are not 100% compatible - e.g. there are no corresponding \zs and \ze atoms for PCRE2.

It's possible to adjust the input before passing it to the pipeline:

call wilder#set_option('pipeline', [
      \   wilder#branch(
      \     ... other branches ...
      \     [{ctx, input -> substitute(input, '\\zs\|\\ze\|\\z', '', 'g')}] + wilder#python_search_pipeline({
      \       ... options ...
      \     }),
      \   ),
      \ ])

There's https://github.com/othree/eregex.vim which translates PCRE2 -> Vim, but I don't think there is one of the other direction.

jdhao commented 2 years ago

Thanks for the reply! I always thought that wilder.nvim is a replacement for the original search and command of vim. In the above cases, maybe wilder.nvim should catch and silently ignore the errors and forward the search to builtin features? That way the user won't notice any errors or warnings.

gelguy commented 2 years ago

The normal search features of Vim/Neovim will still work despite the error shown for wilder e.g. incsearch will continue working as normal, just that there will be no suggestions from wilder.

To hide the error message on the wildmenu, you can change the highlight group:

hi! Empty guifg=<guibg of StatusLine>
call wilder#set_option('renderer', wilder#wildmenu_renderer({
      \ 'highlights': {'error': 'Empty'},
      \ ... other options ...
      \ }))