Implemented vimtex status message system

This commit is contained in:
Karl Yngve Lervåg 2015-03-10 22:28:33 +01:00
parent 8ea72aa938
commit 9e6ebd44c7
5 changed files with 131 additions and 87 deletions

View File

@ -12,6 +12,7 @@ function! vimtex#init() " {{{1
call s:init_environment() call s:init_environment()
call vimtex#toc#init(s:initialized) call vimtex#toc#init(s:initialized)
call vimtex#echo#init(s:initialized)
call vimtex#fold#init(s:initialized) call vimtex#fold#init(s:initialized)
call vimtex#view#init(s:initialized) call vimtex#view#init(s:initialized)
call vimtex#motion#init(s:initialized) call vimtex#motion#init(s:initialized)
@ -35,7 +36,7 @@ function! vimtex#info() " {{{1
endif endif
" Print buffer data " Print buffer data
echo "b:vimtex" call vimtex#echo#echo("b:vimtex\n")
call s:print_dict(b:vimtex) call s:print_dict(b:vimtex)
" Print global data " Print global data
@ -48,8 +49,11 @@ function! vimtex#info() " {{{1
endfor endfor
" Print data blob title line " Print data blob title line
echo "\n" call vimtex#echo#formatted([
echo "g:vimtex#data[" . n . "] : " . remove(d, 'name') \ "\n\ng:vimtex#data[",
\ ['VimtexSuccess', n],
\ '] : ',
\ ['VimtexSuccess', remove(d, 'name') . "\n"]])
call s:print_dict(d) call s:print_dict(d)
let n += 1 let n += 1
endfor endfor
@ -61,7 +65,7 @@ function! vimtex#help() " {{{1
xmap <buffer> xmap <buffer>
omap <buffer> omap <buffer>
else else
echo "Mappings not enabled" call vimtex#echo#warning('vimtex mappings are not enabled')
endif endif
endfunction endfunction
@ -309,17 +313,18 @@ function! s:print_dict(dict, ...) " {{{1
for entry in sort(sort(items(a:dict), for entry in sort(sort(items(a:dict),
\ "s:print_dict_sort_2"), \ "s:print_dict_sort_2"),
\ "s:print_dict_sort_1") \ "s:print_dict_sort_1")
let title = repeat(' ', 2 + 2*level) . entry[0] . ' : ' let title = repeat(' ', 2 + 2*level) . entry[0]
if type(entry[1]) == type([]) if type(entry[1]) == type([])
echo title call vimtex#echo#echo(title)
for val in entry[1] for val in entry[1]
echo repeat(' ', 4 + 2*level) . string(val) call vimtex#echo#echo(repeat(' ', 4 + 2*level) . string(val), 'None')
endfor endfor
elseif type(entry[1]) == type({}) elseif type(entry[1]) == type({})
echo title call vimtex#echo#echo(title . "\n")
call s:print_dict(entry[1], level + 1) call s:print_dict(entry[1], level + 1)
else else
echo printf('%-s%-s', title, string(entry[1])) call vimtex#echo#formatted([title . ' : ',
\ ['None', string(entry[1]) . "\n"]])
endif endif
endfor endfor
endfunction endfunction

View File

@ -19,16 +19,21 @@ function! vimtex#complete#init(initialized) " {{{1
" Check if bibtex is available " Check if bibtex is available
if !executable('bibtex') if !executable('bibtex')
echom "Warning: bibtex completion not available" call vimtex#echo#warning('vimtex warning')
echom " Missing executable: bibtex" call vimtex#echo#warning(' bibtex completion is not available!',
\ 'None')
call vimtex#echo#warning(' bibtex is not executable', 'None')
let s:bibtex = 0 let s:bibtex = 0
endif endif
" Check if kpsewhich is required and available " Check if kpsewhich is required and available
if g:vimtex_complete_recursive_bib && !executable('kpsewhich') if s:bibtex && g:vimtex_complete_recursive_bib && !executable('kpsewhichc')
echom "Warning: bibtex completion not available" call vimtex#echo#warning('vimtex warning')
echom " Missing executable: kpsewhich" call vimtex#echo#warning(' bibtex completion is not available!',
echom " You could try to turn off recursive bib functionality" \ 'None')
call vimtex#echo#warning(' recursive bib search requires kpsewhich',
\ 'None')
call vimtex#echo#warning(' kpsewhich is not executable', 'None')
let s:bibtex = 0 let s:bibtex = 0
endif endif

51
autoload/vimtex/echo.vim Normal file
View File

@ -0,0 +1,51 @@
" vimtex - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: karl.yngve@gmail.com
"
function! vimtex#echo#init(initialized) " {{{1
highlight link VimtexMsg ModeMsg
highlight link VimtexSuccess Statement
highlight link VimtexWarning WarningMsg
endfunction
function! vimtex#echo#echo(message, ...) " {{{1
let hl = len(a:000) > 0 ? a:0 : 'VimtexMsg'
execute 'echohl' hl
echo a:message
echohl None
endfunction
function! vimtex#echo#warning(message, ...) " {{{1
let hl = len(a:000) > 0 ? a:0 : 'VimtexWarning'
execute 'echohl' hl
echomsg a:message
echohl None
endfunction
function! vimtex#echo#formatted(parts) " {{{1
try
for part in a:parts
if type(part) == type('')
echohl VimtexMsg
echon part
else
execute 'echohl' part[0]
echon part[1]
endif
unlet part
endfor
finally
echohl None
endtry
endfunction
function! vimtex#echo#status(parts) " {{{1
echon "\r"
call vimtex#echo#formatted(a:parts)
endfunction
" }}}1
" vim: fdm=marker sw=2

View File

@ -82,16 +82,8 @@ function! vimtex#latexmk#callback(status) " {{{1
call g:vimtex#data[b:vimtex.id].viewer.latexmk_callback() call g:vimtex#data[b:vimtex.id].viewer.latexmk_callback()
endif endif
echohl ModeMsg call vimtex#echo#status(['latexmk compile: ',
echon "latexmk compile: " \ a:status ? ['VimtexSuccess', 'success'] : ['VimtexWarning', 'fail']])
if a:status
echohl Statement
echon "success"
else
echohl WarningMsg
echon "fail"
endif
echohl None
return "" return ""
endfunction endfunction
@ -100,11 +92,8 @@ endfunction
function! vimtex#latexmk#clean(full) " {{{1 function! vimtex#latexmk#clean(full) " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = g:vimtex#data[b:vimtex.id]
if data.pid if data.pid
echohl ModeMsg call vimtex#echo#status(['latexmk clean: ',
echon "latexmk clean: " \ ['VimtexWarning', 'not while latexmk is running!']])
echohl WarningMsg
echon "not while latexmk is running!"
echohl None
return return
endif endif
@ -126,15 +115,8 @@ function! vimtex#latexmk#clean(full) " {{{1
call vimtex#util#execute(exe) call vimtex#util#execute(exe)
let g:vimtex#data[b:vimtex.id].cmd_latexmk_clean = cmd let g:vimtex#data[b:vimtex.id].cmd_latexmk_clean = cmd
echohl ModeMsg call vimtex#echo#status(['latexmk clean: ',
echon "latexmk clean: " \ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]])
echohl Statement
if a:full
echon "finished (full)"
else
echon "finished"
endif
echohl None
endfunction endfunction
" }}}1 " }}}1
@ -164,7 +146,8 @@ endfunction
function! vimtex#latexmk#compile() " {{{1 function! vimtex#latexmk#compile() " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = g:vimtex#data[b:vimtex.id]
if data.pid if data.pid
echomsg "latexmk is already running for `" . data.base . "'" call vimtex#echo#status(['latexmk compile: ',
\ ['VimtexWarning', 'already running for `' . data.base . "'"]])
return return
endif endif
@ -178,10 +161,11 @@ function! vimtex#latexmk#compile() " {{{1
if g:vimtex_latexmk_continuous if g:vimtex_latexmk_continuous
call s:latexmk_set_pid(data) call s:latexmk_set_pid(data)
call vimtex#echo#status(['latexmk compile: ',
echomsg 'latexmk started in continuous mode ...' \ ['VimtexSuccess', 'started continuous mode']])
else else
echomsg 'latexmk compiling ...' call vimtex#echo#status(['latexmk compile: ',
\ ['VimtexSuccess', 'compiling ...']])
endif endif
endfunction endfunction
@ -189,7 +173,8 @@ endfunction
function! vimtex#latexmk#compile_ss(verbose) " {{{1 function! vimtex#latexmk#compile_ss(verbose) " {{{1
let data = g:vimtex#data[b:vimtex.id] let data = g:vimtex#data[b:vimtex.id]
if data.pid if data.pid
echomsg "latexmk is already running for `" . data.base . "'" call vimtex#echo#status(['latexmk compile: '
\ ['VimtexWarning', 'already running for `' . data.base . "'"]])
return return
endif endif
@ -221,11 +206,8 @@ function! vimtex#latexmk#errors_open(force) " {{{1
let log = g:vimtex#data[b:vimtex.id].log() let log = g:vimtex#data[b:vimtex.id].log()
if empty(log) if empty(log)
if a:force if a:force
echohl ModeMsg call vimtex#echo#status(['latexmk errors: ',
echon "latexmk errors: " \ ['VimtexWarning', 'No log file found']])
echohl WarningMsg
echon "No log file found!"
echohl None
endif endif
return return
endif endif
@ -237,11 +219,8 @@ function! vimtex#latexmk#errors_open(force) " {{{1
endif endif
if empty(getqflist()) if empty(getqflist())
if a:force if a:force
echohl ModeMsg call vimtex#echo#status(['latexmk errors: ',
echon "latexmk errors: " \ ['VimtexSuccess', 'No errors!']])
echohl Statement
echon "No errors!"
echohl None
endif endif
return return
endif endif
@ -273,7 +252,7 @@ function! vimtex#latexmk#output() " {{{1
if has_key(g:vimtex#data[b:vimtex.id], 'tmp') if has_key(g:vimtex#data[b:vimtex.id], 'tmp')
let tmp = g:vimtex#data[b:vimtex.id].tmp let tmp = g:vimtex#data[b:vimtex.id].tmp
else else
echo "vimtex: No output exists" call vimtex#echo#status(['vimtex: ', ['VimtexWarning', 'No output exists']])
return return
endif endif
@ -309,7 +288,10 @@ function! vimtex#latexmk#status(detailed) " {{{1
for data in g:vimtex#data for data in g:vimtex#data
if data.pid if data.pid
if !running if !running
echo "latexmk is running" call vimtex#echo#status(['latexmk status: ',
\ ['VimtexSuccess', "running\n"]])
call vimtex#echo#status([['None', ' pid '],
\ ['None', "file\n"]])
let running = 1 let running = 1
endif endif
@ -318,18 +300,23 @@ function! vimtex#latexmk#status(detailed) " {{{1
let name = "..." . name[-winwidth('.')+23:] let name = "..." . name[-winwidth('.')+23:]
endif endif
echom printf('pid: %6s, file: %-s', data.pid, name) call vimtex#echo#status([
\ ['None', printf(' %-6s ', data.pid)],
\ ['None', name . "\n"]])
endif endif
endfor endfor
if !running if !running
echo "latexmk is not running" call vimtex#echo#status(['latexmk status: ',
\ ['VimtexWarning', 'not running']])
endif endif
else else
if g:vimtex#data[b:vimtex.id].pid if g:vimtex#data[b:vimtex.id].pid
echo "latexmk is running" call vimtex#echo#status(['latexmk status: ',
\ ['VimtexSuccess', 'running']])
else else
echo "latexmk is not running" call vimtex#echo#status(['latexmk status: ',
\ ['VimtexWarning', 'not running']])
endif endif
endif endif
endfunction endfunction
@ -341,17 +328,11 @@ function! vimtex#latexmk#stop() " {{{1
if pid if pid
call s:latexmk_kill_pid(pid) call s:latexmk_kill_pid(pid)
let g:vimtex#data[b:vimtex.id].pid = 0 let g:vimtex#data[b:vimtex.id].pid = 0
echohl ModeMsg call vimtex#echo#status(['latexmk compile: ',
echon "latexmk compile: " \ ['VimtexSuccess', 'stopped (' . base . ')']])
echohl Statement
echon "stopped (" . base . ")"
echohl None
else else
echohl ModeMsg call vimtex#echo#status(['latexmk compile: ',
echon "latexmk compile: " \ ['VimtexWarning', 'no process to stop (' . base . ')']])
echohl WarningMsg
echon "no process to stop (" . base . ")"
echohl None
endif endif
endfunction endfunction
@ -516,8 +497,9 @@ function! s:system_incompatible() " {{{1
" "
for cmd in required for cmd in required
if !executable(cmd) if !executable(cmd)
echom "Warning: Could not initialize vimtex#latexmk" call vimtex#echo#warning('vimtex warning: ')
echom " Missing executable: " . cmd call vimtex#echo#warning(' vimtex#latexmk was not initialized', 'None')
call vimtex#echo#warning(' ' . cmd . ' is not executable', 'None')
return 1 return 1
endif endif
endfor endfor

View File

@ -27,8 +27,7 @@ function! vimtex#view#init(initialized) " {{{1
let viewer = 's:' . g:vimtex_view_method let viewer = 's:' . g:vimtex_view_method
if !exists(viewer) if !exists(viewer)
echoerr "Viewer does not exist!" echoerr 'vimtex viewer ' . g:vimtex_view_method . ' does not exist!'
echoerr "Viewer: " . g:vimtex_view_method
return return
endif endif
@ -68,7 +67,7 @@ endfor
" {{{1 General " {{{1 General
function! s:general.init() dict " {{{2 function! s:general.init() dict " {{{2
if !executable(g:vimtex_view_general_viewer) if !executable(g:vimtex_view_general_viewer)
echoerr "General viewer is not available!" echoerr "vimtex viewer is not executable!"
echoerr "g:vimtex_view_general_viewer = " echoerr "g:vimtex_view_general_viewer = "
\ . g:vimtex_view_general_viewer \ . g:vimtex_view_general_viewer
endif endif
@ -92,11 +91,11 @@ endfunction
" {{{1 MuPDF " {{{1 MuPDF
function! s:mupdf.init() dict " {{{2 function! s:mupdf.init() dict " {{{2
if !executable('mupdf') if !executable('mupdf')
echoerr "MuPDF is not available!" echoerr "vimtex viewer MuPDF is not executable!"
endif endif
if !executable('xdotool') if !executable('xdotool')
echomsg "For full MuPDF support, please install xdotool" call vimtex#echo#warning('vimtex viewer MuPDF requires xdotool!')
endif endif
let self.class = 'MuPDF' let self.class = 'MuPDF'
@ -170,7 +169,8 @@ function! s:mupdf.reverse_search() dict " {{{2
if s:output_not_readable(outfile) | return | endif if s:output_not_readable(outfile) | return | endif
if !self.xwin_exists() if !self.xwin_exists()
echomsg "Can't search backwards: Is the PDF file open?" call vimtex#echo#warning(
\ 'vimtex reverse search failed (is MuPDF open?)')
return return
endif endif
@ -228,7 +228,7 @@ endfunction
" {{{1 Okular " {{{1 Okular
function! s:okular.init() dict " {{{2 function! s:okular.init() dict " {{{2
if !executable('okular') if !executable('okular')
echoerr "okular is not available!" echoerr "vimtex viewer Okular is not executable!"
endif endif
endfunction endfunction
@ -250,7 +250,7 @@ endfunction
" {{{1 qpdfview " {{{1 qpdfview
function! s:qpdfview.init() dict " {{{2 function! s:qpdfview.init() dict " {{{2
if !executable('qpdfview') if !executable('qpdfview')
echoerr "qpdfview is not available!" echoerr "vimtex viewer qpdfview is not executable!"
endif endif
endfunction endfunction
@ -274,7 +274,7 @@ endfunction
" {{{1 SumatraPDF " {{{1 SumatraPDF
function! s:sumatrapdf.init() dict " {{{2 function! s:sumatrapdf.init() dict " {{{2
if !executable('SumatraPDF') if !executable('SumatraPDF')
echoerr "SumatraPDF is not available!" echoerr "vimtex viewer SumatraPDF is not executable!"
endif endif
endfunction endfunction
@ -297,11 +297,11 @@ endfunction
" {{{1 Zathura " {{{1 Zathura
function! s:zathura.init() dict " {{{2 function! s:zathura.init() dict " {{{2
if !executable('zathura') if !executable('zathura')
echoerr "Zathura is not available!" echoerr "vimtex viewer Zathura is not executable!"
endif endif
if !executable('xdotool') if !executable('xdotool')
echomsg "For full Zathura support, please install xdotool" call vimtex#echo#warning('vimtex viewer Zathura requires xdotool!')
endif endif
let self.class = 'Zathura' let self.class = 'Zathura'
@ -379,7 +379,7 @@ endfunction
function! s:output_not_readable(output) " {{{2 function! s:output_not_readable(output) " {{{2
if !filereadable(a:output) if !filereadable(a:output)
echomsg "Can't view: Output file is not readable!" call vimtex#echo#warning('vimtex viewer can not read PDF file!')
return 1 return 1
else else
return 0 return 0
@ -395,7 +395,8 @@ function! s:xwin_get_id() dict " {{{2
let cmd = 'xdotool search --class ' . self.class let cmd = 'xdotool search --class ' . self.class
let xwin_ids = systemlist(cmd) let xwin_ids = systemlist(cmd)
if len(xwin_ids) == 0 if len(xwin_ids) == 0
echomsg "Couldn't find " . self.class . " window ID!" call vimtex#echo#warning(
\ 'vimtex viewer can not find ' . self.class . ' window ID!')
let self.xwin_id = 0 let self.xwin_id = 0
else else
let self.xwin_id = xwin_ids[-1] let self.xwin_id = xwin_ids[-1]