From 08dd78c72a5935fd1aa458c28c2b045a2e4aab39 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 28 Apr 2017 01:14:39 +0200 Subject: ftplugin/gitcommit.vim: Restore user completion function Make our custom mapping work while retaining any user-defined `completefunc`. Doing it this way enables us to get away without having to set a hacky `CursorMovedI` unsetting autocommand as imagined in e70d92c495001c0af0037b9fadbeec170d2c318f. We clutter our `GitSHAComplete` completion function a bit with functionality that doesn't really belong to it in order to get a win for simple implementation of the `completefunc` restore feature. --- ftplugin/gitcommit.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ftplugin/gitcommit.vim b/ftplugin/gitcommit.vim index 485a7c1..e08f2e0 100644 --- a/ftplugin/gitcommit.vim +++ b/ftplugin/gitcommit.vim @@ -1,3 +1,5 @@ +let s:old_completefunc = &completefunc + function! GitSHAComplete(findstart, base) if a:findstart " locate the start of the word @@ -9,6 +11,9 @@ function! GitSHAComplete(findstart, base) 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') @@ -22,12 +27,8 @@ function! GitSHAComplete(findstart, base) endfunction function! StartGitSHACompletion() - let old_completefunc = &completefunc - set completefunc=GitSHAComplete return "\\" - - let &completefunc = old_completefunc endfunction inoremap StartGitSHACompletion() -- cgit v1.2.3