" vim: set fdm=marker et ts=4 sw=4 sts=4: function! pandoc#keyboard#references#Init() abort "{{{1 " Defaults: {{{2 " We use a mark for some functions, the user can change it " so it doesn't interfere with his settings if !exists('g:pandoc#keyboard#references#mark') let g:pandoc#keyboard#references#mark = 'r' endif "}}}2 " Add new reference link (or footnote link) after current paragraph. noremap (pandoc-keyboard-ref-insert) :call pandoc#keyboard#references#Insert_Ref()a " Go to link or footnote definition for label under the cursor. noremap (pandoc-keyboard-ref-goto) :call pandoc#keyboard#references#GOTO_Ref() " Go back to last point in the text we jumped to a reference from. noremap (pandoc-keyboard-ref-backfrom) :call pandoc#keyboard#references#BACKFROM_Ref() if g:pandoc#keyboard#use_default_mappings == 1 && index(g:pandoc#keyboard#blacklist_submodule_mappings, 'references') == -1 nmap nr (pandoc-keyboard-ref-insert) nmap rg (pandoc-keyboard-ref-goto) nmap rb (pandoc-keyboard-ref-backfrom) endif endfunction " Functions: {{{1 " handling: {{{2 function! pandoc#keyboard#references#Insert_Ref() abort execute 'normal m'.g:pandoc#keyboard#references#mark let reg_save = getreg('*') normal! "*ya[ call search('\n\(\n\|\_$\)\@=') execute 'normal! o\\0"*P$a: ' call setreg('*', reg_save) endfunction " }}}2 " navigation: {{{2 function! pandoc#keyboard#references#GOTO_Ref() abort let reg_save = getreg('*') execute 'normal! m'.g:pandoc#keyboard#references#mark execute 'silent normal! ?[\vf]"*y' call setreg('*', substitute(getreg('*'), '\[', '\\\[', 'g')) call setreg('*', substitute(getreg('*'), '\]', '\\\]', 'g')) execute 'silent normal! /'.getreg('*').':\' call setreg('*', reg_save) endfunction function! pandoc#keyboard#references#BACKFROM_Ref() abort try execute 'normal! `'.g:pandoc#keyboard#references#mark " clean up execute 'delmark '.g:pandoc#keyboard#references#mark catch /E20/ "no mark set, we must search backwards. let reg_save = getreg('*') "move right, because otherwise it would fail if the cursor is at the "beggining of the line execute 'silent normal! 0l?[\vf]"*y' call setreg('*', substitute(getreg('*'), '\]', '\\\]', 'g')) execute 'silent normal! ?'.getreg('*').'\' call setreg('*', reg_save) endtry endfunction function! pandoc#keyboard#references#NextRefDefinition() abort endfunction function! pandoc#keyboard#references#PrevRefDefinition() abort endfunction " }}}2 " }}}1