diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 81ac2539..33e56146 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -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()