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

Add option to include/exclude binary files #54

Merged
merged 1 commit into from
Oct 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion plugin/EasyGrep.vim
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ function! <sid>EchoOptionsSet()
\ "g:EasyGrepSearchCurrentBufferDir",
\ "g:EasyGrepIgnoreCase",
\ "g:EasyGrepHidden",
\ "g:EasyGrepBinary",
\ "g:EasyGrepFilesToInclude",
\ "g:EasyGrepFilesToExclude",
\ "g:EasyGrepAllOptionsInExplorer",
Expand Down Expand Up @@ -1134,6 +1135,15 @@ function! <sid>ToggleHidden()
call s:Echo("Set hidden files included to (".EasyGrep#OnOrOff(g:EasyGrepHidden).")")
endfunction
" }}}
" ToggleBinary {{{
function! <sid>ToggleBinary()
let g:EasyGrepBinary = !g:EasyGrepBinary

call s:RefreshAllOptions()

call s:Echo("Set binary files included to (".EasyGrep#OnOrOff(g:EasyGrepBinary).")")
endfunction
" }}}
" ToggleBufferDirectories {{{
function! <sid>ToggleBufferDirectories()
let g:EasyGrepSearchCurrentBufferDir = !g:EasyGrepSearchCurrentBufferDir
Expand Down Expand Up @@ -1389,6 +1399,7 @@ function! s:CreateOptionMappings()
exe "nmap <silent> ".p."d :call <sid>ToggleBufferDirectories()<cr>"
exe "nmap <silent> ".p."i :call <sid>ToggleIgnoreCase()<cr>"
exe "nmap <silent> ".p."h :call <sid>ToggleHidden()<cr>"
exe "nmap <silent> ".p."B :call <sid>ToggleBinary()<cr>"
exe "nmap <silent> ".p."w :call <sid>ToggleWindow()<cr>"
exe "nmap <silent> ".p."o :call <sid>ToggleOpenWindow()<cr>"
exe "nmap <silent> ".p."g :call <sid>ToggleEveryMatch()<cr>"
Expand Down Expand Up @@ -1424,6 +1435,7 @@ function! s:CreateOptionsString()
call add(s:Options, "\"h: hidden files included (".EasyGrep#OnOrOff(g:EasyGrepHidden).")")
call add(s:Options, "\"e: echo files that would be searched")
if g:EasyGrepAllOptionsInExplorer
call add(s:Options, "\"B: binary files included (".EasyGrep#OnOrOff(g:EasyGrepBinary).")")
call add(s:Options, "\"x: set files to exclude")
call add(s:Options, "\"c: change grep command (".s:GetGrepCommandNameWithOptions().")")
call add(s:Options, "\"w: window to use (".EasyGrep#GetErrorListName().")")
Expand Down Expand Up @@ -1467,6 +1479,7 @@ function! s:MapOptionsExplorerKeys()
nnoremap <buffer> <silent> d :call <sid>ToggleBufferDirectories()<cr>
nnoremap <buffer> <silent> i :call <sid>ToggleIgnoreCase()<cr>
nnoremap <buffer> <silent> h :call <sid>ToggleHidden()<cr>
nnoremap <buffer> <silent> B :call <sid>ToggleBinary()<cr>
nnoremap <buffer> <silent> e :call <sid>EchoFilesSearched()<cr>

nnoremap <buffer> <silent> x :call <sid>SetFilesToExclude()<cr>
Expand Down Expand Up @@ -2379,6 +2392,8 @@ function! s:ConfigureGrepCommandParameters()
\ 'opt_bool_nofiletargets': '0',
\ 'opt_str_mapinclusionsexpression': '"--include=\"" .v:val."\""',
\ 'opt_bool_requireexplicitfiles': '1',
\ 'opt_str_binaryswitch': '-I',
\ 'opt_bool_binaryexcludedbydefault': '0',
\ })

call s:RegisterGrepProgram("git", {
Expand Down Expand Up @@ -2456,6 +2471,8 @@ function! s:ConfigureGrepCommandParameters()
\ 'opt_bool_nofiletargets': '0',
\ 'opt_str_mapinclusionsexpression': '"--file-search-regex=\"" .substitute(v:val, "^\\*\\.", "\\\\.", "")."\""',
\ 'opt_str_hiddenswitch': '--hidden',
\ 'opt_str_binaryswitch': '--search-binary',
\ 'opt_bool_binaryexcludedbydefault': '1',
\ })

call s:RegisterGrepProgram("pt", {
Expand Down Expand Up @@ -2645,6 +2662,12 @@ function! s:GetGrepCommandLine(pattern, add, wholeword, count, escapeArgs, filte
let opts .= commandParams["opt_str_hiddenswitch"]." "
endif

if s:CommandHasLen("opt_str_binaryswitch") &&
\ ((g:EasyGrepBinary && s:CommandHas("opt_bool_binaryexcludedbydefault")) ||
\ (!g:EasyGrepBinary && !s:CommandHas("opt_bool_binaryexcludedbydefault")))
let opts .= commandParams["opt_str_binaryswitch"]." "
endif

" Suppress errors
if s:CommandHasLen("opt_str_suppresserrormessages")
let opts .= commandParams["opt_str_suppresserrormessages"]." "
Expand Down Expand Up @@ -2846,10 +2869,11 @@ function! s:WarnNoMatches(pattern)

let r = s:IsRecursiveSearch() ? " (+Recursive)" : ""
let h = g:EasyGrepHidden ? " (+Hidden)" : ""
let b = g:EasyGrepBinary ? " (+Binary)" : ""

redraw
call EasyGrep#Warning("No matches for '".a:pattern."'")
call EasyGrep#Warning("File Pattern: ".fpat.r.h)
call EasyGrep#Warning("File Pattern: ".fpat.r.h.b)

let dirs = s:GetDirectorySearchList()
let s = "Directories:"
Expand Down Expand Up @@ -3530,6 +3554,10 @@ if !exists("g:EasyGrepHidden")
let g:EasyGrepHidden=0
endif

if !exists("g:EasyGrepBinary")
let g:EasyGrepBinary=0
endif

if !exists("g:EasyGrepAllOptionsInExplorer")
let g:EasyGrepAllOptionsInExplorer=0
endif
Expand Down