diff --git a/README.md b/README.md index d287dbb..6300b29 100644 --- a/README.md +++ b/README.md @@ -180,8 +180,10 @@ Minimal setup: ```lua require("papis").setup({ - -- Enable the default keymaps + -- Enable the default keymaps (defaults to `false`) enable_keymaps = true, + -- You might want to change the filetypes activating papis.nvim + -- init_filetypes = { "markdown", "norg", "yaml" }, }) ``` @@ -261,7 +263,7 @@ db_path = vim.fn.stdpath("data") .. "/papis_db/papis-nvim.sqlite3", yq_bin = "yq", -- Function to execute when adding a new note. `ref` is the citation key of the --- relevant entry and `notes_name` is defined in `papis_python` above. +-- relevant entry and `notes_name` is the name of the notes file. create_new_note_fn = function(papis_id, notes_name) local testing_session = require("papis.config")["enable_modules"]["testing"] local testing_conf_path = "" @@ -280,6 +282,9 @@ end, -- Filetypes that start papis.nvim. init_filetypes = { "markdown", "norg", "yaml" }, +-- Papis options to import into papis.nvim. +papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" }, + -- Configuration of the search module. ["search"] = { diff --git a/doc/papis.txt b/doc/papis.txt index 3f64e37..aaf0da5 100644 --- a/doc/papis.txt +++ b/doc/papis.txt @@ -1,4 +1,4 @@ -*papis.txt* For NVIM v0.8.0 Last change: 2024 June 14 +*papis.txt* For NVIM v0.8.0 Last change: 2024 June 15 ============================================================================== Table of Contents *papis-table-of-contents* @@ -238,8 +238,10 @@ Minimal setup: >lua require("papis").setup({ - -- Enable the default keymaps + -- Enable the default keymaps (defaults to `false`) enable_keymaps = true, + -- You might want to change the filetypes activating papis.nvim + -- init_filetypes = { "markdown", "norg", "yaml" }, }) < @@ -318,7 +320,7 @@ All configuration options (with defaults) ~ yq_bin = "yq", -- Function to execute when adding a new note. `ref` is the citation key of the - -- relevant entry and `notes_name` is defined in `papis_python` above. + -- relevant entry and `notes_name` is the name of the notes file. create_new_note_fn = function(papis_id, notes_name) local testing_session = require("papis.config")["enable_modules"]["testing"] local testing_conf_path = "" @@ -337,6 +339,9 @@ All configuration options (with defaults) ~ -- Filetypes that start papis.nvim. init_filetypes = { "markdown", "norg", "yaml" }, + -- Papis options to import into papis.nvim. + papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" }, + -- Configuration of the search module. ["search"] = { diff --git a/lua/papis/config.lua b/lua/papis/config.lua index 553f8d2..26c432d 100644 --- a/lua/papis/config.lua +++ b/lua/papis/config.lua @@ -66,6 +66,7 @@ local default_config = { ) end, init_filetypes = { "markdown", "norg", "yaml" }, + papis_conf_keys = { "info-name", "notes-name", "dir", "opentool" }, ["formatter"] = { format_notes_fn = function(entry) local title_format = { @@ -145,13 +146,13 @@ local default_config = { } ---Queries Papis to get various options. ----@param testing_session boolean #If true, will use testing papis conf +---@param papis_conf_keys table #A table with keys to query from Papis +---@param is_testing_session boolean #If true, will use testing papis conf ---@return table #A table { info_name = val, dir = val } -local function get_papis_py_conf(testing_session) - local papis_conf_keys = { "info-name", "notes-name", "dir" } +local function get_papis_py_conf(papis_conf_keys, is_testing_session) local papis_py_conf_new = {} local testing_conf_path = "" - if testing_session then + if is_testing_session then testing_conf_path = "-c ./tests/papis_config " end for _, key in ipairs(papis_conf_keys) do @@ -182,7 +183,8 @@ function M:update_papis_py_conf() end local is_testing_session = self["enable_modules"]["testing"] - local papis_py_conf_new = get_papis_py_conf(is_testing_session) + local papis_conf_keys = self["papis_conf_keys"] + local papis_py_conf_new = get_papis_py_conf(papis_conf_keys, is_testing_session) local papis_py_conf_old = db.config:get()[1] papis_py_conf_old["id"] = nil @@ -207,8 +209,9 @@ function M:setup_papis_py_conf() -- 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) + local is_testing_session = self["enable_modules"]["testing"] + local papis_conf_keys = self["papis_conf_keys"] + local papis_py_conf_new = get_papis_py_conf(papis_conf_keys, is_testing_session) db.config:drop() db.config:update({ id = 1 }, papis_py_conf_new) end diff --git a/lua/papis/sqlite-wrapper.lua b/lua/papis/sqlite-wrapper.lua index 65eb524..94682b9 100644 --- a/lua/papis/sqlite-wrapper.lua +++ b/lua/papis/sqlite-wrapper.lua @@ -97,12 +97,19 @@ M.state = M:tbl("state", { tag_format = { "text", default = nil }, }) -M.config = M:tbl("config", { - id = true, - info_name = { "text", default = nil }, - notes_name = { "text", default = nil }, - dir = { "text", default = nil }, -}) + +---Creates the schema of the config table +---@return table #The config table schema +local function get_config_tbl_schema() + local tbl_schema = { id = true, } + for _, key in ipairs(config["papis_conf_keys"]) do + local sanitized_key = string.gsub(key, "-", "_") + tbl_schema[sanitized_key] = { "text", default = nil } + end + return tbl_schema +end + +M.config = M:tbl("config", get_config_tbl_schema()) ---Adds common methods to tbls ---@param tbls table #Set of tables that should have methods added diff --git a/lua/papis/utils.lua b/lua/papis/utils.lua index c636f0b..fa851e2 100644 --- a/lua/papis/utils.lua +++ b/lua/papis/utils.lua @@ -47,7 +47,7 @@ end ---Splits string by `inputstr` and trims whitespace ---@param inputstr string #String to be split ----@param sep? string #String giving each character by witch to split +---@param sep? string #String giving each character by which to split ---@return table #List of split elements function M.do_split_str(inputstr, sep) if sep == nil then @@ -63,20 +63,15 @@ end -- Open file outside neovim ---@param path string #Path to the file -function M.do_open_file_external(path) - local command - local args - if is_windows then - command = "rundll32.exe" - args = { "url.dll,FileProtocolHandler", path } - else - if is_linux then - command = "xdg-open" - elseif is_macos then - command = "open" - end - args = { path } +function M:do_open_file_external(path) + local opentool = require("papis.sqlite-wrapper").config:get_value({ id = 1 }, "opentool") + local opentool_table = self.do_split_str(opentool, " ") + local command = opentool_table[1] + local args = {} + for i = 2, #opentool_table do + table.insert(args, opentool_table[i]) end + table.insert(args, path) local handle handle = vim.loop.spawn(command, { @@ -119,7 +114,7 @@ function M:do_open_attached_files(papis_id) elseif #filenames == 1 then log.info("Opening file '" .. filenames[1] .. "' ") local path = lookup_tbl[filenames[1]] - self.do_open_file_external(path) + self:do_open_file_external(path) else vim.ui.select(filenames, { prompt = "Select attachment to open:", @@ -127,7 +122,7 @@ function M:do_open_attached_files(papis_id) if choice then log.info("Opening file '" .. choice .. "' ") local path = lookup_tbl[choice] - self.do_open_file_external(path) + self:do_open_file_external(path) end end) end