Added PapisView
PapisView: when cursor on a citation, opens the pdf through papis normal! everywhere also, to make that the command does not use userdefined mappings.
This commit is contained in:
parent
3ef9699528
commit
108946be28
@ -10,9 +10,9 @@ function! s:get_reference(line)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:inside_cite_body()
|
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'
|
let l:inbody = getline('.')[col('.')-1: col('.') + 3] ==# '\cite'
|
||||||
execute "normal `q"
|
execute "normal! `q"
|
||||||
return l:inbody
|
return l:inbody
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -39,15 +39,60 @@ function! s:handler(a)
|
|||||||
else
|
else
|
||||||
" If you are already in a \cite{} body
|
" If you are already in a \cite{} body
|
||||||
if s:inside_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
|
" start a fresh \cite{} body
|
||||||
else
|
else
|
||||||
execute "normal a\\cite{" . join(l:candidates, ", ") . "}\e"
|
execute "normal! a\\cite{" . join(l:candidates, ", ") . "}\e"
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let g:PapisFormat = '"{doc[author]}: {doc[title]}'
|
let g:PapisFormat = '"{doc[author]}: {doc[title]}'
|
||||||
|
let g:PapisBackend = 'whoosh'
|
||||||
|
|
||||||
command! -bang -nargs=* Papis
|
command! -bang -nargs=* Papis
|
||||||
\ call fzf#run(fzf#wrap({'source': 'papis list <args> --format ' . g:PapisFormat . ' @{doc[ref]}"', 'sink*': function('<sid>handler'), 'options': '--multi --expect=ctrl-y --print-query'}))
|
\ call fzf#run(fzf#wrap({'source': 'papis list "*" <args> --format ' . g:PapisFormat . ' @{doc[ref]}"', 'sink*': function('<sid>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()
|
||||||
|
Loading…
Reference in New Issue
Block a user