Shougo / unite.vim

:dragon: Unite and create user interfaces
http://www.vim.org/scripts/script.php?script_id=3396
Other
2.85k stars 223 forks source link

file_rec/git does not respect ignore_pattern and ignore_globs #886

Closed laishulu closed 9 years ago

laishulu commented 9 years ago
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 23 2014 10:43:45)
MacOS X (unix) version
Included patches: 1-258
Compiled by Homebrew
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +cmdline_info    +emacs_tags      -gettext         +lua             +mouse_urxvt     +profile         +statusline      +transparency    -X11
+arabic          +comments        +eval            -hangul_input    +menu            +mouse_xterm     +python          -sun_workshop    +user_commands   -xfontset
+autocmd         +conceal         +ex_extra        +iconv           +mksession       +multi_byte      -python3         +syntax          +vertsplit       +xim
+balloon_eval    +cryptv          +extra_search    +insert_expand   +modify_fname    +multi_lang      +quickfix        +tag_binary      +virtualedit     -xsmp
+browse          +cscope          +farsi           +jumplist        +mouse           -mzscheme        +reltime         +tag_old_static  +visual          -xterm_clipboard
++builtin_terms  +cursorbind      +file_in_path    +keymap          +mouseshape      +netbeans_intg   +rightleft       -tag_any_white   +visualextra     -xterm_save
+byte_offset     +cursorshape     +find_in_path    +langmap         +mouse_dec       +odbeditor       +ruby            +tcl             +viminfo         -xpm
+cindent         +dialog_con_gui  +float           +libcall         -mouse_gpm       +path_extra      +scrollbind      +terminfo        +vreplace
+clientserver    +diff            +folding         +linebreak       -mouse_jsbterm   +perl            +signs           +termresponse    +wildignore
+clipboard       +digraphs        -footer          +lispindent      +mouse_netterm   +persistent_undo +smartindent     +textobjects     +wildmenu
+cmdline_compl   +dnd             +fork()          +listcmds        +mouse_sgr       +postscript      -sniff           +title           +windows
+cmdline_hist    -ebcdic          +fullscreen      +localmap        -mouse_sysmouse  +printer         +startuptime     +toolbar         +writebackup
" Your vimrc
set nocompatible
set runtimepath+=~/.vim/bundle/neobundle.vim/
set wildignore=*.o,*.obj,*.la,*.lo,*.so,*.pyc,*.pyo,*.jpg,*.png,*.gif

      call unite#custom#source('file_rec/git', 'ignore_globs',
          \ split(&wildignore, ','))

      let dot = '\%(^\|/\)\.'
      let dirs = '\%(^\|/\)\%(' . join(
            \ ['node_modules', 'bower_components', 'dist'], '\|')
            \ . '\)\%($\|/\)'
      let files = join(['\.pyc\%($\)'], '\|')
      let pattern = join([dot, dirs, files], '\|')
      call unite#custom#source('file_rec/git', 'ignore_pattern', pattern)
Shougo commented 9 years ago

OK. I will check it. But... Please read the issue template.

https://github.com/Shougo/unite.vim/issues/584

Shougo commented 9 years ago

Unfortunatelly, I cannot reproduce the problem. ignore_globs working. But, Yes old version has problems. Please upload unite.vim version.

laishulu commented 9 years ago

  " Note: Skip initialization for vim-tiny or vim-small.
  if !1 | finish | endif

  if has('vim_starting')
    set nocompatible               " Be iMproved

    " Required:
    set runtimepath+=~/.vim/bundle/neobundle.vim/
  endif

  " Required:
  call neobundle#begin(expand('~/.vim/bundle/'))

  " Required:
  call neobundle#begin(expand('~/.vim/bundle/'))

  " Let NeoBundle manage NeoBundle
  " Required:
  NeoBundleFetch 'Shougo/neobundle.vim'

  " My Bundles here:
  " Refer to |:NeoBundle-examples|.
  " Note: You don't set neobundle setting in .gvimrc!

  call neobundle#end()

  " Required:
  filetype plugin indent on

  " If there are uninstalled bundles found on startup,
  " this will conveniently prompt you to install them.
  NeoBundleCheck

  NeoBundle 'Shougo/vimproc.vim', {
        \  'build' : {
        \    'windows' : 'make -f make_mingw32.mak',
        \    'cygwin' : 'make -f make_cygwin.mak',
        \    'mac' : 'make -f make_mac.mak',
        \    'unix' : 'make -f make_unix.mak',
        \  },
        \}
  NeoBundle 'Shougo/unite.vim' "{{{
    let bundle = neobundle#get('unite.vim')
    function! bundle.hooks.on_source(bundle)
      call unite#filters#matcher_default#use(['matcher_fuzzy'])
      call unite#filters#sorter_default#use(['sorter_rank'])
      call unite#custom#profile('files', 'context.smartcase', 1)
      call unite#custom#source('line,outline','matchers',['matcher_fuzzy'])

      set wildignore=*.o,*.obj,*.la,*.lo,*.so,*.pyc,*.pyo,*.jpg,*.png,*.gif
      call unite#custom#source('file_rec/git', 'ignore_globs',
          \ split(&wildignore, ','))

      let dot = '\%(^\|/\)\.'
      let dirs = '\%(^\|/\)\%(' . join(
            \ ['node_modules', 'bower_components', 'dist'], '\|')
            \ . '\)\%($\|/\)'
      let files = join(['\.pyc\%($\)'], '\|')
      let pattern = join([dot, dirs, files], '\|')
      call unite#custom#source('file_rec/git', 'ignore_pattern', pattern)
    endfunction

    let g:unite_data_directory='~/.vim/.cache/unite'
    let g:unite_enable_start_insert=1
    let g:unite_source_history_yank_enable=1
    let g:unite_source_rec_max_cache_files=5000

    if executable('ag')
      let g:unite_source_grep_command='ag'
      let g:unite_source_grep_default_opts ='--nocolor --nogroup' .
            \' --ignore "node_modules"' .
            \' --ignore "bower_components"'
      let g:unite_source_grep_recursive_opt=''
    endif

    function! s:unite_settings()
      nmap <buffer> Q <plug>(unite_exit)
      nmap <buffer> <esc> <plug>(unite_exit)
      imap <buffer> <esc> <plug>(unite_exit)
    endfunction
    autocmd FileType unite call s:unite_settings()

    nmap <space> [unite]
    nnoremap [unite] <nop>

    " current dir(c: current dir)
    nnoremap <silent> [unite]c :<C-u>UniteWithCurrentDir -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>
    " buffer dir(b: buffer dir)
    nnoremap <silent> [unite]b :<C-u>UniteWithBufferDir -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>
    " fuzzy find bookmark/file/buffer(f: find)
    nnoremap <silent> [unite]f :<C-u>Unite -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>

For this full .vimrc file with the latest version of unite after I runned NeobundleInstall, the problem is still there

When I type <space> f in some git directory, I still can see .png files

Shougo commented 9 years ago

Please upload your unite.vim version. Unite.vim has some fixes for ignore_globs.

Shougo commented 9 years ago

startup vim. jpg file should not presented when file_rec/git is invoked.

I tested your minimal .vimrc, but jpg files are not presented. It is filtered by "ignore_globs".

Shougo commented 9 years ago

@chenhouwu Please upload your png file extensions.

laishulu commented 9 years ago

qq20150331-1

Shougo commented 9 years ago

Please upload your unite.vim version.

Shougo commented 9 years ago

@chenhouwu Please check the function in your unite.vim/candidates.vim.

function! s:ignore_candidates(candidates, context) "{{{
  let candidates = copy(a:candidates)

  if a:context.ignore_pattern != ''
    let candidates = unite#filters#vim_filter_pattern(
          \   candidates, a:context.ignore_pattern)
  endif

  if !empty(a:context.ignore_globs)
    let candidates = unite#filters#filter_patterns(candidates,
          \ unite#filters#globs2patterns(a:context.ignore_globs),
          \ unite#filters#globs2patterns(a:context.white_globs))
  endif

  if a:context.path != ''
    let candidates = unite#filters#{unite#util#has_lua()? 'lua' : 'vim'}
          \_filter_head(candidates, a:context.path)
  endif

  return candidates
endfunction"}}}

Please upload unite#filters#globs2patterns(a:context.ignore_globs) result in the function.

laishulu commented 9 years ago

candidates:

[file_rec/git] directory: /Users/chw/tmp
[]
[{'word': '/Users/chw/tmp/a.jpg', 'action__path': '/Users/chw/tmp/a.jpg'}, {'word': '/Users/chw/tmp/a.png', 'action__path': '/Users/chw/tmp/a.png'}]
Shougo commented 9 years ago

Please upload unite#filters#globs2patterns(a:context.ignore_globs) result in the function.

Not candidates value.

laishulu commented 9 years ago

unite#filters#globs2patterns(a:context.ignore_globs) is shown as bellow.

[file_rec/git] directory: /Users/chw/tmp
['/%.$', '/[^/]*~$', '/[^/]*%.o$', '/[^/]*%.exe$', '/[^/]*%.bak$', '/ds_store$', '/[^/]*%.pyc$', '/[^/]*%.sw[po]$', '/[^/]*%.class$', '/%.hg/.*$', '/%.git/.*$', '/%.bzr/.*$', '/%
.svn/.*$', '/tags$', '/tags%-[^/]*$']
['/%.$', '/[^/]*~$', '/[^/]*%.o$', '/[^/]*%.exe$', '/[^/]*%.bak$', '/ds_store$', '/[^/]*%.pyc$', '/[^/]*%.sw[po]$', '/[^/]*%.class$', '/%.hg/.*$', '/%.git/.*$', '/%.bzr/.*$', '/%
.svn/.*$', '/tags$', '/tags%-[^/]*$']
[]
Press ENTER or type command to continue

seems s:ignore_candidates(candidates, context) is executed three times, and at the last time, it's cleared to blank.

Shougo commented 9 years ago

OK. I get it.

function! bundle.hooks.on_source(bundle) is not executed. You must call call neobundle#end() after :NeoBundle lines.

Shougo commented 9 years ago

Your .vimrc is broken. Corrected version is here:


  " Note: Skip initialization for vim-tiny or vim-small.
  if !1 | finish | endif

  if has('vim_starting')
    set nocompatible               " Be iMproved

    " Required:
    set runtimepath+=~/.vim/bundle/neobundle.vim/
  endif

  " Required:
  call neobundle#begin(expand('~/.vim/bundle/'))

  " Let NeoBundle manage NeoBundle
  " Required:
  NeoBundleFetch 'Shougo/neobundle.vim'

  " My Bundles here:
  " Refer to |:NeoBundle-examples|.
  " Note: You don't set neobundle setting in .gvimrc!

  NeoBundle 'Shougo/vimproc.vim', {
        \  'build' : {
        \    'windows' : 'make -f make_mingw32.mak',
        \    'cygwin' : 'make -f make_cygwin.mak',
        \    'mac' : 'make -f make_mac.mak',
        \    'unix' : 'make -f make_unix.mak',
        \  },
        \}
  NeoBundle 'Shougo/unite.vim' "{{{
    let bundle = neobundle#get('unite.vim')
    function! bundle.hooks.on_source(bundle)
      call unite#filters#matcher_default#use(['matcher_fuzzy'])
      call unite#filters#sorter_default#use(['sorter_rank'])
      call unite#custom#profile('files', 'context.smartcase', 1)
      call unite#custom#source('line,outline','matchers',['matcher_fuzzy'])

      set wildignore=*.o,*.obj,*.la,*.lo,*.so,*.pyc,*.pyo,*.jpg,*.png,*.gif
      call unite#custom#source('file_rec/git', 'ignore_globs',
          \ split(&wildignore, ','))

      let dot = '\%(^\|/\)\.'
      let dirs = '\%(^\|/\)\%(' . join(
            \ ['node_modules', 'bower_components', 'dist'], '\|')
            \ . '\)\%($\|/\)'
      let files = join(['\.pyc\%($\)'], '\|')
      let pattern = join([dot, dirs, files], '\|')
      call unite#custom#source('file_rec/git', 'ignore_pattern', pattern)
    endfunction

    let g:unite_data_directory='~/.vim/.cache/unite'
    let g:unite_enable_start_insert=1
    let g:unite_source_history_yank_enable=1
    let g:unite_source_rec_max_cache_files=5000

    if executable('ag')
      let g:unite_source_grep_command='ag'
      let g:unite_source_grep_default_opts ='--nocolor --nogroup' .
            \' --ignore "node_modules"' .
            \' --ignore "bower_components"'
      let g:unite_source_grep_recursive_opt=''
    endif

    function! s:unite_settings()
      nmap <buffer> Q <plug>(unite_exit)
      nmap <buffer> <esc> <plug>(unite_exit)
      imap <buffer> <esc> <plug>(unite_exit)
    endfunction
    autocmd FileType unite call s:unite_settings()

    nmap <space> [unite]
    nnoremap [unite] <nop>

    " current dir(c: current dir)
    nnoremap <silent> [unite]c :<C-u>UniteWithCurrentDir -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>
    " buffer dir(b: buffer dir)
    nnoremap <silent> [unite]b :<C-u>UniteWithBufferDir -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>
    " fuzzy find bookmark/file/buffer(f: find)
    nnoremap <silent> [unite]f :<C-u>Unite -buffer-name=files -no-split
          \ file_point buffer bookmark file_rec/git file/new<CR>

  call neobundle#end()

  " Required:
  filetype plugin indent on

  " If there are uninstalled bundles found on startup,
  " this will conveniently prompt you to install them.
  NeoBundleCheck
laishulu commented 9 years ago

disaster after I move call neobundle#end() to the end of the file, I got

E185: Cannot find color scheme 'solarized'

But, now the ignore works :-)

I have the following between call neobundle#begin(expand('~/.vim/bundle/')), call neobundle#end()

  NeoBundle 'altercation/vim-colors-solarized'
    set background=dark
    colorscheme solarized
laishulu commented 9 years ago

after I move the following lines after call neobundle#end(), then all is OK

set background=dark
colorscheme solarized

But it's ugly, because I want theme related config to sit together. Any solution?

I've tried to invoke an additional call neobundle#end() twice(one for solarized, the othe for unite), but the later one has no effect.

Shougo commented 9 years ago

But it's ugly, because I want theme related config to sit together. Any solution?

You should use force.

NeoBundle 'altercation/vim-colors-solarized', {'force':1}
laishulu commented 9 years ago

works, thanks for your warm help!