Add mq status for hg repositories

Now that we have async feature for Vim 8, we can add the output of 'hg
qtop' back to the statusline if it is supported
This commit is contained in:
Christian Brabandt 2016-10-20 22:23:01 +02:00
parent 64d91665fe
commit 14ab47cae6
1 changed files with 50 additions and 1 deletions

View File

@ -106,7 +106,18 @@ endfunction
function! s:get_hg_branch()
if s:has_lawrencium
return lawrencium#statusline()
let stl=lawrencium#statusline()
if !empty(stl) && has('job')
call s:get_mq_async('hg qtop', expand('%:p'))
endif
if exists("s:mq") && !empty(s:mq)
if stl is# 'default'
" Shorten default a bit
let stl='def'
endif
let stl.=' ['.s:mq.']'
endif
return stl
endif
return ''
endfunction
@ -154,6 +165,44 @@ if s:has_async
\ 'close_cb': function('s:on_exit', options)})
let s:jobs[a:file] = id
endfu
function! s:on_exit_mq(channel) dict abort
if !empty(self.buf)
if self.buf is# 'no patches applied' ||
\ self.buf =~# "unknown command 'qtop'"
let self.buf = ''
elseif exists("s:mq") && s:mq isnot# self.buf
" make sure, statusline is updated
unlet! b:airline_head
endif
let s:mq = self.buf
endif
if has_key(s:jobs, self.file)
call remove(s:jobs, self.file)
endif
endfunction
function! s:get_mq_async(cmd, file)
if g:airline#util#is_windows && &shell =~ 'cmd'
let cmd = a:cmd. shellescape(a:file)
else
let cmd = ['sh', '-c', a:cmd]
endif
let options = {'cmd': a:cmd, 'buf': '', 'file': a:file}
if has_key(s:jobs, a:file)
if job_status(get(s:jobs, a:file)) == 'run'
return
elseif has_key(s:jobs, a:file)
call remove(s:jobs, a:file)
endif
endif
let id = job_start(cmd, {
\ 'err_io': 'out',
\ 'out_cb': function('s:on_stdout', options),
\ 'close_cb': function('s:on_exit_mq', options)})
let s:jobs[a:file] = id
endfu
endif
function! airline#extensions#branch#head()