diff --git a/lua/persisted/config.lua b/lua/persisted/config.lua index 61878bd..425ecdf 100644 --- a/lua/persisted/config.lua +++ b/lua/persisted/config.lua @@ -8,13 +8,6 @@ local defaults = { autosave = true, -- automatically save session files when exiting Neovim should_autosave = nil, -- function to determine if a session should be autosaved (resolve to a boolean) - -- TODO: Remove callbacks after deprecation notice ends - before_save = nil, -- function to run before the session is saved to disk - after_save = nil, -- function to run after the session is saved to disk - before_source = nil, -- function to run before the session is sourced - after_source = nil, -- function to run after the session is sourced - -- - autoload = false, -- automatically load the session for the cwd on Neovim startup on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load @@ -23,10 +16,6 @@ local defaults = { ignored_dirs = nil, -- table of dirs that are ignored for auto-saving and auto-loading telescope = { -- options for the telescope extension - -- TODO: Remove callbacks after deprecation notice ends - before_source = nil, -- function to run before the session is sourced via telescope - after_source = nil, -- function to run after the session is sourced via telescope - -- reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted }, } @@ -36,77 +25,6 @@ M.options = {} function M.setup(opts) M.options = vim.tbl_deep_extend("force", {}, defaults, opts or {}) vim.fn.mkdir(M.options.save_dir, "p") - - if opts then - if opts.before_source then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "before_source", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedLoadPre", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - if opts.after_source then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "after_source", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedLoadPost", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - if opts.before_save then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "before_save", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedSavePre", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - if opts.after_save then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "after_save", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedSavePost", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - - -- Telescope - if opts.telescope and opts.telescope.before_source then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "telescope.before_source", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedTelescopeLoadPre", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - if opts.telescope and opts.telescope.after_source then - require("persisted.deprecate").write( - "----------\n", - "The use of the ", - { "telescope.after_source", "ErrorMsg" }, - " callback.\nPlease replace with the ", - { "PersistedTelescopeLoadPost", "WarningMsg" }, - { " user event. This will be removed from the plugin on " }, - { "2023-03-05", "WarningMsg" } - ) - end - end end return M diff --git a/lua/persisted/deprecate.lua b/lua/persisted/deprecate.lua index 8ec42a8..b8b8d30 100644 --- a/lua/persisted/deprecate.lua +++ b/lua/persisted/deprecate.lua @@ -3,36 +3,36 @@ --https://github.com/EdenEast/nightfox.nvim/blob/main/lua/nightfox/lib/deprecation.lua --] local M = { - _list = { { "[Persisted.nvim]\n", "Question" }, { "The following have been " }, { "deprecated:\n", "WarningMsg" } }, - _has_registered = false, + _list = { { "[Persisted.nvim]\n", "Question" }, { "The following have been " }, { "deprecated:\n", "WarningMsg" } }, + _has_registered = false, } function M.write(...) - for _, e in ipairs({ ... }) do - table.insert(M._list, type(e) == "string" and { e } or e) - end + for _, e in ipairs({ ... }) do + table.insert(M._list, type(e) == "string" and { e } or e) + end - M._list[#M._list][1] = M._list[#M._list][1] .. "\n" + M._list[#M._list][1] = M._list[#M._list][1] .. "\n" - if not M._has_registered then - vim.cmd([[ + if not M._has_registered then + vim.cmd([[ augroup PersistedDeprecations au! autocmd VimEnter * ++once lua require("persisted.deprecate").flush() augroup END ]]) - M._has_registered = true - end + M._has_registered = true + end end function M.flush() - M.write( - "----------\n", - "See ", - { "https://github.com/olimorris/persisted.nvim/issues/51", "Title" }, - " for more information." - ) - vim.api.nvim_echo(M._list, true, {}) + M.write( + "----------\n", + "See ", + { "https://github.com/olimorris/persisted.nvim/issues/51", "Title" }, + " for more information." + ) + vim.api.nvim_echo(M._list, true, {}) end return M diff --git a/lua/persisted/init.lua b/lua/persisted/init.lua index 5c65a3e..6cb8a67 100644 --- a/lua/persisted/init.lua +++ b/lua/persisted/init.lua @@ -86,9 +86,7 @@ function M.load(opt) if session then if vim.fn.filereadable(session) ~= 0 then vim.g.persisting_session = config.options.follow_cwd and nil or session - -- TODO: Alter this function call after deprecation notice ends - utils.load_session(session, config.options.before_source, config.options.after_source, config.options.silent) - -- + utils.load_session(session, config.options.silent) elseif type(config.options.on_autoload_no_session) == "function" then config.options.on_autoload_no_session() end @@ -131,37 +129,26 @@ end function M.save(opt) opt = opt or {} - -- If the user has stopped the session, then do not save + -- Do not save the session if the user has manually stopped it if vim.g.persisting == false then return end - -- Autosave config option takes priority unless it's overriden + -- Do not save the session if autosave is turned off...unless it's overriden if not config.options.autosave and not opt.override then return end + -- Do not save the session if the callback returns false if type(config.options.should_autosave) == "function" and not config.options.should_autosave() then return end - --TODO: Remove this after deprecation notice period ends - if type(config.options.before_save) == "function" then - config.options.before_save() - end - -- - vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePre" }) vim.cmd("mks! " .. e(vim.g.persisting_session or get_current())) vim.g.persisting = true - --TODO: Remove this after deprecation notice period ends - if type(config.options.after_save) == "function" then - config.options.after_save() - end - -- - vim.api.nvim_exec_autocmds("User", { pattern = "PersistedSavePost" }) end diff --git a/lua/persisted/utils.lua b/lua/persisted/utils.lua index 93ab155..d0df86b 100644 --- a/lua/persisted/utils.lua +++ b/lua/persisted/utils.lua @@ -61,19 +61,9 @@ end ---Load the given session ---@param session string ----@param before_callback function ----@param after_callback function ---@param silent boolean Load the session silently? ---@return nil|string -function M.load_session(session, before_callback, after_callback, silent) - -- TODO: Clean up this function call after deprecation notice ends - - --TODO: Remove this after deprecation notice period ends - if type(before_callback) == "function" then - before_callback() - end - -- - +function M.load_session(session, silent) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPre", data = session }) local ok, result = pcall(vim.cmd, (silent and "silent " or "") .. "source " .. e(session)) @@ -81,12 +71,6 @@ function M.load_session(session, before_callback, after_callback, silent) return echoerr("Error loading the session! ", result) end - --TODO: Remove this after deprecation notice period ends - if type(after_callback) == "function" then - after_callback() - end - -- - vim.api.nvim_exec_autocmds("User", { pattern = "PersistedLoadPost", data = session }) end diff --git a/lua/telescope/_extensions/actions.lua b/lua/telescope/_extensions/actions.lua index 0f0d791..671f6a5 100644 --- a/lua/telescope/_extensions/actions.lua +++ b/lua/telescope/_extensions/actions.lua @@ -18,14 +18,7 @@ M.load_session = function(session, config) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPre", data = session }) vim.schedule(function() - -- TODO: clean up this function call after deprecation notice ends - utils.load_session( - session.file_path, - config.telescope.before_source and config.telescope.before_source(session) or _, - config.telescope.after_source and config.telescope.after_source(session) or _, - config.silent - -- - ) + utils.load_session(session.file_path, config.silent) end) vim.api.nvim_exec_autocmds("User", { pattern = "PersistedTelescopeLoadPost", data = session }) diff --git a/lua/telescope/_extensions/persisted.lua b/lua/telescope/_extensions/persisted.lua index 4c42990..ae0de2e 100644 --- a/lua/telescope/_extensions/persisted.lua +++ b/lua/telescope/_extensions/persisted.lua @@ -10,7 +10,7 @@ local telescope_opts = {} local function search_sessions(opts) local config = require("persisted.config").options - opts = vim.tbl_extend('force', telescope_opts, opts or {}) + opts = vim.tbl_extend("force", telescope_opts, opts or {}) pickers .new(opts, { @@ -21,7 +21,7 @@ local function search_sessions(opts) local refresh_sessions = function() local picker = action_state.get_current_picker(prompt_bufnr) picker:refresh(_finders.session_finder(require("persisted").list()), { - reset_prompt = config.telescope.reset_prompt_after_deletion + reset_prompt = config.telescope.reset_prompt_after_deletion, }) end