diff --git a/lua/papis/completion/source.lua b/lua/papis/completion/source.lua index 760b45b..7317c47 100644 --- a/lua/papis/completion/source.lua +++ b/lua/papis/completion/source.lua @@ -63,7 +63,7 @@ function M:is_available() local current_filepath = Path(api.nvim_buf_get_name(0)) local filename = current_filepath:basename() - local info_name = db.config:get_value({ id = 1 }, "info_name") + local info_name = db.config:get_conf_value("info_name") if filename == info_name then log.trace("we are in a papis info file") if not tag_delimiter then diff --git a/lua/papis/fs-watcher.lua b/lua/papis/fs-watcher.lua index db74490..5b9c08f 100644 --- a/lua/papis/fs-watcher.lua +++ b/lua/papis/fs-watcher.lua @@ -54,7 +54,7 @@ end ---Gets all directories in the library_dir ---@return table #A list of all directories in library_dir local function get_library_dirs() - local library_dir = Path(db.config:get_value({ id = 1 }, "dir")) + local library_dir = Path(db.config:get_conf_value("dir")) local library_dirs = {} for path in library_dir:fs_iterdir() do library_dirs[#library_dirs + 1] = path @@ -72,7 +72,7 @@ local function init_fs_watcher(dir_to_watch, is_library_root) ---@param filename string #The name of the file that triggered the event ---@param unwatch_cb function #The callback that stops a watcher local function do_handle_event(filename, unwatch_cb) - local info_name = db.config:get_value({ id = 1 }, "info_name") + local info_name = db.config:get_conf_value("info_name") local mtime local entry_dir local info_path @@ -160,7 +160,7 @@ end ---Starts file system watchers for root dir and all entry dirs local function start_fs_watchers() log.debug("Set db state to indicate fswatcher is active") - local library_dir = Path(db.config:get_value({ id = 1 }, "dir")) + local library_dir = Path(db.config:get_conf_value("dir")) db.state:set_fw_running(uv.os_getpid()) log.debug("Setting up fswatcher for library root directory") diff --git a/lua/papis/papis-storage.lua b/lua/papis/papis-storage.lua index b95b399..47f876f 100644 --- a/lua/papis/papis-storage.lua +++ b/lua/papis/papis-storage.lua @@ -142,8 +142,8 @@ end ---@param paths? table #A list with paths of papis entries ---@return table #A list of { path = path, mtime = mtime } values function M.get_metadata(paths) - local library_dir = Path(db.config:get_value({ id = 1 }, "dir")) - local info_name = db.config:get_value({ id = 1 }, "info_name") + local library_dir = Path(db.config:get_conf_value("dir")) + local info_name = db.config:get_conf_value("info_name") if not paths then paths = {} for path in library_dir:fs_iterdir() do diff --git a/lua/papis/sqlite-wrapper.lua b/lua/papis/sqlite-wrapper.lua index 643e384..17c9ae1 100644 --- a/lua/papis/sqlite-wrapper.lua +++ b/lua/papis/sqlite-wrapper.lua @@ -115,6 +115,11 @@ function tbl_methods.config:update() self:__update({ where = { id = 1 }, set = papis_py_conf_new }) end +---Gets config from Papis and updates the config table with it +function tbl_methods.config:get_conf_value(key) + return self:get_value({ id = 1 }, key) +end + ---Gets the pid of the neovim instance that is running file watchers ---@return number? #Pid of the relevant process if they are running, nil if not function tbl_methods.state:get_fw_running() diff --git a/lua/papis/utils.lua b/lua/papis/utils.lua index cc1487c..3f1a930 100644 --- a/lua/papis/utils.lua +++ b/lua/papis/utils.lua @@ -64,7 +64,7 @@ end -- Open file outside neovim ---@param path string #Path to the file function M:do_open_file_external(path) - local opentool = require("papis.sqlite-wrapper").config:get_value({ id = 1 }, "opentool") + local opentool = require("papis.sqlite-wrapper").config:get_conf_value("opentool") local opentool_table = self.do_split_str(opentool, " ") local command = table.remove(opentool_table, 1) local args = opentool_table @@ -175,7 +175,7 @@ function M:do_open_text_file(papis_id, type) popup:unmount() local config = require("papis.config") local create_new_note_fn = config.create_new_note_fn - local notes_name = db.config:get_value({ id = 1 }, "notes_name") + local notes_name = db.config:get_conf_value("notes_name") local enable_modules = config.enable_modules create_new_note_fn(papis_id, notes_name) if enable_modules["formatter"] then