diff --git a/doc/papis.txt b/doc/papis.txt index 8a6a22c..e064674 100644 --- a/doc/papis.txt +++ b/doc/papis.txt @@ -1,4 +1,4 @@ -*papis.txt* For NVIM v0.8.0 Last change: 2024 June 09 +*papis.txt* For NVIM v0.8.0 Last change: 2024 June 12 ============================================================================== Table of Contents *papis-table-of-contents* diff --git a/lua/papis/commands.lua b/lua/papis/commands.lua index 9421b32..e10a99a 100644 --- a/lua/papis/commands.lua +++ b/lua/papis/commands.lua @@ -20,9 +20,7 @@ local commands = { reinit_papis_py_config = { name = "PapisReInitConfig", command = function() - local testing_session = config["enable_modules"]["testing"] - local papis_py_conf_new = config:get_papis_py_conf(testing_session) - config:compare_papis_py_conf(papis_py_conf_new) + config:update_papis_py_conf() end, opts = { desc = "Papis: import configuration from Papis" }, }, diff --git a/lua/papis/config.lua b/lua/papis/config.lua index 38d5633..68c2263 100644 --- a/lua/papis/config.lua +++ b/lua/papis/config.lua @@ -143,12 +143,10 @@ local default_config = { }, } -local M = vim.deepcopy(default_config) - ----Queries papis to get info-name and dir settings. +---Queries Papis to get various options. ---@param testing_session boolean #If true, will use testing papis conf ---@return table #A table { info_name = val, dir = val } -function M:get_papis_py_conf(testing_session) +local function get_papis_py_conf(testing_session) local papis_conf_keys = { "info-name", "notes-name", "dir" } local papis_py_conf_new = {} local testing_conf_path = "" @@ -172,15 +170,18 @@ function M:get_papis_py_conf(testing_session) return papis_py_conf_new end +local M = vim.deepcopy(default_config) + ---Compares and updates Queries papis to get info-name and dir settings. It is very slow and shouldn't be used ---if possible. ----@param papis_py_conf_new table #A table with new (read from Papis) config entries -function M:compare_papis_py_conf(papis_py_conf_new) +function M:update_papis_py_conf() local db = require("papis.sqlite-wrapper") if not db then return end + local is_testing_session = self["enable_modules"]["testing"] + local papis_py_conf_new = get_papis_py_conf(is_testing_session) local papis_py_conf_old = db.config:get()[1] papis_py_conf_old["id"] = nil @@ -194,6 +195,24 @@ function M:compare_papis_py_conf(papis_py_conf_new) end end +---Sets up Papis configuration values if not already done. +function M:setup_papis_py_conf() + local db = require("papis.sqlite-wrapper") + if not db then + return + end + local log = require("papis.log") + + -- get config from Papis if not already in db + if not db.config:is_setup() then + log.info("Papis.nvim configuration not setup, importing values from Papis now") + local testing_session = self["enable_modules"]["testing"] + local papis_py_conf_new = get_papis_py_conf(testing_session) + db.config:drop() + db.config:update({ id = 1 }, papis_py_conf_new) + end +end + ---Updates the default configuration with user supplied options and gets conf from Papis ---@param opts table #Same format as default_config and contains user config function M:update(opts) @@ -219,25 +238,6 @@ function M:update(opts) for k, v in pairs(newconf) do self[k] = v end - - local db = require("papis.sqlite-wrapper") - if not db then - return - end - local log = require("papis.log") - if not log then - return - end - - -- get config from Papis if not already in db - if not db.config:is_setup() then - log.new(self["log"] or log.get_default_config(), true) - log.info("Papis.nvim configuration not setup, importing values from Papis now") - local testing_session = self["enable_modules"]["testing"] - local papis_py_conf_new = self:get_papis_py_conf(testing_session) - db.config:drop() - db.config:update({ id = 1 }, papis_py_conf_new) - end end return M diff --git a/lua/papis/init.lua b/lua/papis/init.lua index 0bc8297..275f4f2 100644 --- a/lua/papis/init.lua +++ b/lua/papis/init.lua @@ -23,18 +23,26 @@ end local M = {} ----This function is run when neovim starts. It sets up the `PapisStart` command and autocmd ----to allow lazy-loading of papis.nvim. +---This function is run when neovim starts and sets up papis.nvim. ---@param opts table #User configuration function M.setup(opts) -- update config with user config config:update(opts) + -- create autocmd that starts papis.nvim for configured filetypes + make_start_autocmd() +end + +---This function starts all of papis.nvim. +function M.start() log = require("papis.log") log.new(config["log"] or log.get_default_config(), true) + log.debug("_________________________STARTING PAPIS.NVIM_________________________") - log.debug("_________________________SETTING UP PAPIS.NVIM_________________________") + -- ensure that config options from Papis (python app) are setup + config:setup_papis_py_conf() + -- checking for dependencies local dependencies = { "papis", config["yq_bin"] } for _, dependency in ipairs(dependencies) do if vim.fn.executable(dependency) == 0 then @@ -45,14 +53,6 @@ function M.setup(opts) end end - log.debug("Creating autocmds to lazily load papis.nvim") - make_start_autocmd() -end - ----This function starts all of papis.nvim. -function M.start() - log.debug("Starting papis.nvim") - -- require what's necessary within `M.start()` instead of globally to allow lazy-loading local db = require("papis.sqlite-wrapper") if not db then