ctrlpvim / ctrlp.vim

Active fork of kien/ctrlp.vim—Fuzzy file, buffer, mru, tag, etc finder.
ctrlpvim.github.com/ctrlp.vim
Other
5.57k stars 259 forks source link

`g:ctrlp_match_func` doesn't look correct work. #553

Closed na0x2c6 closed 3 years ago

na0x2c6 commented 3 years ago

Thank you for the great plugin.

If g:ctrlp_match_func is set, the prefix will concatenate to the file names in the list repeatedly.

Example:

function! Hoge(items, str, limit, mmode, ispath, crfile, regex)
    return a:items
endfunction

let g:ctrlp_match_func = {'match' : 'Hoge' }

The above script means that any pattern matches any file.

Result: using-ctrlp_match_func

So, I cannot open the correct file but new file which has unnecessary prefix.

I use Vim v8.2.1704 on MacOS. Thanks.

mattn commented 3 years ago

You should use copy

function! Hoge(items, str, limit, mmode, ispath, crfile, regex)
    return copy(a:items)
endfunction
na0x2c6 commented 3 years ago

@mattn Thank you for your fast response.

Actually, What I really want to do is to use migemogrep according to this article: https://vim-jp.org/blog/2014/08/08/dropped-migemo-from-ctrlp-vim.html

Now, my code is:

function! MigemoMatch(items, str, limit, mmode, ispath, crfile, regex)
  let tmp = tempname()
  try
    if a:str =~ '^\s*$'
      return a:items
    endif
    call writefile(split(iconv(join(a:items, "\n"), &encoding, 'utf-8'), "\n"), tmp)
    return copy(split(iconv(system(
    \  printf('migemogrep %s %s',
    \    shellescape(a:str),
    \    shellescape(tmp))), 'utf-8', &encoding), "\n"))
  catch
    return []
  finally
    call delete(tmp)
  endtry
endfunction
let g:ctrlp_match_func = {'match' : 'MigemoMatch' }

But, ONE prefix still is concatenated to file names: one-prefix

mattn commented 3 years ago

Please try this.

function! MigemoMatch(items, str, limit, mmode, ispath, crfile, regex)
  let tmp = tempname()
  try
    if a:str =~ '^\s*$'
      return copy(a:items)
    endif
    call writefile(split(iconv(join(a:items, "\n"), &encoding, 'utf-8'), "\n"), tmp)
    return split(iconv(system(
    \  printf('migemogrep %s %s',
    \    shellescape(a:str),
    \    shellescape(tmp))), 'utf-8', &encoding), "\n")
  catch
    return []
  finally
    call delete(tmp)
  endtry
endfunction
let g:ctrlp_match_func = {'match' : 'MigemoMatch' }
na0x2c6 commented 3 years ago

Ohhhh, completely worked. Thank you!!!

mattn commented 3 years ago

👍