Skip to content

Commit

Permalink
Move ruby startup code to script local function
Browse files Browse the repository at this point in the history
Command-T takes about 320 ms to load on Vim startup. This is a lot
considering most other plugins takes less than 1 ms. In this pull
request I move the ruby startup code in command-t.vim to a script local
function and only call it when user uses Command-T. With this change,
command-t.vim takes less than 1 ms to load at Vim startup.

Via:

  wincent#14
  • Loading branch information
kien authored and wincent committed Jun 29, 2011
1 parent cee619a commit 86e87ab
Showing 1 changed file with 31 additions and 26 deletions.
57 changes: 31 additions & 26 deletions plugin/command-t.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ endfunction

function s:CommandTShowBufferFinder()
if has('ruby')
call s:Initialize()
ruby $command_t.show_buffer_finder
else
call s:CommandTRubyWarning()
Expand All @@ -56,6 +57,7 @@ endfunction

function s:CommandTShowFileFinder(arg)
if has('ruby')
call s:Initialize()
ruby $command_t.show_file_finder
else
call s:CommandTRubyWarning()
Expand All @@ -64,6 +66,7 @@ endfunction

function s:CommandTFlush()
if has('ruby')
call s:Initialize()
ruby $command_t.flush
else
call s:CommandTRubyWarning()
Expand All @@ -74,6 +77,33 @@ if !has('ruby')
finish
endif

function s:Initialize()
ruby << EOF
# require Ruby files
begin
# prepare controller
require 'command-t/vim'
require 'command-t/controller'
$command_t = CommandT::Controller.new
rescue LoadError
load_path_modified = false
::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
lib = "#{path}/ruby"
if !$LOAD_PATH.include?(lib) and File.exist?(lib)
$LOAD_PATH << lib
load_path_modified = true
end
end
retry if load_path_modified

# could get here if C extension was not compiled, or was compiled
# for the wrong architecture or Ruby version
require 'command-t/stub'
$command_t = CommandT::Stub.new
end
EOF
endfunction

function CommandTHandleKey(arg)
ruby $command_t.handle_key
endfunction
Expand Down Expand Up @@ -136,29 +166,4 @@ endfunction

function CommandTCursorStart()
ruby $command_t.cursor_start
endfunction

ruby << EOF
# require Ruby files
begin
# prepare controller
require 'command-t/vim'
require 'command-t/controller'
$command_t = CommandT::Controller.new
rescue LoadError
load_path_modified = false
::VIM::evaluate('&runtimepath').to_s.split(',').each do |path|
lib = "#{path}/ruby"
if !$LOAD_PATH.include?(lib) and File.exist?(lib)
$LOAD_PATH << lib
load_path_modified = true
end
end
retry if load_path_modified

# could get here if C extension was not compiled, or was compiled
# for the wrong architecture or Ruby version
require 'command-t/stub'
$command_t = CommandT::Stub.new
end
EOF
endfunction

0 comments on commit 86e87ab

Please sign in to comment.