aspeddro / cmp-pandoc.nvim

Pandoc source for nvim-cmp
MIT License
37 stars 8 forks source link

Support for bibliographies not in the yaml header #3

Open dsanson opened 2 years ago

dsanson commented 2 years ago

In my fork, dsanson/cmp-pandoc.nvim, I took the easy way out: if bib_paths isn't populated from the YAML header, I check for the existence of vim.g["pandoc#biblio#bibs"] and, if it exists, use that instead. I'm happy to submit a pull request if that piggy-backing solution appeals to you.

sebastianbock17 commented 2 years ago

The idea is great @dsanson, but somehow cmp-pandoc stops working with your commit https://github.com/aspeddro/cmp-pandoc.nvim/pull/2/commits/1056b969ec64d544cdc3e51d1628c82d34aa040a. Absolute paths as in (https://github.com/aspeddro/cmp-pandoc.nvim/pull/2/commits/592cf8096300e200bee4f4e5cd3ebd1b1bfef0a7) do work well, though. What could be the issue?

I have set the bib file with the vim-pandoc variable like so:

vim.cmd [[
let g:pandoc#bib#bibs="/home/test/zotero/citations.bib"
]]

And the correct path is returned when running :echo pandoc#bib#bibs.

:  /home/test/zotero/citations.bib

What should I possibly need to change in your commit?:

M.bibliography = function(bufnr, opts)
  local bib_paths = M.get_bibliography_paths(bufnr)
  if vim.g["pandoc#biblio#bibs"] then
    bib_paths = vim.g["pandoc#biblio#bibs"]
  end

  if not bib_paths then
    return
  end

I have also tried to set the path directly, but it still does not work

local bib_paths = {"pandoc#biblio#bibs"}

If I hardcore the path like so:

  local bib_paths = {"/home/test/zotero/citations.bib"}

Then it works though. So what could be the issue, or would this be an alternative solution?

aspeddro commented 2 years ago

The defined was pandoc#bib#bibs.

The correct is pandoc#biblio#bibs

vim.cmd [[
let g:pandoc#biblio#bibs="/home/test/zotero/citations.bib"
]]
aspeddro commented 2 years ago

This feature can make compilation a problem. As cmp-pandoc will read an undefined file in the YAML header, this will make the experience of compiling file a problem, as the program is not able to find the file.

sebastianbock17 commented 2 years ago

Thanks for the hint, somehow I still get some errors,at least I am fine with the solution, which I had searched for so long!

It clearly has benefits, if you want to set compile options with an externally (e.g. a script to be called from within vim, or a plugin).

Thanks a lot so far!! :)

aspeddro commented 2 years ago

Okay. I think the configuration should be defined in the setup function, something like this:

{
  bibliography = {
    global = {
      --- Enable this feature, default is false
      enable = true,
      --- When true, if a file is added to the YAML header, then it must be read along with the global files.
      extend = true,
      --- Paths to bib files
      paths = { "/home/test/zotero/citations.bib", "path/to/bib2.bib" }
    }
  },
}
sebastianbock17 commented 1 year ago

Hello again,

after reinstalling my system and the @dsanson branch for setting absolute bibliography path, I get this error when I try to cite with @

Error executing lua callback: ...ck/packer/start/cmp-pandoc.nvim/lua/cmp_pandoc/parse.lua:165: bad arg
ument #1 to 'ipairs' (table expected, got string)
stack traceback:
        [C]: in function 'ipairs'
        ...ck/packer/start/cmp-pandoc.nvim/lua/cmp_pandoc/parse.lua:165: in function 'bibliography'
        ...ck/packer/start/cmp-pandoc.nvim/lua/cmp_pandoc/parse.lua:232: in function 'init'
        ...k/packer/start/cmp-pandoc.nvim/lua/cmp_pandoc/source.lua:17: in function 'complete'
        ...arvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:311: in function 'complete'
        ...unarvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:286: in function 'complete'
        ...unarvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:168: in function 'callback'
        ...unarvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:218: in function 'autoindent'
        ...unarvim/site/pack/packer/start/nvim-cmp/lua/cmp/core.lua:160: in function 'on_change'
        ...unarvim/site/pack/packer/start/nvim-cmp/lua/cmp/init.lua:310: in function 'callback'
        ...ite/pack/packer/start/nvim-cmp/lua/cmp/utils/autocmd.lua:49: in function 'emit'
        ...ite/pack/packer/start/nvim-cmp/lua/cmp/utils/autocmd.lua:23: in function <...ite/pack/packe
r/start/nvim-cmp/lua/cmp/utils/autocmd.lua:22>

However, the aspedro branch works fine with the usual YAML-header bibliography.

I have also tried to setup absolute bibliography path in cmp-pandoc like @aspeddro's suggestion (with both branches)

{
  bibliography = {
    global = {
      --- Enable this feature, default is false
      enable = true,
      --- When true, if a file is added to the YAML header, then it must be read along with the global files.
      extend = true,
      --- Paths to bib files
      paths = { "/home/test/zotero/citations.bib", "path/to/bib2.bib" }
    }
  },
}

Then nothing happens. Is it implemented yet and if so, how to set it up? Could it be a solution?

Kind regards :)

aspeddro commented 1 year ago

This feature is not implemented.

muziejus commented 1 year ago

I'm interested in revisiting this feature. If I understand @aspeddro correctly, the problem is that the vim-pandoc intervention is done in read_file. Wouldn't the issue of compilation be skipped if the intervention happened in get_bibliography_paths instead?

I'll try with @dsanson's fork and moving the test around.