mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-06 12:14:26 +08:00
Extract commit message setup function
This commit is contained in:
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user