From b9285c87db7273a3a8c700c29c5e7910868392dd Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 24 Feb 2016 00:08:34 +0900 Subject: [PATCH] [Tags/BTags] Take optional argument as the default query Related #90. Function signature of s:btags_source has changed. /cc @AdnoC --- README.md | 6 +++--- autoload/fzf/vim.vim | 14 +++++++++----- doc/fzf-vim.txt | 4 ++-- plugin/fzf.vim | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f3dfdd2..596b6e4 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ Commands | Command | List | | --- | --- | | `Files [PATH]` | Files (similar to `:FZF`) | -| `GitFiles` | Git files +| `GitFiles` | Git files | | `Buffers` | Open buffers | | `Colors` | Color schemes | | `Ag [PATTERN]` | [ag][ag] search result (`ALT-A` to select all, `ALT-D` to deselect all) | | `Lines` | Lines in loaded buffers | | `BLines` | Lines in the current buffer | -| `Tags` | Tags in the project (`ctags -R`) | -| `BTags` | Tags in the current buffer | +| `Tags [QUERY]` | Tags in the project (`ctags -R`) | +| `BTags [QUERY]` | Tags in the current buffer | | `Marks` | Marks | | `Windows` | Windows | | `Locate PATTERN` | `locate` command output | diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 2bc3c70..7b53c54 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -474,8 +474,12 @@ function! s:btags_sink(lines) normal! zz endfunction -" [tag commands], options -function! fzf#vim#buffer_tags(...) +function! s:q(query) + return ' --query "'.escape(a:query, '"').'"' +endfunction + +" query, [[tag commands], options] +function! fzf#vim#buffer_tags(query, ...) let args = copy(a:000) let tag_cmds = len(args) > 1 ? remove(args, 0) : [ \ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s', &filetype, expand('%:S')), @@ -484,7 +488,7 @@ function! fzf#vim#buffer_tags(...) return s:fzf(fzf#vim#wrap({ \ 'source': s:btags_source(tag_cmds), \ 'sink*': s:function('s:btags_sink'), - \ 'options': '--reverse -m -d "\t" --with-nth 1,4.. -n 1 --prompt "BTags> "'}), args) + \ 'options': '--reverse -m -d "\t" --with-nth 1,4.. -n 1 --prompt "BTags> "'.s:q(a:query)}), a:000) catch return s:warn(v:exception) endtry @@ -518,7 +522,7 @@ function! s:tags_sink(lines) normal! zz endfunction -function! fzf#vim#tags(...) +function! fzf#vim#tags(query, ...) if empty(tagfiles()) call s:warn('Preparing tags') call system('ctags -R') @@ -541,7 +545,7 @@ function! fzf#vim#tags(...) \ 'source': proc.shellescape(fnamemodify(tagfile, ':t')), \ 'sink*': s:function('s:tags_sink'), \ 'dir': fnamemodify(tagfile, ':h'), - \ 'options': copt.'-m --tiebreak=begin --prompt "Tags> "'}), a:000) + \ 'options': copt.'-m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}), a:000) endfunction " ------------------------------------------------------------------ diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 2ebe3f1..1ecb48a 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -81,8 +81,8 @@ COMMANDS *fzf-vim-commands* `Ag [PATTERN]` | {ag}{5} search result (ALT-A to select all, ALT-D to deselect all) `Lines` | Lines in loaded buffers `BLines` | Lines in the current buffer - `Tags` | Tags in the project ( `ctags -R` ) - `BTags` | Tags in the current buffer + `Tags [QUERY]` | Tags in the project ( `ctags -R` ) + `BTags [QUERY]` | Tags in the current buffer `Marks` | Marks `Windows` | Windows `Locate PATTERN` | `locate` command output diff --git a/plugin/fzf.vim b/plugin/fzf.vim index a773ab3..52176a9 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -50,8 +50,8 @@ call s:defs([ \'command! -bang Colors call fzf#vim#colors(s:w(0))', \'command! -bang -nargs=1 -complete=dir Locate call fzf#vim#locate(, s:w(0))', \'command! -bang -nargs=* Ag call fzf#vim#ag(, s:w(0))', -\'command! -bang Tags call fzf#vim#tags(s:w(0))', -\'command! -bang BTags call fzf#vim#buffer_tags(s:w(0))', +\'command! -bang -nargs=* Tags call fzf#vim#tags(, s:w(0))', +\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, s:w(0))', \'command! -bang Snippets call fzf#vim#snippets(s:w(0))', \'command! -bang Commands call fzf#vim#commands(s:w(0))', \'command! -bang Marks call fzf#vim#marks(s:w(0))',