diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index e548dd2..fb62cd6 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -12,6 +12,7 @@ function! vimtex#init() " {{{1 call s:init_environment() call vimtex#toc#init(s:initialized) + call vimtex#echo#init(s:initialized) call vimtex#fold#init(s:initialized) call vimtex#view#init(s:initialized) call vimtex#motion#init(s:initialized) @@ -35,7 +36,7 @@ function! vimtex#info() " {{{1 endif " Print buffer data - echo "b:vimtex" + call vimtex#echo#echo("b:vimtex\n") call s:print_dict(b:vimtex) " Print global data @@ -48,8 +49,11 @@ function! vimtex#info() " {{{1 endfor " Print data blob title line - echo "\n" - echo "g:vimtex#data[" . n . "] : " . remove(d, 'name') + call vimtex#echo#formatted([ + \ "\n\ng:vimtex#data[", + \ ['VimtexSuccess', n], + \ '] : ', + \ ['VimtexSuccess', remove(d, 'name') . "\n"]]) call s:print_dict(d) let n += 1 endfor @@ -61,7 +65,7 @@ function! vimtex#help() " {{{1 xmap omap else - echo "Mappings not enabled" + call vimtex#echo#warning('vimtex mappings are not enabled') endif endfunction @@ -82,8 +86,8 @@ function! vimtex#reinit() " {{{1 " let n = bufnr('%') bufdo if getbufvar('%', '&filetype') == 'tex' | - \ unlet b:vimtex | - \ call vimtex#init() | + \ unlet b:vimtex | + \ call vimtex#init() | \ endif silent execute 'buffer ' . n endfunction @@ -309,17 +313,18 @@ function! s:print_dict(dict, ...) " {{{1 for entry in sort(sort(items(a:dict), \ "s:print_dict_sort_2"), \ "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([]) - echo title + call vimtex#echo#echo(title) for val in entry[1] - echo repeat(' ', 4 + 2*level) . string(val) + call vimtex#echo#echo(repeat(' ', 4 + 2*level) . string(val), 'None') endfor elseif type(entry[1]) == type({}) - echo title + call vimtex#echo#echo(title . "\n") call s:print_dict(entry[1], level + 1) else - echo printf('%-s%-s', title, string(entry[1])) + call vimtex#echo#formatted([title . ' : ', + \ ['None', string(entry[1]) . "\n"]]) endif endfor endfunction diff --git a/autoload/vimtex/complete.vim b/autoload/vimtex/complete.vim index 1e9e7b5..634268f 100644 --- a/autoload/vimtex/complete.vim +++ b/autoload/vimtex/complete.vim @@ -19,16 +19,21 @@ function! vimtex#complete#init(initialized) " {{{1 " Check if bibtex is available if !executable('bibtex') - echom "Warning: bibtex completion not available" - echom " Missing executable: bibtex" + call vimtex#echo#warning('vimtex warning') + call vimtex#echo#warning(' bibtex completion is not available!', + \ 'None') + call vimtex#echo#warning(' bibtex is not executable', 'None') let s:bibtex = 0 endif " Check if kpsewhich is required and available - if g:vimtex_complete_recursive_bib && !executable('kpsewhich') - echom "Warning: bibtex completion not available" - echom " Missing executable: kpsewhich" - echom " You could try to turn off recursive bib functionality" + if s:bibtex && g:vimtex_complete_recursive_bib && !executable('kpsewhichc') + call vimtex#echo#warning('vimtex warning') + call vimtex#echo#warning(' bibtex completion is not available!', + \ 'None') + call vimtex#echo#warning(' recursive bib search requires kpsewhich', + \ 'None') + call vimtex#echo#warning(' kpsewhich is not executable', 'None') let s:bibtex = 0 endif diff --git a/autoload/vimtex/echo.vim b/autoload/vimtex/echo.vim new file mode 100644 index 0000000..f01041a --- /dev/null +++ b/autoload/vimtex/echo.vim @@ -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 diff --git a/autoload/vimtex/latexmk.vim b/autoload/vimtex/latexmk.vim index 2a27683..d53a050 100644 --- a/autoload/vimtex/latexmk.vim +++ b/autoload/vimtex/latexmk.vim @@ -82,16 +82,8 @@ function! vimtex#latexmk#callback(status) " {{{1 call g:vimtex#data[b:vimtex.id].viewer.latexmk_callback() endif - echohl ModeMsg - echon "latexmk compile: " - if a:status - echohl Statement - echon "success" - else - echohl WarningMsg - echon "fail" - endif - echohl None + call vimtex#echo#status(['latexmk compile: ', + \ a:status ? ['VimtexSuccess', 'success'] : ['VimtexWarning', 'fail']]) return "" endfunction @@ -100,11 +92,8 @@ endfunction function! vimtex#latexmk#clean(full) " {{{1 let data = g:vimtex#data[b:vimtex.id] if data.pid - echohl ModeMsg - echon "latexmk clean: " - echohl WarningMsg - echon "not while latexmk is running!" - echohl None + call vimtex#echo#status(['latexmk clean: ', + \ ['VimtexWarning', 'not while latexmk is running!']]) return endif @@ -126,15 +115,8 @@ function! vimtex#latexmk#clean(full) " {{{1 call vimtex#util#execute(exe) let g:vimtex#data[b:vimtex.id].cmd_latexmk_clean = cmd - echohl ModeMsg - echon "latexmk clean: " - echohl Statement - if a:full - echon "finished (full)" - else - echon "finished" - endif - echohl None + call vimtex#echo#status(['latexmk clean: ', + \ ['VimtexSuccess', 'finished' . (a:full ? ' (full)' : '')]]) endfunction " }}}1 @@ -164,7 +146,8 @@ endfunction function! vimtex#latexmk#compile() " {{{1 let data = g:vimtex#data[b:vimtex.id] if data.pid - echomsg "latexmk is already running for `" . data.base . "'" + call vimtex#echo#status(['latexmk compile: ', + \ ['VimtexWarning', 'already running for `' . data.base . "'"]]) return endif @@ -178,10 +161,11 @@ function! vimtex#latexmk#compile() " {{{1 if g:vimtex_latexmk_continuous call s:latexmk_set_pid(data) - - echomsg 'latexmk started in continuous mode ...' + call vimtex#echo#status(['latexmk compile: ', + \ ['VimtexSuccess', 'started continuous mode']]) else - echomsg 'latexmk compiling ...' + call vimtex#echo#status(['latexmk compile: ', + \ ['VimtexSuccess', 'compiling ...']]) endif endfunction @@ -189,7 +173,8 @@ endfunction function! vimtex#latexmk#compile_ss(verbose) " {{{1 let data = g:vimtex#data[b:vimtex.id] if data.pid - echomsg "latexmk is already running for `" . data.base . "'" + call vimtex#echo#status(['latexmk compile: ' + \ ['VimtexWarning', 'already running for `' . data.base . "'"]]) return endif @@ -221,11 +206,8 @@ function! vimtex#latexmk#errors_open(force) " {{{1 let log = g:vimtex#data[b:vimtex.id].log() if empty(log) if a:force - echohl ModeMsg - echon "latexmk errors: " - echohl WarningMsg - echon "No log file found!" - echohl None + call vimtex#echo#status(['latexmk errors: ', + \ ['VimtexWarning', 'No log file found']]) endif return endif @@ -237,11 +219,8 @@ function! vimtex#latexmk#errors_open(force) " {{{1 endif if empty(getqflist()) if a:force - echohl ModeMsg - echon "latexmk errors: " - echohl Statement - echon "No errors!" - echohl None + call vimtex#echo#status(['latexmk errors: ', + \ ['VimtexSuccess', 'No errors!']]) endif return endif @@ -273,7 +252,7 @@ function! vimtex#latexmk#output() " {{{1 if has_key(g:vimtex#data[b:vimtex.id], 'tmp') let tmp = g:vimtex#data[b:vimtex.id].tmp else - echo "vimtex: No output exists" + call vimtex#echo#status(['vimtex: ', ['VimtexWarning', 'No output exists']]) return endif @@ -309,7 +288,10 @@ function! vimtex#latexmk#status(detailed) " {{{1 for data in g:vimtex#data if data.pid 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 endif @@ -318,18 +300,23 @@ function! vimtex#latexmk#status(detailed) " {{{1 let name = "..." . name[-winwidth('.')+23:] endif - echom printf('pid: %6s, file: %-s', data.pid, name) + call vimtex#echo#status([ + \ ['None', printf(' %-6s ', data.pid)], + \ ['None', name . "\n"]]) endif endfor if !running - echo "latexmk is not running" + call vimtex#echo#status(['latexmk status: ', + \ ['VimtexWarning', 'not running']]) endif else if g:vimtex#data[b:vimtex.id].pid - echo "latexmk is running" + call vimtex#echo#status(['latexmk status: ', + \ ['VimtexSuccess', 'running']]) else - echo "latexmk is not running" + call vimtex#echo#status(['latexmk status: ', + \ ['VimtexWarning', 'not running']]) endif endif endfunction @@ -341,17 +328,11 @@ function! vimtex#latexmk#stop() " {{{1 if pid call s:latexmk_kill_pid(pid) let g:vimtex#data[b:vimtex.id].pid = 0 - echohl ModeMsg - echon "latexmk compile: " - echohl Statement - echon "stopped (" . base . ")" - echohl None + call vimtex#echo#status(['latexmk compile: ', + \ ['VimtexSuccess', 'stopped (' . base . ')']]) else - echohl ModeMsg - echon "latexmk compile: " - echohl WarningMsg - echon "no process to stop (" . base . ")" - echohl None + call vimtex#echo#status(['latexmk compile: ', + \ ['VimtexWarning', 'no process to stop (' . base . ')']]) endif endfunction @@ -516,8 +497,9 @@ function! s:system_incompatible() " {{{1 " for cmd in required if !executable(cmd) - echom "Warning: Could not initialize vimtex#latexmk" - echom " Missing executable: " . cmd + call vimtex#echo#warning('vimtex warning: ') + call vimtex#echo#warning(' vimtex#latexmk was not initialized', 'None') + call vimtex#echo#warning(' ' . cmd . ' is not executable', 'None') return 1 endif endfor diff --git a/autoload/vimtex/view.vim b/autoload/vimtex/view.vim index 78e8838..4e650b3 100644 --- a/autoload/vimtex/view.vim +++ b/autoload/vimtex/view.vim @@ -27,8 +27,7 @@ function! vimtex#view#init(initialized) " {{{1 let viewer = 's:' . g:vimtex_view_method if !exists(viewer) - echoerr "Viewer does not exist!" - echoerr "Viewer: " . g:vimtex_view_method + echoerr 'vimtex viewer ' . g:vimtex_view_method . ' does not exist!' return endif @@ -68,7 +67,7 @@ endfor " {{{1 General function! s:general.init() dict " {{{2 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 = " \ . g:vimtex_view_general_viewer endif @@ -92,11 +91,11 @@ endfunction " {{{1 MuPDF function! s:mupdf.init() dict " {{{2 if !executable('mupdf') - echoerr "MuPDF is not available!" + echoerr "vimtex viewer MuPDF is not executable!" endif if !executable('xdotool') - echomsg "For full MuPDF support, please install xdotool" + call vimtex#echo#warning('vimtex viewer MuPDF requires xdotool!') endif let self.class = 'MuPDF' @@ -170,7 +169,8 @@ function! s:mupdf.reverse_search() dict " {{{2 if s:output_not_readable(outfile) | return | endif 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 endif @@ -228,7 +228,7 @@ endfunction " {{{1 Okular function! s:okular.init() dict " {{{2 if !executable('okular') - echoerr "okular is not available!" + echoerr "vimtex viewer Okular is not executable!" endif endfunction @@ -250,7 +250,7 @@ endfunction " {{{1 qpdfview function! s:qpdfview.init() dict " {{{2 if !executable('qpdfview') - echoerr "qpdfview is not available!" + echoerr "vimtex viewer qpdfview is not executable!" endif endfunction @@ -274,7 +274,7 @@ endfunction " {{{1 SumatraPDF function! s:sumatrapdf.init() dict " {{{2 if !executable('SumatraPDF') - echoerr "SumatraPDF is not available!" + echoerr "vimtex viewer SumatraPDF is not executable!" endif endfunction @@ -297,11 +297,11 @@ endfunction " {{{1 Zathura function! s:zathura.init() dict " {{{2 if !executable('zathura') - echoerr "Zathura is not available!" + echoerr "vimtex viewer Zathura is not executable!" endif if !executable('xdotool') - echomsg "For full Zathura support, please install xdotool" + call vimtex#echo#warning('vimtex viewer Zathura requires xdotool!') endif let self.class = 'Zathura' @@ -379,7 +379,7 @@ endfunction function! s:output_not_readable(output) " {{{2 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 else return 0 @@ -395,7 +395,8 @@ function! s:xwin_get_id() dict " {{{2 let cmd = 'xdotool search --class ' . self.class let xwin_ids = systemlist(cmd) 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 else let self.xwin_id = xwin_ids[-1]