@@ -147,7 +147,8 @@ function! s:GetBufferDirsList()
147
147
endif
148
148
let dirs[d ]= 1
149
149
endfor
150
- return keys (dirs)
150
+ " Note that this returns a unique set of directories
151
+ return sort (keys (dirs))
151
152
endfunction
152
153
" }}}
153
154
" GetVisibleBuffers {{{
@@ -670,13 +671,13 @@ endfunction
670
671
" }}}
671
672
" AddAdditionalLocationsToFileTargetList {{{
672
673
function ! s: AddAdditionalLocationsToFileTargetList (lst)
673
- if empty (a: lst ) || s: IsModeBuffers ()
674
- return a: lst
674
+ let lst = a: lst
675
+ if empty (lst) || s: IsModeBuffers ()
676
+ return lst
675
677
endif
676
678
677
- let lst = a: lst
678
679
if g: EasyGrepSearchCurrentBufferDir && s: IsBufferDirSearchAllowed ()
679
- let lst = s: AddBufferDirsToFileTargetList (lst)
680
+ let lst = s: ApplySearchDirectoriesToFileTargetList (lst)
680
681
endif
681
682
682
683
if g: EasyGrepHidden
@@ -718,14 +719,14 @@ function! s:AddAdditionalLocationsToFileTargetList(lst)
718
719
return newlst
719
720
endfunction
720
721
" }}}
721
- " AddBufferDirsToFileTargetList {{{
722
- function ! s: AddBufferDirsToFileTargetList (lst )
723
- let lst = a: lst
722
+ " ApplySearchDirectoriesToFileTargetList {{{
723
+ function ! s: ApplySearchDirectoriesToFileTargetList (fileTargets )
724
+ let fileTargets = a: fileTargets
724
725
725
726
" Build a list of the directories in buffers
726
- let dirs = sort ( s: GetBufferDirsList () )
727
+ let dirs = s: GetBufferDirsList ()
727
728
728
- let newlst = copy (lst )
729
+ let newlst = copy (fileTargets )
729
730
730
731
let root = s: GetGrepRoot ()
731
732
let currDir = s: GetCwdEscaped ()
@@ -747,7 +748,7 @@ function! s:AddBufferDirsToFileTargetList(lst)
747
748
endif
748
749
if addToList
749
750
call add (accepteddirs, dir )
750
- for p in lst
751
+ for p in fileTargets
751
752
call add (newlst, dir ." /" .p )
752
753
endfor
753
754
endif
@@ -785,18 +786,29 @@ function! s:IsRecursivelyReachable(fromthisdir, target)
785
786
return 1
786
787
endfunction
787
788
" }}}
788
- " GetRecursiveMinimalSetList {{{
789
- function ! s: GetRecursiveMinimalSetList ()
789
+ " GetDirectorySearchList {{{
790
+ function ! s: GetDirectorySearchList ()
791
+ if ! g: EasyGrepSearchCurrentBufferDir
792
+ return [ s: GetGrepRoot () ]
793
+ endif
790
794
795
+ let root = s: GetGrepRoot ()
791
796
let currDir = s: GetCwdEscaped ()
792
- let bufferdirs = sort (s: GetBufferDirsList ())
793
- let bufferSetList = [ s: GetGrepRoot () ]
797
+ let bufferDirs = s: GetBufferDirsList ()
794
798
795
- for dir in bufferdirs
799
+ call add (bufferDirs, root)
800
+ let bufferDirsWithRoot = sort (bufferDirs)
801
+
802
+ let bufferSetList = []
803
+
804
+ let i = 0
805
+ let end = len (bufferDirsWithRoot)
806
+ while i < end
807
+ let dir = bufferDirsWithRoot[i ]
796
808
let addToList = 1
797
- if dir == currDir || dir == ' . '
809
+ if ( i > 0 ) && ( dir == bufferDirsWithRoot[ i - 1 ])
798
810
let addToList = 0
799
- else
811
+ elseif s: IsRecursiveSearch ()
800
812
for d in bufferSetList
801
813
if s: IsRecursivelyReachable (d , dir )
802
814
let addToList = 0
@@ -807,24 +819,22 @@ function! s:GetRecursiveMinimalSetList()
807
819
if addToList
808
820
call add (bufferSetList, s: FileEscape (dir ))
809
821
endif
810
- endfor
822
+ let i += 1
823
+ endwhile
811
824
812
- return bufferSetList
813
- endfunction
814
- " }}}
815
- " GetDirectorySearchList {{{
816
- function ! s: GetDirectorySearchList ()
817
- if g: EasyGrepSearchCurrentBufferDir
818
- if s: IsRecursiveSearch ()
819
- return s: GetRecursiveMinimalSetList ()
820
- else
821
- let lst = [s: GetGrepRoot ()]
822
- call s: AddBufferDirsToFileTargetList (lst)
823
- return lst
825
+ " Place the root as the first item if possible
826
+ let i = 0
827
+ let end = len (bufferSetList)
828
+ while i < end
829
+ if bufferSetList[i ] == root
830
+ call remove (bufferSetList, i )
831
+ call insert (bufferSetList, root, 0 )
832
+ break
824
833
endif
825
- else
826
- return [ s: GetGrepRoot () ]
827
- endif
834
+ let i += 1
835
+ endwhile
836
+
837
+ return bufferSetList
828
838
endfunction
829
839
" }}}
830
840
" CheckIfCurrentFileIsSearched {{{
@@ -1041,27 +1051,30 @@ function! <sid>EchoGrepCommand()
1041
1051
return 0
1042
1052
endif
1043
1053
1044
- let placeholder = " <pattern> "
1045
- let dirAnnotation = " Grep Root : "
1046
- let grepCommand = s: GetGrepCommandLine (placeholder, " " , 0 , " " , 1 )
1054
+ let recursiveTag = s: IsRecursiveSearch () ? " (Recursive) " : " "
1055
+ call s: Echo ( " Search Mode : " . s: GetModeName ( g: EasyGrepMode ).recursiveTag)
1056
+
1047
1057
if g: EasyGrepSearchCurrentBufferDir && s: IsBufferDirSearchAllowed ()
1048
1058
let dirs = s: GetDirectorySearchList ()
1059
+ let dirAnnotation = " Search Directory: "
1049
1060
for d in dirs
1050
1061
call s: Echo (dirAnnotation.d )
1051
1062
let dirAnnotation = " Additional Directory: "
1052
1063
endfor
1053
- let bufferDirs = s: GetBufferDirsList ()
1054
- if (len (bufferDirs) > len (dirs))
1055
- call s: Echo (" Note: Additional directories covered by recursive search" )
1056
- endif
1057
1064
else
1065
+ let dirAnnotation = " Search Directory: "
1058
1066
call s: Echo (dirAnnotation.s: GetGrepRoot ())
1059
1067
endif
1068
+
1069
+ let placeholder = " <pattern>"
1070
+ let grepCommand = s: GetGrepCommandLine (placeholder, " " , 0 , " " , 1 )
1060
1071
call s: Echo (" VIM command: " .grepCommand)
1072
+
1061
1073
if s: GetGrepCommandName () == " grep"
1062
1074
let shellCommand = substitute (grepCommand, " grep" , &grepprg , " " )
1063
1075
call s: Echo (" Shell command: " .shellCommand)
1064
1076
endif
1077
+
1065
1078
if s: GetGrepCommandChoice (0 ) != s: GetGrepCommandChoice (1 )
1066
1079
call s: Echo (" Note: " ." Overriding '" .substitute (s: GetGrepCommandName (0 ), " grep" , &grepprg , " " )." ' with '" .s: GetGrepCommandName (1 )." ' due to 'Buffers' mode" )
1067
1080
endif
@@ -2669,8 +2682,8 @@ function! s:ConfigureGrepCommandParameters()
2669
2682
\ ' opt_bool_bufferdirsearchallowed' : ' 1' ,
2670
2683
\ ' opt_str_suppresserrormessages' : ' ' ,
2671
2684
\ ' opt_bool_directoryneedsbackslash' : ' 0' ,
2672
- \ ' opt_bool_isinherentlyrecursive' : ' 0 ' ,
2673
- \ ' opt_bool_isselffiltering' : ' 0 ' ,
2685
+ \ ' opt_bool_isinherentlyrecursive' : ' 1 ' ,
2686
+ \ ' opt_bool_isselffiltering' : ' 1 ' ,
2674
2687
\ ' opt_bool_replacewildcardwithcwd' : ' 0' ,
2675
2688
\ })
2676
2689
0 commit comments