aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/gitcha.vim
diff options
context:
space:
mode:
authorTeddy Wing2017-05-10 05:10:41 +0200
committerTeddy Wing2017-05-10 05:53:57 +0200
commit60bc8ea8b3b7be511c4240ca1d7dc1cc1149b113 (patch)
tree2f118dac7c6085c63c95ffad4dec3d437d436dc8 /autoload/gitcha.vim
parente7fb8f326e7c3e184e305286199640fdaac35d5b (diff)
downloadvim-gitcha-60bc8ea8b3b7be511c4240ca1d7dc1cc1149b113.tar.bz2
gitcha#GitSHAComplete(): Use `complete()` to open popup menu (WIP)
Work in progress Rough code for a working implementation using `complete()` instead of 'completefunc'. Rejigger `start` and make a new `base` variable since we can no longer get it as an argument. Correctly reset 'completeopt' to its original user value after opening the popup menu. Return an empty string from the function as recommended by :h complete()
Diffstat (limited to 'autoload/gitcha.vim')
-rw-r--r--autoload/gitcha.vim36
1 files changed, 21 insertions, 15 deletions
diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim
index e5543f7..c2e30b1 100644
--- a/autoload/gitcha.vim
+++ b/autoload/gitcha.vim
@@ -4,32 +4,36 @@ 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
+function! gitcha#GitSHAComplete()
+ " 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 = col('.')
+ while start > 0 && line[start - 2] =~ '[0-9a-f]'
let start -= 1
endwhile
- return start
- endif
-
- " Restore user completion function
- let &completefunc = s:old_completefunc
- " let &completeopt = s:old_completeopt
+ " return start
+ " endif
" 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
+ " echom start
+ " echom string(matches)
+ " let &completeopt = 'menu,pattern,menuone'
+ set completeopt=menu,menuone,preview
+ call complete(start, matches)
+ " call complete(col('.'), matches)
+ let &completeopt = s:old_completeopt
+ return ''
endfunction
" Takes rev-list output from:
@@ -58,7 +62,9 @@ endfunction
" Allow mappings to initiate completion
function! gitcha#StartGitSHACompletion()
- set completefunc=gitcha#GitSHAComplete
- set completeopt=menu,menuone,preview
- return "\<C-x>\<C-u>"
+ " call gitcha#GitSHAComplete()
+ " return ''
+ " set completefunc=gitcha#GitSHAComplete
+ " set completeopt=menu,menuone,preview
+ " return "\<C-x>\<C-u>"
endfunction