Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test telescope replacements #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 21 additions & 12 deletions vim/plugin/asyncsearch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ else
let s:arguments="--vimgrep --case-sensitive {}"
endif

command -nargs=+ -complete=file Grep call <SID>Grep(<q-args>)
" command -nargs=+ -complete=file Grep call <SID>Grep(<q-args>)
command -nargs=+ -complete=file Grep lua require('telescope.builtin').grep_string({search = <q-args>})
function! s:Grep(args)
if empty(a:args)
echohl ErrorMsg
Expand All @@ -17,15 +18,19 @@ function! s:Grep(args)
return
endif

cclose
let l:formatted_args = '"' . escape(a:args, '\') . '"'
let l:arguments = substitute(s:arguments, '{}', l:formatted_args, '')
let l:maker = {
\ 'exe': s:executable,
\ 'args': l:arguments,
\ 'errorformat': &errorformat,
\ }
call neomake#Make(0, [l:maker])
" cclose
" let l:formatted_args = '"' . escape(a:args, '\') . '"'
" echom formatted_args
" let l:arguments = substitute(s:arguments, '{}', l:formatted_args, '')
" let l:maker = {
" \ 'exe': s:executable,
" \ 'args': l:arguments,
" \ 'errorformat': &errorformat,
" \ }
" call neomake#Make(0, [l:maker])
let s = a:args
lua require('telescope.builtin').grep_string({search = s})
" lua require('telescope.builtin').live_grep({search = a:args})
endfunction

function! s:Escape(string)
Expand All @@ -40,13 +45,17 @@ nnoremap <silent> s :set operatorfunc=<SID>GrepMotion<CR>g@
function! s:GrepMotion(...) abort
let save = @@
silent execute "normal! `[v`]y"
call s:Grep(s:Escape(@@))
" call s:Grep(s:Escape(@@))
let s = s:Escape(@@)
lua require('telescope.builtin').grep_string({search = s})
let @@ = save
endfunction

vnoremap <silent> s :<C-U>call <SID>GrepVisual()<CR>
function! s:GrepVisual()
call s:Grep(s:Escape(s:GetVisualSelection()))
" call s:Grep(s:Escape(s:GetVisualSelection()))
let s = s:Escape(s:GetVisualSelection())
lua require('telescope.builtin').grep_string({search = s})
endfunction

" What a PITA https://stackoverflow.com/a/6271254/902968
Expand Down
44 changes: 40 additions & 4 deletions vim/plugin/fuzzy.vim
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,43 @@ function! FuzzyFindCommand(vimCommand) abort
startinsert
endfunction

nnoremap <C-p> :call FuzzyFindCommand("edit")<cr>
nnoremap <C-p>e :call FuzzyFindCommand("edit")<cr>
nnoremap <C-p>v :call FuzzyFindCommand("vsplit")<cr>
nnoremap <C-p>s :call FuzzyFindCommand("split")<cr>

function! s:GitListCommand2(directory)
" Until you can use --recurse-submodules and --others together
if filereadable(a:directory . "/.gitmodules")
" TODO: should second command here have --cached?
return ["git", "ls-files", a:directory, "--cached", "--exclude-standard", "--recurse-submodules", "2>/dev/null", "&&", "git", "ls-files", a:directory, "--exclude-standard", "--others", "2>/dev/null"]
else
return ["git", "ls-files", a:directory, "--cached", "--exclude-standard", "--others", "2>/dev/null"]
endif
endfunction

" Command for searching folders even if they
" aren't tracked with git
function! s:SearchCommand2()
let l:output = system("git rev-parse --show-toplevel")
if v:shell_error == 0
let l:output = substitute(l:output, "\\n", "", "")
return s:GitListCommand2(l:output)
else
" TODO: fall back to whatever telescope does by default
return "find * -type f -o -type l"
endif
endfunction

function! FuzzyFindCommand2(vimCommand) abort
let cmd = s:SearchCommand2()
lua require('telescope.builtin').find_files({ find_command = cmd })
" lua require('telescope.builtin').find_files({ find_command = {"git", "ls-files", ".", "--cached", "--exclude-standard", "--others"}, hidden = true })
" lua require('telescope.builtin').git_files({show_untracked = true})
endfunction

" " nnoremap <C-p> :call FuzzyFindCommand("edit")<cr>
" " nnoremap <C-p>e :call FuzzyFindCommand("edit")<cr>
" nnoremap <C-p>v :call FuzzyFindCommand("vsplit")<cr>
" nnoremap <C-p>s :call FuzzyFindCommand("split")<cr>

nnoremap <C-p> :call FuzzyFindCommand2("edit")<cr>
" nnoremap <C-p>e :call FuzzyFindCommand2("edit")<cr>
" nnoremap <C-p>v :call FuzzyFindCommand2("vsplit")<cr>
" nnoremap <C-p>s :call FuzzyFindCommand2("split")<cr>