Skip to content

Commit

Permalink
Version 1.10 (April 24, 2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
yegappan committed Nov 14, 2013
1 parent af4fa2e commit c27a827
Showing 1 changed file with 54 additions and 12 deletions.
66 changes: 54 additions & 12 deletions plugin/grep.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" File: grep.vim
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 1.9
" Last Modified: September 10, 2007
" Version: 1.10
" Last Modified: April 20, 2013
"
" Overview
" --------
Expand Down Expand Up @@ -251,13 +251,13 @@
"
" :let Grep_Find_Use_Xargs = 0
"
" To handle file names with space characters in them, the xargs utility
" is invoked with the '--null' argument. If the xargs utility in your system
" doesn't accept the '--null' argument, then you can change the
" Grep_Xargs_Options variable. For example, to use the '--print0' xargs
" argument, you can use the following command:
" To handle file names with space characters in them, the xargs utility is
" invoked with the '-0' argument. If the xargs utility in your system doesn't
" accept the '-0' argument, then you can change the Grep_Xargs_Options
" variable. For example, to use the '--null' xargs argument, you can use the
" following command:
"
" :let Grep_Xargs_Options = '--print0'
" :let Grep_Xargs_Options = '--null'
"
" The Grep_Cygwin_Find variable should be set to 1, if you are using the find
" utility from the cygwin package. This setting is used to handle the
Expand Down Expand Up @@ -352,7 +352,7 @@ endif

" The command-line arguments to supply to the xargs utility
if !exists('Grep_Xargs_Options')
let Grep_Xargs_Options = '--null'
let Grep_Xargs_Options = '-0'
endif

" The find utility is from the cygwin package or some other find utility.
Expand Down Expand Up @@ -404,7 +404,36 @@ endif
" RunGrepCmd()
" Run the specified grep command using the supplied pattern
function! s:RunGrepCmd(cmd, pattern, action)
let cmd_output = system(a:cmd)
if has('win32') && !has('win32unix') && !has('win95')
\ && (&shell =~ 'cmd.exe')
" Windows does not correctly deal with commands that have more than 1
" set of double quotes. It will strip them all resulting in:
" 'C:\Program' is not recognized as an internal or external command
" operable program or batch file. To work around this, place the
" command inside a batch file and call the batch file.
" Do this only on Win2K, WinXP and above.
let s:grep_tempfile = fnamemodify(tempname(), ':h') . '\mygrep.cmd'
if v:version >= 700
call writefile([a:cmd], s:grep_tempfile, "b")
else
exe 'redir! > ' . s:grep_tempfile
silent echo a:cmd
redir END
endif

let cmd_output = system('"' . s:grep_tempfile . '"')
else
let cmd_output = system(a:cmd)
endif

if exists('s:grep_tempfile')
" Delete the temporary cmd file created on MS-Windows
call delete(s:grep_tempfile)
endif

" Do not check for the shell_error (return code from the command).
" Even if there are valid matches, grep returns error codes if there
" are problems with a few input files.

if cmd_output == ""
echohl WarningMsg |
Expand Down Expand Up @@ -508,6 +537,7 @@ function! s:RunGrepRecursive(cmd_name, grep_cmd, action, ...)
endif
let pattern = g:Grep_Shell_Quote_Char . pattern .
\ g:Grep_Shell_Quote_Char
echo "\r"
endif

let cwd = getcwd()
Expand All @@ -522,13 +552,15 @@ function! s:RunGrepRecursive(cmd_name, grep_cmd, action, ...)
if startdir == ""
return
endif
echo "\r"

if filepattern == ""
let filepattern = input("Search in files matching pattern: ",
\ g:Grep_Default_Filelist)
if filepattern == ""
return
endif
echo "\r"
endif

let txt = filepattern . ' '
Expand Down Expand Up @@ -576,7 +608,7 @@ function! s:RunGrepRecursive(cmd_name, grep_cmd, action, ...)
endif

if g:Grep_Find_Use_Xargs == 1
let cmd = g:Grep_Find_Path . " " . startdir
let cmd = g:Grep_Find_Path . ' "' . startdir . '"'
let cmd = cmd . " " . find_prune . " -prune -o"
let cmd = cmd . " " . find_skip_files
let cmd = cmd . " " . find_file_pattern
Expand Down Expand Up @@ -618,7 +650,14 @@ function! s:RunGrepSpecial(cmd_name, which, action, ...)

while i <= last_bufno
if bufexists(i) && buflisted(i)
let filenames = filenames . " " . bufname(i)
let fullpath = fnamemodify(bufname(i), ':p')
if filereadable(fullpath)
if v:version >= 702
let filenames = filenames . " " . fnameescape(fullpath)
else
let filenames = filenames . " " . fullpath
endif
endif
endif
let i = i + 1
endwhile
Expand Down Expand Up @@ -684,6 +723,7 @@ function! s:RunGrepSpecial(cmd_name, which, action, ...)
if pattern == ""
return
endif
echo "\r"
endif

let pattern = g:Grep_Shell_Quote_Char . pattern . g:Grep_Shell_Quote_Char
Expand Down Expand Up @@ -761,6 +801,7 @@ function! s:RunGrep(cmd_name, grep_cmd, action, ...)
endif
let pattern = g:Grep_Shell_Quote_Char . pattern .
\ g:Grep_Shell_Quote_Char
echo "\r"
endif

if filenames == ""
Expand All @@ -773,6 +814,7 @@ function! s:RunGrep(cmd_name, grep_cmd, action, ...)
if filenames == ""
return
endif
echo "\r"
endif

" Add /dev/null to the list of filenames, so that grep print the
Expand Down

0 comments on commit c27a827

Please sign in to comment.