bibliographies.vim 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. " vim: set fdm=marker et ts=4 sw=4 sts=4:
  2. " Init(): sets up defaults, populates b:pandoc_biblio_bibs {{{1
  3. function! pandoc#bibliographies#Init() abort
  4. " set up defaults {{{2
  5. " Places to look for bibliographies {{{3
  6. " b: bibs named after the current file in the working dir
  7. " c: any bib in the working dir
  8. " l: pandoc local dir
  9. " t: texmf
  10. " g: append values in g:pandoc#biblio#bibs
  11. " y: add bibliography specified in yaml header
  12. "
  13. if !exists('g:pandoc#biblio#sources')
  14. let g:pandoc#biblio#sources = 'bcgy'
  15. endif
  16. "}}}
  17. " File extensions to check for {{{3
  18. if !exists('g:pandoc#biblio#bib_extensions')
  19. let g:pandoc#biblio#bib_extensions = ['bib', 'bibtex', 'ris', 'mods', 'enl', 'wos', 'medline', 'copac']
  20. endif
  21. " }}}
  22. " Use bibtool for queries? {{{3
  23. if !exists('g:pandoc#biblio#use_bibtool')
  24. let g:pandoc#biblio#use_bibtool = 0
  25. endif
  26. "}}}
  27. " Pass extra args to bibtool? {{{3
  28. if !exists('g:pandoc#biblio#bibtool_extra_args')
  29. let g:pandoc#biblio#bibtool_extra_args = '-r biblatex'
  30. endif
  31. "}}}
  32. " Files to add to b:pandoc_biblio_bibs if "g" is in g:pandoc#biblio#sources {{{3
  33. if !exists('g:pandoc#biblio#bibs')
  34. let g:pandoc#biblio#bibs = []
  35. endif
  36. " populate b:pandoc_biblio_bibs {{{2
  37. let b:pandoc_biblio_bibs = []
  38. " add bibliographies in yaml header
  39. if match(g:pandoc#biblio#sources, 'y') > -1
  40. if exists('b:pandoc_yaml_data')
  41. if has_key(b:pandoc_yaml_data, 'bibliography') && filereadable(b:pandoc_yaml_data['bibliography'])
  42. call add(b:pandoc_biblio_bibs, b:pandoc_yaml_data['bibliography'])
  43. endif
  44. endif
  45. endif
  46. " set up python
  47. if has('python3')
  48. py3 import vim_pandoc.bib.vim_completer
  49. endif
  50. endfunction
  51. " Find_Bibliographies(): gives a list of bibliographies in g:pandoc#biblio#sources {{{1
  52. function! pandoc#bibliographies#Find_Bibliographies() abort
  53. if has('python3')
  54. return py3eval('vim_pandoc.bib.vim_completer.find_bibfiles()')
  55. endif
  56. return []
  57. endfunction
  58. " GetSuggestions(partkey): returns bibliographic suggestions. {{{1
  59. " called by our omnifunc, if completion is enabled
  60. function! pandoc#bibliographies#GetSuggestions(partkey) abort
  61. if has('python3')
  62. let l:sugs = py3eval('vim_pandoc.bib.vim_completer.VimCompleter().get_suggestions(vim.eval("a:partkey"))')
  63. if len(l:sugs) > 0
  64. return l:sugs
  65. else
  66. return []
  67. endif
  68. endif
  69. endfunction