From e7fb8f326e7c3e184e305286199640fdaac35d5b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 10 May 2017 00:24:43 +0200 Subject: autoload/gitcha.vim: Set completeopt+=menuone Work in progress Adds 'menuone' to the 'completeopt' option. This makes the popup menu display even if there's only a single result. We want this because it allows us to see the commit message subject for the completed SHA, providing a way to confirm that the completed SHA is the right one. Here, the idea was to try to save the user's 'completeopt' setting and restore it after completion, but we can't do that in `gitcha#GitSHAComplete` because if we do, it restores 'completeopt' before the completion menu is shown. Thus, it cancels out our custom `+=menuone` setting. After checking online to see how other plugins handle this (https://github.com/search?utf8=%E2%9C%93&q=completeopt+language%3AVimL+path%3A%2Fautoload&type=Code&ref=advsearch&l=&l=), I found that they use the `complete()` built-in function instead of overriding the user-designated 'completefunc' setting: https://github.com/heavenshell/vim-flood/blob/2bd8580642c56c2a090a8e44cc768e98019310be/autoload/flood/complete.vim This allows us to add `+=menuone` before calling `complete()` and remove the setting afterwards. Using `complete()` seems like the way to go here, so it looks like I'm going to have to refactor the code to do that instead in order to get "menuone" to work. The way I originally wrote the program was intuitive at the time. I'm glad I did it that way, because it provided me with the knowledge of how to remap the built-in completion mappings in Auditory.vim. Will have to try that out at some point. --- autoload/gitcha.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/gitcha.vim b/autoload/gitcha.vim index 7ed45c7..e5543f7 100644 --- a/autoload/gitcha.vim +++ b/autoload/gitcha.vim @@ -1,6 +1,7 @@ " Save user-defined completefunc so it 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) @@ -16,6 +17,7 @@ function! gitcha#GitSHAComplete(findstart, base) " Restore user completion function let &completefunc = s:old_completefunc + " let &completeopt = s:old_completeopt " Match Git SHAs in the current repository let matches = [] @@ -57,5 +59,6 @@ endfunction " Allow mappings to initiate completion function! gitcha#StartGitSHACompletion() set completefunc=gitcha#GitSHAComplete + set completeopt=menu,menuone,preview return "\\" endfunction -- cgit v1.2.3