Extract commit message setup function

This commit is contained in:
Tim Pope
2021-04-12 13:56:24 -04:00
parent 42e9ee3f95
commit b4081f0a88

View File

@@ -11,25 +11,25 @@ if !exists('g:dispatch_compilers')
endif
let g:dispatch_compilers['hub'] = 'git'
function! s:Config() abort
if exists('*FugitiveFind')
let dir = FugitiveFind('.git/config')[0:-8]
return filereadable(dir . '/config') ? readfile(dir . '/config') : []
else
return []
function! s:SetUpMessage(filename) abort
if &omnifunc !~# '^\%(syntaxcomplete#Complete\)\=$' ||
\ a:filename !~# '\.git[\/].*MSG$' ||
\ !exists('*FugitiveFind') || empty(FugitiveGitDir())
return
endif
let config_file = FugitiveFind('.git/config')
let config = filereadable(config_file) ? readfile(config_file) : []
if !empty(filter(config,
\ '!empty(rhubarb#HomepageForUrl(matchstr(v:val, ''^\s*url\s*=\s*"\=\zs\S*'')))'))
setlocal omnifunc=rhubarb#Complete
endif
endfunction
augroup rhubarb
autocmd!
autocmd User Fugitive
\ if expand('%:p') =~# '\.git[\/].*MSG$' &&
\ exists('+omnifunc') &&
\ &omnifunc =~# '^\%(syntaxcomplete#Complete\)\=$' &&
\ !empty(filter(s:Config(),
\ '!empty(rhubarb#HomepageForUrl(matchstr(v:val, ''^\s*url\s*=\s*"\=\zs\S*'')))')) |
\ setlocal omnifunc=rhubarb#Complete |
\ endif
if exists('+omnifunc')
autocmd User Fugitive call s:SetUpMessage(expand('%:p'))
endif
autocmd BufEnter *
\ if expand('%') ==# '' && &previewwindow && pumvisible() && getbufvar('#', '&omnifunc') ==# 'rhubarb#omnifunc' |
\ setlocal nolist linebreak filetype=markdown |