From ee60b16343ff5e98dc4279bb976586001a002bfe Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 Apr 2017 04:48:35 +0200 Subject: Move functions to autoload/ Don't force our functions to be loaded when the ftplugin is loaded. Be good Vimscript citizens and respect load performance. --- autoload/gitcha.vim | 32 ++++++++++++++++++++++++++++++++ ftplugin/gitcommit/gitcha.vim | 35 +---------------------------------- 2 files changed, 33 insertions(+), 34 deletions(-) create mode 100644 autoload/gitcha.vim diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim new file mode 100644 index 0000000..6defd61 --- /dev/null +++ b/autoload/gitcha.vim @@ -0,0 +1,32 @@ +let s:old_completefunc = &completefunc + +function! gitcha#GitSHAComplete(findstart, base) + if a:findstart + " locate the start of the word + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '\a' + let start -= 1 + endwhile + return start + endif + + " Restore user completion function + let &completefunc = s:old_completefunc + + " Match Git SHAs in the current repository + let matches = [] + let revs = system('git rev-list --all') + for m in split(revs) + if m =~ '^' . a:base + call add(matches, m) + endif + endfor + + return matches +endfunction + +function! gitcha#StartGitSHACompletion() + set completefunc=gitcha#GitSHAComplete + return "\\" +endfunction diff --git a/ftplugin/gitcommit/gitcha.vim b/ftplugin/gitcommit/gitcha.vim index e08f2e0..ecd1e90 100644 --- a/ftplugin/gitcommit/gitcha.vim +++ b/ftplugin/gitcommit/gitcha.vim @@ -1,34 +1 @@ -let s:old_completefunc = &completefunc - -function! GitSHAComplete(findstart, base) - if a:findstart - " locate the start of the word - let line = getline('.') - let start = col('.') - 1 - while start > 0 && line[start - 1] =~ '\a' - let start -= 1 - endwhile - return start - endif - - " Restore user completion function - let &completefunc = s:old_completefunc - - " Match Git SHAs in the current repository - let matches = [] - let revs = system('git rev-list --all') - for m in split(revs) - if m =~ '^' . a:base - call add(matches, m) - endif - endfor - - return matches -endfunction - -function! StartGitSHACompletion() - set completefunc=GitSHAComplete - return "\\" -endfunction - -inoremap StartGitSHACompletion() +inoremap gitcha#StartGitSHACompletion() -- cgit v1.2.3