Improved citation adding when inside \cite{}
When inside a cite body, the citation is added to this \cite{} body and no new body is initialized
This commit is contained in:
parent
023cdd322a
commit
3ef9699528
@ -4,36 +4,50 @@ function! s:yank_to_register(data)
|
|||||||
silent! let @+ = a:data
|
silent! let @+ = a:data
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:get_reference(line)
|
||||||
|
let l:pat='@\v(.*)$'
|
||||||
|
return substitute(matchlist(a:line, l:pat)[1], "/", "", "g")
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:inside_cite_body()
|
||||||
|
execute "silent! normal mq?\\\\cite\\|}\r"
|
||||||
|
let l:inbody = getline('.')[col('.')-1: col('.') + 3] ==# '\cite'
|
||||||
|
execute "normal `q"
|
||||||
|
return l:inbody
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:handler(a)
|
function! s:handler(a)
|
||||||
let lines = a:a
|
let l:lines = a:a
|
||||||
if lines == [] || lines == ['','','']
|
if l:lines == [] || l:lines == ['','','']
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
" Expect at least 2 elements, `query` and `keypress`, which may be empty
|
" Expect at least 2 elements, `query` and `keypress`, which may be empty
|
||||||
" strings.
|
" strings.
|
||||||
let query = lines[0]
|
let l:keypress = l:lines[1]
|
||||||
let keypress = lines[1]
|
let l:citations = l:lines[2:]
|
||||||
let cmd = "normal a"
|
let l:candidates = []
|
||||||
let pat = '@\v(.{-})$'
|
|
||||||
|
" Making list of the things to cite
|
||||||
|
for l:line in l:citations
|
||||||
|
call add(l:candidates, s:get_reference(l:line))
|
||||||
|
endfor
|
||||||
|
|
||||||
" it is possible to yank the doc id using the ctrl-y keypress
|
" it is possible to yank the doc id using the ctrl-y keypress
|
||||||
if keypress ==? "ctrl-y"
|
if l:keypress ==? "ctrl-y"
|
||||||
let hashes = join(filter(map(lines[2:], 'matchlist(v:val, pat)[1]'), 'len(v:val)'), "\n")
|
execute s:yank_to_register(join(l:candidates, "\n"))
|
||||||
return s:yank_to_register(hashes)
|
|
||||||
" this will insert \cite{id} command for all selected citations
|
" this will insert \cite{id} command for all selected citations
|
||||||
else
|
else
|
||||||
let citations = lines[2:]
|
" If you are already in a \cite{} body
|
||||||
let candidates = []
|
if s:inside_cite_body()
|
||||||
for line in citations
|
execute "normal \/\}\rgea, " . join(l:candidates, ", ") ."\e"
|
||||||
let id = matchlist(line, pat)[1]
|
" start a fresh \cite{} body
|
||||||
call add(candidates, substitute(id, "/", "", "g"))
|
else
|
||||||
endfor
|
execute "normal a\\cite{" . join(l:candidates, ", ") . "}\e"
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
execute "normal a\\cite{" . join(candidates, ", ") . "}\egql"
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
let g:PapisFormat = '"{doc[author]}: {doc[title]}'
|
||||||
|
|
||||||
command! -bang -nargs=* Papis
|
command! -bang -nargs=* Papis
|
||||||
\ call fzf#run(fzf#wrap({'source': 'papis list <args> --format "{doc[author]}: {doc[title]} @{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'}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user