Skip to content

Commit

Permalink
Merge branch 'davidszotten/traverse-scm' into next
Browse files Browse the repository at this point in the history
* davidszotten/traverse-scm:
  Tweak SCM traversal
  Add option to search from nearest scm parent
  • Loading branch information
wincent committed Jul 30, 2014
2 parents 4ca835c + 8a38757 commit ebcda3c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
60 changes: 46 additions & 14 deletions doc/command-t.txt
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,34 @@ Following is a list of all available options:
Command-T would usually consult, such as 'wildignore' and
|g:CommandTScanDotDirectories| are ignored.

*g:CommandTTraverseSCM*
|g:CommandTTraverseSCM| string (default: 'file')

Instructs Command-T how to chose a root path when opening a file finder
without an explicit path argument. Possible values are:

- "file": starting from the file currently being edited, traverse
upwards through the filesystem hierarchy until you find an SCM root
(as indicated by the presence of a ".git", ".hg" or similar directory)
and use that as the base path. If no such root is found, fallback to
using Vim's present working directory as a root. The list of SCM
directories that Command-T uses to detect an SCM root can be
customized with the |g:CommandTSCMDirectories| option.

- "dir": traverse upwards looking for an SCM root just like the "file"
setting (above), but instead of starting from the file currently being
edited, start from Vim's present working directory instead.

- "pwd": use Vim's present working directory as a root (ie. attempt no
traversal).

*g:CommandTSCMDirectories*
|g:CommandTSCMDirectories| string (default: '.git,.hg,.svn,.bzr,_darcs')

The marker directories that Command-T will use to identify SCM roots
during traversal (see |g:CommandTTraverseSCM| above).


*g:CommandTMinHeight*
|g:CommandTMinHeight| number (default: 0)

Expand Down Expand Up @@ -1024,20 +1052,21 @@ Command-T is written and maintained by Greg Hurrell <greg@hurrell.net>.
Other contributors that have submitted patches include (in alphabetical
order):

Abhinav Gupta Matthew Todd Scott Bronson
Andy Waite Mike Lundy Seth Fowler
Anthony Panozzo Nadav Samet Shlomi Fish
Artem Nezvigin Nate Kane Steven Moazami
Daniel Hahler Nicholas Alpi Sung Pae
Felix Tjandrawibawa Noon Silk Thomas Pelletier
Gary Bernhardt Ole Petter Bang Ton van den Heuvel
Ivan Ukhov Patrick Hayes Victor Hugo Borja
Jacek Wysocki Paul Jolly Vít Ondruch
Jeff Kreeftmeijer Pavel Sergeev Woody Peterson
Kevin Webster Rainux Luo Yan Pritzker
Lucas de Vries Richard Feldman Yiding Jia
Marcus Brito Roland Puntaier Zak Johnson
Marian Schubert Ross Lagerwall
Abhinav Gupta Marian Schubert Scott Bronson
Andy Waite Matthew Todd Seth Fowler
Anthony Panozzo Mike Lundy Shlomi Fish
Artem Nezvigin Nadav Samet Steven Moazami
Ben Osheroff Nate Kane Sung Pae
Daniel Hahler Nicholas Alpi Thomas Pelletier
David Szotten Noon Silk Ton van den Heuvel
Felix Tjandrawibawa Ole Petter Bang Victor Hugo Borja
Gary Bernhardt Patrick Hayes Vít Ondruch
Ivan Ukhov Paul Jolly Woody Peterson
Jacek Wysocki Pavel Sergeev Yan Pritzker
Jeff Kreeftmeijer Rainux Luo Yiding Jia
Kevin Webster Richard Feldman Zak Johnson
Lucas de Vries Roland Puntaier
Marcus Brito Ross Lagerwall

As this was the first Vim plug-in I had ever written I was heavily influenced
by the design of the LustyExplorer plug-in by Stephen Bach, which I understand
Expand Down Expand Up @@ -1137,6 +1166,9 @@ HISTORY *command-t-history*
Richard Feldman)
- add "git" file scanner (patch from Patrick Hayes)
- speed-up when 'wildignore' is unset (patch from Patrick Hayes)
- add |g:CommandTTraverseSCM| setting which anchors Command-T's file finder to
the nearest SCM directory (based on patches from David Szotten and Ben
Osheroff)

1.10 (15 July 2014)

Expand Down
23 changes: 22 additions & 1 deletion ruby/command-t/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ def show_tag_finder

def show_file_finder
# optional parameter will be desired starting directory, or ""
@path = File.expand_path(::VIM::evaluate('a:arg'), VIM::pwd)

arg = ::VIM::evaluate('a:arg')
if arg && arg.size > 0
@path = File.expand_path(arg, VIM::pwd)
else
traverse = get_string('g:CommandTTraverseSCM') || 'file'
case traverse
when 'file'
@path = nearest_ancestor(VIM::current_file_dir, scm_markers)
when 'dir'
@path = nearest_ancestor(VIM::pwd, scm_markers)
end
end

@path = VIM::pwd unless @path
@active_finder = file_finder
file_finder.path = @path
show
Expand Down Expand Up @@ -202,6 +216,13 @@ def vsplit_command

private

def scm_markers
markers = get_string('g:CommandTSCMDirectories')
markers = markers && markers.split(/\s*,\s*/)
markers = %w[.git .hg .svn .bzr _darcs] unless markers && markers.length
markers
end

def list_matches!
list_matches(:force => true)
end
Expand Down
4 changes: 4 additions & 0 deletions ruby/command-t/vim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def self.wild_ignore
exists?('&wildignore') && ::VIM::evaluate('&wildignore').to_s
end

def self.current_file_dir
::VIM::evaluate 'expand("%:p:h")'
end

# Execute cmd, capturing the output into a variable and returning it.
def self.capture cmd
::VIM::command 'silent redir => g:command_t_captured_output'
Expand Down
13 changes: 13 additions & 0 deletions ruby/command-t/vim/path_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ def relative_path_under_working_directory path
pwd = File.expand_path(VIM::pwd) + '/'
path.index(pwd) == 0 ? path[pwd.length..-1] : path
end

def nearest_ancestor(starting_directory, markers)
path = File.expand_path(starting_directory)
while !markers.
map { |dir| File.join(path, dir) }.
map { |dir| File.directory?(dir) }.
any?
return nil if path == '/'
path = File.expand_path(File.join(path, '..'))
end
path
end

end # module PathUtilities
end # module VIM
end # module CommandT

0 comments on commit ebcda3c

Please sign in to comment.