spacevim/autoload/SpaceVim/layers/telescope.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

402 lines
13 KiB
VimL

"=============================================================================
" telescope.vim --- telescope support for spacevim
" Copyright (c) 2016-2023 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
if exists('s:file')
finish
endif
""
" @section telescope, layers-telescope
" @parentsection layers
" This layer provides fuzzy finder feature which is based on |telescope|, and this
" This layer is not loaded by default. To use this layer:
" >
" [[layers]]
" name = 'telescope'
" <
" @subsection Key bindings
"
" The following key bindings will be enabled when this layer is loaded:
" >
" Key bindings Description
" SPC p f / Ctrl-p search files in current directory
" <Leader> f SPC Fuzzy find menu:CustomKeyMaps
" <Leader> f e Fuzzy find register
" <Leader> f h Fuzzy find history/yank
" <Leader> f j Fuzzy find jump, change
" <Leader> f l Fuzzy find location list
" <Leader> f m Fuzzy find output messages
" <Leader> f o Fuzzy find functions
" <Leader> f t Fuzzy find tags
" <Leader> f q Fuzzy find quick fix
" <Leader> f r Resumes Unite window
" <
function! SpaceVim#layers#telescope#loadable() abort
return has('nvim-0.7.0')
endfunction
function! SpaceVim#layers#telescope#plugins() abort
let plugins = []
if has('nvim-0.10.0')
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope.nvim-0.1.8', {'merged' : 0, 'loadconf' : 1, 'on_cmd' : ['Telescope']}])
elseif has('nvim-0.7.2')
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope.nvim-0.1.5', {'merged' : 0, 'loadconf' : 1, 'on_cmd' : ['Telescope']}])
elseif has('nvim-0.7.0')
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope.nvim-0.1.2', {'merged' : 0, 'loadconf' : 1, 'on_cmd' : ['Telescope']}])
endif
call add(plugins, [g:_spacevim_root_dir . 'bundle/plenary.nvim', {'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope-menu', {'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope-ctags-outline.nvim', {'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', { 'merged' : 0}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope-fzf-native.nvim', { 'merged' : 0}])
if g:spacevim_snippet_engine ==# 'ultisnips'
call add(plugins, ['fhill2/telescope-ultisnips.nvim', { 'merged' : 0}])
endif
return plugins
endfunction
let s:filename = expand('<sfile>:~')
let s:lnum = expand('<slnum>') + 2
function! SpaceVim#layers#telescope#config() abort
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['?'], 'Telescope menu menu=CustomKeyMaps default_text=[SPC]',
\ ['show-mappings',
\ [
\ 'SPC ? is to show mappings',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['h', '[SPC]'], 'call call('
\ . string(s:_function('s:get_help')) . ', ["SpaceVim"])',
\ ['find-SpaceVim-help',
\ [
\ 'SPC h SPC is to find SpaceVim help',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
" @fixme SPC h SPC make vim flick
exe printf('nmap %sh%s [SPC]h[SPC]', g:spacevim_default_custom_leader, g:spacevim_default_custom_leader)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['b', 'b'], 'Telescope buffers',
\ ['list-buffer',
\ [
\ 'SPC b b is to open buffer list',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['f', 'r'], 'Telescope neomru',
\ ['open-recent-file',
\ [
\ 'SPC f r is to open recent file list',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['j', 'i'], 'Telescope ctags_outline outline',
\ ['jump-to-definition-in-buffer',
\ [
\ 'SPC j i is to jump to a definition in buffer',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['T', 's'], 'Telescope colorscheme',
\ ['fuzzy-find-colorschemes',
\ [
\ 'SPC T s is to fuzzy find colorschemes',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['f', 'f'],
\ "exe 'Telescope find_files cwd=' . fnamemodify(bufname('%'), ':p:h')",
\ ['find-files-in-buffer-directory',
\ [
\ '[SPC f f] is to find files in the directory of the current buffer',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ]
\ , 1)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['p', 'f'],
\ 'Telescope find_files',
\ ['find-files-in-project',
\ [
\ '[SPC p f] is to find files in the root of the current project',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ]
\ , 1)
nnoremap <silent> <C-p> :<C-u>Telescope find_files<cr>
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nnoremap', ['h', 'i'], 'call call('
\ . string(s:_function('s:get_help_with_cursor_symbol')) . ', [])',
\ ['get-help-for-cursor-symbol',
\ [
\ '[SPC h i] is to get help with the symbol at point',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ],
\ 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 't', 'f'],
\ 'Telescope task', 'fuzzy-find-tasks', 1)
let g:_spacevim_mappings.f = {'name' : '+Fuzzy Finder'}
call s:defind_fuzzy_finder()
" this autocmd should only be called when using deoplete
augroup spacevim_telescope_layer
autocmd!
if g:spacevim_autocomplete_method == 'deoplete'
" https://github.com/nvim-telescope/telescope.nvim/issues/161
autocmd FileType TelescopePrompt call deoplete#custom#buffer_option('auto_complete', v:false)
endif
" @fixme 无法移除 jk 映射
" autocmd FileType TelescopePrompt iunmap <buffer> jk
augroup END
endfunction
function! s:get_help_with_cursor_symbol() abort
exe 'Telescope help_tags default_text=' . expand('<cword>')
endfunction
function! s:get_help(word) abort
exe 'Telescope help_tags default_text=' . a:word
endfunction
function! s:get_menu(menu, input) abort
let save_ctrlp_default_input = get(g:, 'ctrlp_default_input', '')
let g:ctrlp_default_input = a:input
exe 'CtrlPMenu ' . a:menu
let g:ctrlp_default_input = save_ctrlp_default_input
endfunction
let s:file = expand('<sfile>:~')
let s:unite_lnum = expand('<slnum>') + 3
function! s:defind_fuzzy_finder() abort
nnoremap <silent> <Leader>fe
\ :<C-u>Telescope registers<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.e = ['Telescope registers',
\ 'fuzzy find registers',
\ [
\ '[Leader f e ] is to fuzzy find registers',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fr
\ :<C-u>Telescope resume<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.r = ['Telescope resume',
\ 'resume telescope window',
\ [
\ '[Leader f r ] is to resume telescope window',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fh
\ :<C-u>Telescope neoyank<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.h = ['Telescope neoyank',
\ 'fuzzy find yank history',
\ [
\ '[Leader f h] is to fuzzy find history and yank content',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fj
\ :<C-u>Telescope jumplist<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.j = ['Telescope jumplist',
\ 'fuzzy find jump list',
\ [
\ '[Leader f j] is to fuzzy find jump list',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fl
\ :<C-u>Telescope loclist<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.l = ['Telescope loclist',
\ 'fuzzy find local list',
\ [
\ '[Leader f q] is to fuzzy find local list',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fm
\ :<C-u>Telescope messages<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.m = ['Telescope messages',
\ 'fuzzy find and yank message history',
\ [
\ '[Leader f m] is to fuzzy find and yank message history',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fq
\ :<C-u>Telescope quickfix<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.q = ['Telescope quickfix',
\ 'fuzzy find quickfix list',
\ [
\ '[Leader f q] is to fuzzy find quickfix list',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fo :<C-u>Telescope ctags_outline outline<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.o = ['Telescope ctags_outline outline',
\ 'fuzzy find outline',
\ [
\ '[Leader f o] is to fuzzy find outline',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>f<Space> :Telescope menu menu=CustomKeyMaps<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f['[SPC]'] = ['Telescope menu menu=CustomKeyMaps',
\ 'fuzzy find custom key bindings',
\ [
\ '[Leader f SPC] is to fuzzy find custom key bindings',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
nnoremap <silent> <Leader>fp :<C-u>Telescope menu menu=AddedPlugins<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.p = ['Telescope menu menu=AddedPlugins',
\ 'fuzzy find vim packages',
\ [
\ '[Leader f p] is to fuzzy find vim packages installed in SpaceVim',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
if g:spacevim_snippet_engine ==# 'ultisnips'
nnoremap <silent> <Leader>fs :<C-u>Telescope ultisnips<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.s = ['Telescope ultisnips',
\ 'fuzzy find ultisnips snippets',
\ [
\ '[Leader f s] is to fuzzy find ultisnips snippets',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
endif
if SpaceVim#layers#isLoaded('tools')
nnoremap <silent> <Leader>fb :<C-u>Telescope bookmarks<CR>
let lnum = expand('<slnum>') + s:unite_lnum - 4
let g:_spacevim_mappings.f.b = ['Telescope bookmarks',
\ 'fuzzy find bookmarks',
\ [
\ '[Leader f b] is to fuzzy find bookmarks',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
endif
let lnum = expand('<slnum>') + s:unite_lnum - 4
call SpaceVim#mapping#space#def('nnoremap', ['f', 'v', 's'], 'Telescope scriptnames',
\ ['open-custom-configuration',
\ [
\ '[SPC f v d] is to open the custom configuration file for SpaceVim',
\ '',
\ 'Definition: ' . s:file . ':' . lnum,
\ ]
\ ]
\ , 1)
endfunction
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort
return function(a:fstr)
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . s:_SID() . '_'
function! s:_function(fstr) abort
return function(substitute(a:fstr, 's:', s:_s, 'g'))
endfunction
endif
function! SpaceVim#layers#telescope#health() abort
return 1
endfunction
function! SpaceVim#layers#telescope#set_variable(var) abort
endfunction
function! SpaceVim#layers#telescope#get_options() abort
return []
endfunction