Skip to content

Commit

Permalink
Add g:CommandTMaxCachedDirectories option
Browse files Browse the repository at this point in the history
This allows the user to specify an upper limit on the number of caches
which Command-T will use when changing directories. The default of 1
preserves the existing behavior, meaning that each time you change into
a different directory, Command-T will scan it.

Set to a higher number to increase the number of cached directories, or
to 0 for no limit at all.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information
wincent committed Sep 28, 2011
1 parent 226f677 commit a05def7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions doc/command-t.txt
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ Following is a list of all available options:
current directory. Any directories at levels beyond this depth will be
skipped.

*g:CommandTMaxCachedDirectories*
|g:CommandTMaxCachedDirectories| number (default 1)

The maximum number of directories whose contents should be cached when
recursively scanning. With the default value of 1, each time you change
directories the cache will be emptied and Command-T will have to
rescan. Higher values will make Command-T hold more directories in the
cache, bringing performance at the cost of memory usage. If set to 0,
there is no limit on the number of cached directories.

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

Expand Down Expand Up @@ -650,6 +660,11 @@ POSSIBILITY OF SUCH DAMAGE.

HISTORY *command-t-history*

1.3 (not yet released)

- added the option to maintain multiple caches when changing among
directories; see the accompanying |g:CommandTMaxCachedDirectories| setting

1.2.1 (30 April 2011)

- Remove duplicate copy of the documentation that was causing "Duplicate tag"
Expand Down
3 changes: 2 additions & 1 deletion ruby/command-t/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ def set_up_max_height

def set_up_file_finder
@file_finder = CommandT::FileFinder.new nil,
:max_files => get_number('g:CommandTMaxFiles'),
:max_depth => get_number('g:CommandTMaxDepth'),
:max_files => get_number('g:CommandTMaxFiles'),
:max_caches => get_number('g:CommandTMaxCachedDirectories'),
:always_show_dot_files => get_bool('g:CommandTAlwaysShowDotFiles'),
:never_show_dot_files => get_bool('g:CommandTNeverShowDotFiles'),
:scan_dot_directories => get_bool('g:CommandTScanDotDirectories')
Expand Down
12 changes: 12 additions & 0 deletions ruby/command-t/scanner/file_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ class FileLimitExceeded < ::RuntimeError; end

def initialize path = Dir.pwd, options = {}
@paths = {}
@paths_keys = []
@path = path
@max_depth = options[:max_depth] || 15
@max_files = options[:max_files] || 10_000
@max_caches = options[:max_caches] || 1
@scan_dot_directories = options[:scan_dot_directories] || false
end

def paths
return @paths[@path] if @paths.has_key?(@path)
begin
ensure_cache_under_limit
@paths[@path] = []
@depth = 0
@files = 0
Expand All @@ -57,6 +60,15 @@ def flush

private

def ensure_cache_under_limit
# Ruby 1.8 doesn't have an ordered hash, so use a separate stack to
# track and expire the oldest entry in the cache
if @max_caches > 0 && @paths_keys.length >= @max_caches
@paths.delete @paths_keys.shift
end
@paths_keys << @path
end

def path_excluded? path
# first strip common prefix (@path) from path to match VIM's behavior
path = path[(@prefix_len + 1)..-1]
Expand Down

0 comments on commit a05def7

Please sign in to comment.