wilder.nvim icon indicating copy to clipboard operation
wilder.nvim copied to clipboard

python_search: bad escape \z at position 4

Open jdhao opened this issue 3 years ago • 3 comments

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.

jdhao avatar Nov 22 '21 08:11 jdhao

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.

gelguy avatar Dec 03 '21 00:12 gelguy

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.

jdhao avatar Dec 03 '21 02:12 jdhao

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 ...
      \ }))

gelguy avatar Dec 04 '21 14:12 gelguy