diff --git a/plugin/papis.vim b/plugin/papis.vim index 2b12f39..957bf27 100644 --- a/plugin/papis.vim +++ b/plugin/papis.vim @@ -10,9 +10,9 @@ function! s:get_reference(line) endfunction function! s:inside_cite_body() - execute "silent! normal mq?\\\\cite\\|}\r" + execute "silent! normal! mq?\\\\cite\\|}\r" let l:inbody = getline('.')[col('.')-1: col('.') + 3] ==# '\cite' - execute "normal `q" + execute "normal! `q" return l:inbody endfunction @@ -39,15 +39,60 @@ function! s:handler(a) else " If you are already in a \cite{} body if s:inside_cite_body() - execute "normal \/\}\rgea, " . join(l:candidates, ", ") ."\e" + execute "normal! \/\}\rgea, " . join(l:candidates, ", ") ."\e" " start a fresh \cite{} body else - execute "normal a\\cite{" . join(l:candidates, ", ") . "}\e" + execute "normal! a\\cite{" . join(l:candidates, ", ") . "}\e" endif endif endfunction let g:PapisFormat = '"{doc[author]}: {doc[title]}' +let g:PapisBackend = 'whoosh' command! -bang -nargs=* Papis - \ call fzf#run(fzf#wrap({'source': 'papis list --format ' . g:PapisFormat . ' @{doc[ref]}"', 'sink*': function('handler'), 'options': '--multi --expect=ctrl-y --print-query'})) + \ call fzf#run(fzf#wrap({'source': 'papis list "*" --format ' . g:PapisFormat . ' @{doc[ref]}"', 'sink*': function('handler'), 'options': '--multi --expect=ctrl-y --print-query'})) + +function! s:get_citeref(cite, full_list) + for l:ref in a:full_list + if a:cite ==# substitute(l:ref, "/", "", "g") + return l:ref + endif + endfor +endfunction + +function! s:get_all_citerefs() + return systemlist('papis list "ref:*" --format "{doc[ref]}"') +endfunction + +function! s:get_cite_under_cursor() + if s:inside_cite_body() + if getline('.')[col('.') -1] ==# ',' + return + endif + + execute "silent! normal! mq/[}{]\r" + if getline('.')[col('.') -1] ==# '{' + execute "silent! normal! `q" + return + endif + + execute "silent! normal! `q" + execute "silent! normal! ?[{,]\rwv/[,}]\rge\"qy`q" + return @q + endif +endfunction + +function! s:PapisView() + let l:cite = s:get_cite_under_cursor() + if l:cite ==# "" + return + endif + + let l:full_list = s:get_all_citerefs() + let l:ref = s:get_citeref(l:cite, l:full_list) + call system('papis open "ref:' . l:ref . '"') +endfunction + +command! -bang PapisView + \ call s:PapisView()