From 0773fdd7bde5e7ce462c15bd1c71db3a3e46862a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 Apr 2017 05:45:43 +0200 Subject: autoload/gitcha.vim: Add commit subject to completion popup (WIP) Initial try at adding the commit subject to the popup menu to provide context for the commit. Currently only shows the first word of the subject because I'm using `split()`. --- autoload/gitcha.vim | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim index bde75a2..d84cf15 100644 --- a/autoload/gitcha.vim +++ b/autoload/gitcha.vim @@ -19,9 +19,10 @@ function! gitcha#GitSHAComplete(findstart, base) " 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 + let revs = system('git rev-list --all --pretty=oneline --no-abbrev-commit') + + for m in s:BuildMatchDictionary(revs) + if m['word'] =~ '^' . a:base call add(matches, m) endif endfor @@ -29,6 +30,29 @@ function! gitcha#GitSHAComplete(findstart, base) return matches endfunction +" Takes rev-list output from: +" $ git rev-list --all --pretty=oneline --no-abbrev-commit +" +" Creates a dictionary to be used for matching that uses commit SHAs for the +" completion word and the commit subject as extra text. +function! s:BuildMatchDictionary(rev_list) + let matches = [] + let commits = split(a:rev_list, '\n') + + for commit in commits + let commit_parts = split(commit) + let sha = commit_parts[0] + let subject = commit_parts[1] + + call add(matches, { + \ 'word': sha, + \ 'menu': subject + \ }) + endfor + + return matches +endfunction + " Allow mappings to initiate completion function! gitcha#StartGitSHACompletion() set completefunc=gitcha#GitSHAComplete -- cgit v1.2.3