@@ -142,8 +142,8 @@ function! s:GetBufferDirsList()
142
142
if empty (d )
143
143
let d = currDir
144
144
elseif has (" win32" ) && d [0 ] == " /"
145
- " Remove the trailing slash
146
- let d = fnamemodify (d , " :s-/$--" )
145
+ " Add the drive prefix but remove the trailing slash
146
+ let d = fnamemodify (d , " :p: s-/$--" )
147
147
endif
148
148
let dirs[d ]= 1
149
149
endfor
@@ -637,12 +637,12 @@ endfunction
637
637
" GetFileTargetList {{{
638
638
function ! s: GetFileTargetList (addAdditionalLocations)
639
639
let addAdditionalLocations = a: addAdditionalLocations
640
- let lst = []
640
+ let fileTargetList = []
641
641
if s: IsModeBuffers ()
642
- let lst = s: EscapeList (s: GetBufferNamesList (), " " )
642
+ let fileTargetList = s: EscapeList (s: GetBufferNamesList (), " " )
643
643
let addAdditionalLocations = 0
644
644
elseif s: IsModeTracked ()
645
- let lst = s: GetFileTargetList_Tracked ()
645
+ let fileTargetList = s: GetFileTargetList_Tracked ()
646
646
else
647
647
let i = 0
648
648
let numItems = len (s: Dict )
@@ -655,36 +655,36 @@ function! s:GetFileTargetList(addAdditionalLocations)
655
655
endwhile
656
656
657
657
if ! empty (keyList)
658
- let lst = s: CollectEnabledFileTargets (keyList)
658
+ let fileTargetList = s: CollectEnabledFileTargets (keyList)
659
659
else
660
660
call s: InternalFailure (" Keylist should not be empty" )
661
- let lst = [ " *" ]
661
+ let fileTargetList = [ " *" ]
662
662
endif
663
663
endif
664
664
665
665
if addAdditionalLocations
666
- let lst = s: AddAdditionalLocationsToFileTargetList (lst )
666
+ let fileTargetList = s: AddAdditionalLocationsToFileTargetList (fileTargetList )
667
667
endif
668
668
669
- return lst
669
+ return fileTargetList
670
670
endfunction
671
671
" }}}
672
672
" AddAdditionalLocationsToFileTargetList {{{
673
- function ! s: AddAdditionalLocationsToFileTargetList (lst )
674
- let lst = a: lst
675
- if empty (lst ) || s: IsModeBuffers ()
676
- return lst
673
+ function ! s: AddAdditionalLocationsToFileTargetList (fileTargetList )
674
+ let fileTargetList = a: fileTargetList
675
+ if empty (fileTargetList ) || s: IsModeBuffers ()
676
+ return fileTargetList
677
677
endif
678
678
679
679
if g: EasyGrepSearchCurrentBufferDir && s: IsBufferDirSearchAllowed ()
680
- let lst = s: ApplySearchDirectoriesToFileTargetList (lst )
680
+ let fileTargetList = s: ApplySearchDirectoriesToFileTargetList (fileTargetList )
681
681
endif
682
682
683
683
if g: EasyGrepHidden
684
684
let i = 0
685
- let size = len (lst )
685
+ let size = len (fileTargetList )
686
686
while i < size
687
- let item = lst [i ]
687
+ let item = fileTargetList [i ]
688
688
let lastpiece = strridx (item, ' /' )
689
689
if lastpiece == -1 && item[0 ] == ' .'
690
690
" skip this item, it's already hidden
@@ -700,21 +700,19 @@ function! s:AddAdditionalLocationsToFileTargetList(lst)
700
700
endif
701
701
let i += 1
702
702
let size += 1
703
- call insert (lst , newItem, i )
703
+ call insert (fileTargetList , newItem, i )
704
704
endif
705
705
let i += 1
706
706
endwhile
707
707
endif
708
708
709
709
let newlst = []
710
- for item in lst
710
+ for item in fileTargetList
711
711
if s: IsRecursiveSearch () && s: IsCommandVimgrep ()
712
712
" Insert a recursive specifier into the command
713
- let str = substitute (item, ' /\([^/]\+\)$' , ' /**/\1' , " " )
714
- else
715
- let str = item
713
+ let item = substitute (item, ' /\([^/]\+\)$' , ' /**/\1' , " " )
716
714
endif
717
- call add (newlst, str )
715
+ call add (newlst, item )
718
716
endfor
719
717
720
718
return newlst
@@ -760,8 +758,9 @@ endfunction
760
758
" IsRecursivelyReachable {{{
761
759
function ! s: IsRecursivelyReachable (fromthisdir, target)
762
760
let directoryTarget = fnamemodify (a: target , " :p:h" )
761
+ let fromthisdir = a: fromthisdir == " ." ? s: GetCwdEscaped () : a: fromthisdir
763
762
764
- if match (directoryTarget, a: fromthisdir ) != 0
763
+ if match (directoryTarget, fromthisdir) != 0
765
764
return 0
766
765
endif
767
766
@@ -1047,11 +1046,13 @@ function! <sid>EchoGrepCommand()
1047
1046
endfor
1048
1047
else
1049
1048
let dirAnnotation = " Search Directory: "
1050
- call s: Echo (dirAnnotation.s: GetGrepRoot ())
1049
+ let d = s: GetGrepRoot ()
1050
+ let d = (d == " ." ) ? d ." --> " .s: GetCwdEscaped ()." " : d
1051
+ call s: Echo (dirAnnotation.d )
1051
1052
endif
1052
1053
1053
1054
let placeholder = " <pattern>"
1054
- let grepCommand = s: GetGrepCommandLine (placeholder, " " , 0 , " " , 1 )
1055
+ let grepCommand = s: GetGrepCommandLine (placeholder, " " , 0 , " " , 1 , 0 )
1055
1056
call s: Echo (" VIM command: " .grepCommand)
1056
1057
1057
1058
if s: GetGrepCommandName () == " grep"
@@ -2550,7 +2551,6 @@ function! s:ConfigureGrepCommandParameters()
2550
2551
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2551
2552
\ ' opt_bool_isinherentlyrecursive' : ' 0' ,
2552
2553
\ ' opt_bool_isselffiltering' : ' 0' ,
2553
- \ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2554
2554
\ })
2555
2555
2556
2556
call s: RegisterGrepProgram (" grep" , {
@@ -2573,8 +2573,7 @@ function! s:ConfigureGrepCommandParameters()
2573
2573
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2574
2574
\ ' opt_bool_isinherentlyrecursive' : ' 0' ,
2575
2575
\ ' opt_bool_isselffiltering' : ' 0' ,
2576
- \ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2577
- \ ' opt_bool_greprecursionwar' : ' 1' ,
2576
+ \ ' opt_str_recursiveinclusionexpression' : ' "--include=\"" .v:val."\""' ,
2578
2577
\ })
2579
2578
2580
2579
call s: RegisterGrepProgram (" git" , {
@@ -2597,7 +2596,6 @@ function! s:ConfigureGrepCommandParameters()
2597
2596
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2598
2597
\ ' opt_bool_isinherentlyrecursive' : ' 0' ,
2599
2598
\ ' opt_bool_isselffiltering' : ' 0' ,
2600
- \ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2601
2599
\ })
2602
2600
2603
2601
call s: RegisterGrepProgram (" ack" , {
@@ -2620,7 +2618,6 @@ function! s:ConfigureGrepCommandParameters()
2620
2618
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2621
2619
\ ' opt_bool_isinherentlyrecursive' : ' 1' ,
2622
2620
\ ' opt_bool_isselffiltering' : ' 1' ,
2623
- \ ' opt_bool_replacewildcardwithcwd' : ' 1' ,
2624
2621
\ })
2625
2622
2626
2623
call s: RegisterGrepProgram (" ack-grep" , s: commandParamsDict [" ack" ])
@@ -2645,7 +2642,6 @@ function! s:ConfigureGrepCommandParameters()
2645
2642
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2646
2643
\ ' opt_bool_isinherentlyrecursive' : ' 1' ,
2647
2644
\ ' opt_bool_isselffiltering' : ' 1' ,
2648
- \ ' opt_bool_replacewildcardwithcwd' : ' 1' ,
2649
2645
\ })
2650
2646
2651
2647
call s: RegisterGrepProgram (" pt" , {
@@ -2668,7 +2664,6 @@ function! s:ConfigureGrepCommandParameters()
2668
2664
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2669
2665
\ ' opt_bool_isinherentlyrecursive' : ' 1' ,
2670
2666
\ ' opt_bool_isselffiltering' : ' 1' ,
2671
- \ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2672
2667
\ })
2673
2668
2674
2669
call s: RegisterGrepProgram (" findstr" , {
@@ -2691,7 +2686,6 @@ function! s:ConfigureGrepCommandParameters()
2691
2686
\ ' opt_bool_directoryneedsbackslash' : ' 1' ,
2692
2687
\ ' opt_bool_isinherentlyrecursive' : ' 0' ,
2693
2688
\ ' opt_bool_isselffiltering' : ' 0' ,
2694
- \ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2695
2689
\ })
2696
2690
endfunction
2697
2691
" }}}
@@ -2710,7 +2704,7 @@ function! s:GetGrepCommandParameters()
2710
2704
endfunction
2711
2705
" }}}
2712
2706
" GetGrepCommandLine {{{
2713
- function ! s: GetGrepCommandLine (pattern, add , wholeword, count , escapeArgs)
2707
+ function ! s: GetGrepCommandLine (pattern, add , wholeword, count , escapeArgs, filterTargetsWithNoFiles )
2714
2708
2715
2709
call s: CheckCommandRequirements ()
2716
2710
@@ -2777,7 +2771,7 @@ function! s:GetGrepCommandLine(pattern, add, wholeword, count, escapeArgs)
2777
2771
let fileTargetList = s: GetFileTargetList (1 )
2778
2772
let filesToExclude = g: EasyGrepFilesToExclude
2779
2773
2780
- if s: CommandHas (" opt_bool_filtertargetswithnofiles" )
2774
+ if a: filterTargetsWithNoFiles && s: CommandHas (" opt_bool_filtertargetswithnofiles" )
2781
2775
call s: FilterTargetsWithNoFiles (fileTargetList)
2782
2776
endif
2783
2777
@@ -2790,22 +2784,19 @@ function! s:GetGrepCommandLine(pattern, add, wholeword, count, escapeArgs)
2790
2784
let opts .= " " . join (map (split (filesToExclude, ' ,' ), commandParams[" opt_str_mapexclusionsexpression" ]), ' ' ) . " "
2791
2785
endif
2792
2786
2793
- if s: CommandHas (" opt_bool_replacewildcardwithcwd" )
2794
- " 1) Replace a leading star with the current directory
2795
- " 2) Replace all trailing stars with a space
2787
+ if s: CommandHas (" opt_bool_isinherentlyrecursive" )
2788
+ " Eliminate a trailing star
2789
+ call map (fileTargetList, ' substitute(v:val, "/\\*$", "/", "")' )
2790
+ " " Replace an individual star with a dot
2796
2791
call map (fileTargetList, ' substitute(v:val, "^\\*$", s:GetGrepRoot(), "")' )
2797
2792
endif
2798
2793
2799
2794
" Set extra inclusions and exclusions
2800
- if s: CommandHas (" opt_bool_greprecursionwar" )
2801
- " Specific inclusions are only set in recursive mode
2802
- if s: IsRecursiveSearch ()
2803
- " The --include paths will contain the file patterns
2804
- let opts .= " " . join (map (fileTargetList, ' "--include=\"" .v:val."\""' ), ' ' ). " "
2805
-
2806
- " while the files we specify will be directories
2807
- let fileTargetList = s: GetDirectorySearchList ()
2808
- endif
2795
+ if s: CommandHasLen (" opt_str_recursiveinclusionexpression" ) && s: IsRecursiveSearch ()
2796
+ " Explicitly specify the file types as arguments according to the configured expression
2797
+ let opts .= " " . join (map (fileTargetList, commandParams[" opt_str_recursiveinclusionexpression" ]), ' ' ). " "
2798
+ " while the files we specify will be directories
2799
+ let fileTargetList = s: GetDirectorySearchList ()
2809
2800
endif
2810
2801
2811
2802
let filesToGrep = join (fileTargetList, ' ' )
@@ -2856,7 +2847,7 @@ function! s:DoGrep(pattern, add, wholeword, count, escapeArgs)
2856
2847
endif
2857
2848
2858
2849
call s: SetGrepVariables (commandName)
2859
- let grepCommand = s: GetGrepCommandLine (a: pattern , a: add , a: wholeword , a: count , a: escapeArgs )
2850
+ let grepCommand = s: GetGrepCommandLine (a: pattern , a: add , a: wholeword , a: count , a: escapeArgs, 1 )
2860
2851
2861
2852
" change directory to the grep root before executing
2862
2853
call s: ChangeDirectoryToGrepRoot ()
0 commit comments