Skip to content

Commit

Permalink
new remap to extract abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coates authored Jul 27, 2024
1 parent b2187f9 commit 71e4958
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions doc/zotcite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ In Vim's Normal mode, put the cursor over a citation key and press:

- <Leader>za to see all fields of a reference as stored by Zotcite.

- <leader>zb to extract the abstract into the currently open buffer if its
available.

- <Leader>zy to see how the reference will be converted into YAML.

- <Leader>zv to view the (pdf or html) document generated from the current
Expand Down Expand Up @@ -215,6 +218,11 @@ the example:
>
nmap ,Y <Plug>ZCitationYamlRef
<
To change the shortcut to extract the abstract into the current buffer from the
abstract field in complete info:
>
nmap ,Y <Plug>ZExtractAbstract
<
To change the shortcut to view the (pdf or html) document generated from the
current (Markdown, Rmd, or Quarto) document, follow the example:
>
Expand Down
18 changes: 13 additions & 5 deletions lua/zotcite/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ local M = {}

local b = {}

M.show = function ()
M.show = function()
local info = {}
for k, v in pairs(config) do
table.insert(info, { k, "Identifier" } )
table.insert(info, { " = ", "Operator" } )
table.insert(info, { vim.inspect(v) .. "\n" } )
table.insert(info, { k, "Identifier" })
table.insert(info, { " = ", "Operator" })
table.insert(info, { vim.inspect(v) .. "\n" })
end
vim.schedule(function() vim.api.nvim_echo(info, false, {}) end)
end
Expand All @@ -41,7 +41,9 @@ M.update_config = function(opts)
if config.exclude_fields then vim.env.Zotcite_exclude = config.exclude_fields end
if config.year_page_sep then vim.env.ZYearPageSep = config.year_page_sep end
if vim.env.Zotero_encoding then
zwarn("The environment variable `Zotero_encoding` now is a config option: `zotero_encoding`.")
zwarn(
"The environment variable `Zotero_encoding` now is a config option: `zotero_encoding`."
)
end
if config.zotero_encoding then vim.env.ZoteroEncoding = config.zotero_encoding end
end
Expand Down Expand Up @@ -209,6 +211,12 @@ M.init = function()
"<Cmd>lua require('zotcite.get').yaml_ref()<CR>",
"Zotcite: show reference as YAML"
)
create_map(
"<Plug>ZExtractAbstract",
"<leader>zb",
"<Cmd>lua require('zotcite.get').abstract()<CR>",
"Zotcite: Paste abstract note in current buffer"
)
vim.o.conceallevel = config.conceallevel
require("zotcite.get").collection_name()
vim.cmd("autocmd BufWritePre <buffer> lua require('zotcite.utils').check_bib()")
Expand Down
16 changes: 16 additions & 0 deletions lua/zotcite/get.lua
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ M.reference_data = function(btype)
end
end

M.abstract = function()
local wrd = M.citation_key()
if wrd ~= "" then
local repl = vim.fn.py3eval('ZotCite.GetRefData("' .. wrd .. '")')
if not repl then
zwarn("Citation key not found")
return
end
if repl.abstractNote then
vim.api.nvim_put({ repl.abstractNote }, "l", true, true)
else
zwarn("No abstract found associated with article")
end
end
end

M.refs = function(key)
local mtchs = getmach(key)
local info = {}
Expand Down

0 comments on commit 71e4958

Please sign in to comment.