aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-05-10 21:06:38 +0200
committerTeddy Wing2017-05-10 21:06:38 +0200
commit0bbf4337a6b7c6b0fc0d216a02897b5c45ebc36b (patch)
treed64fbbe9ea49b8ea5b60d8823d5913b1ffcfcdd0
parent5eca0d8f26acf29edbcc2376f6a8cd7a9d928a2f (diff)
parent69a382bf1d6cd4645dfb4408f757368b069694fc (diff)
downloadvim-gitcha-0bbf4337a6b7c6b0fc0d216a02897b5c45ebc36b.tar.bz2
Merge branch 'completeopt-menuone'
-rw-r--r--autoload/gitcha.vim40
-rw-r--r--ftplugin/gitcommit/gitcha.vim2
2 files changed, 18 insertions, 24 deletions
diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim
index 7ed45c7..13d61bf 100644
--- a/autoload/gitcha.vim
+++ b/autoload/gitcha.vim
@@ -1,33 +1,33 @@
-" Save user-defined completefunc so it can be restored after running this
+" Save user-defined 'completeopt's so they can be restored after running this
" custom completion function
-let s:old_completefunc = &completefunc
+let s:old_completeopt = &completeopt
" Completion for Git SHAs in the current repository
-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] =~ '[0-9a-f]'
- let start -= 1
- endwhile
- return start
- endif
-
- " Restore user completion function
- let &completefunc = s:old_completefunc
+function! gitcha#GitSHAComplete()
+ let line = getline('.')
+ let start = col('.')
+ while start > 0 && line[start - 2] =~ '[0-9a-f]'
+ let start -= 1
+ endwhile
" Match Git SHAs in the current repository
let matches = []
let revs = system('git rev-list --all --pretty=oneline --no-abbrev-commit')
+ let base = line[start - 1 : col('.') - 1]
for m in s:BuildMatchDictionary(revs)
- if m['word'] =~ '^' . a:base
+ if m['word'] =~ '^' . base
call add(matches, m)
endif
endfor
- return matches
+ set completeopt=menu,menuone,preview
+
+ call complete(start, matches)
+
+ let &completeopt = s:old_completeopt
+
+ return ''
endfunction
" Takes rev-list output from:
@@ -53,9 +53,3 @@ function! s:BuildMatchDictionary(rev_list)
return matches
endfunction
-
-" Allow mappings to initiate completion
-function! gitcha#StartGitSHACompletion()
- set completefunc=gitcha#GitSHAComplete
- return "\<C-x>\<C-u>"
-endfunction
diff --git a/ftplugin/gitcommit/gitcha.vim b/ftplugin/gitcommit/gitcha.vim
index 19f4a0b..c81cf26 100644
--- a/ftplugin/gitcommit/gitcha.vim
+++ b/ftplugin/gitcommit/gitcha.vim
@@ -12,6 +12,6 @@ if !hasmapto('<Plug>GitchaCompleteSHA')
imap <buffer> <C-x><C-s> <Plug>GitchaCompleteSHA
endif
-inoremap <buffer> <expr> <Plug>GitchaCompleteSHA gitcha#StartGitSHACompletion()
+inoremap <buffer> <Plug>GitchaCompleteSHA <C-r>=gitcha#GitSHAComplete()<CR>
let b:undo_ftplugin = 'iunmap <buffer> <C-x><C-s>'