feat: add `silent` config option

main
Latif Sulistyo 2022-09-13 14:28:36 +07:00 committed by GitHub
parent 321ba42367
commit b54b72dbde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 6 deletions

View File

@ -126,6 +126,7 @@ The plugin comes with the following defaults:
require("persisted").setup({ require("persisted").setup({
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
command = "VimLeavePre", -- the autocommand for which the session is saved command = "VimLeavePre", -- the autocommand for which the session is saved
silent = false, -- silent nvim message when sourcing session file
use_git_branch = false, -- create session files based on the branch of the git enabled repository use_git_branch = false, -- create session files based on the branch of the git enabled repository
branch_separator = "_", -- string used to separate session directory name from branch name branch_separator = "_", -- string used to separate session directory name from branch name
autosave = true, -- automatically save session files when exiting Neovim autosave = true, -- automatically save session files when exiting Neovim

View File

@ -4,6 +4,7 @@ local M = {}
local defaults = { local defaults = {
save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
command = "VimLeavePre", -- the autocommand for which the session is saved command = "VimLeavePre", -- the autocommand for which the session is saved
silent = false, -- silent nvim message when sourcing session file
use_git_branch = false, -- create session files based on the branch of the git enabled repository use_git_branch = false, -- create session files based on the branch of the git enabled repository
branch_separator = "_", -- string used to separate session directory name from branch name branch_separator = "_", -- string used to separate session directory name from branch name
autosave = true, -- automatically save session files when exiting Neovim autosave = true, -- automatically save session files when exiting Neovim

View File

@ -93,7 +93,6 @@ function M.setup(opts)
then then
M.start() M.start()
end end
end end
---Load a session ---Load a session
@ -105,13 +104,12 @@ function M.load(opt)
if session then if session then
if vim.fn.filereadable(session) ~= 0 then if vim.fn.filereadable(session) ~= 0 then
utils.load_session(session, config.options.before_source, config.options.after_source) utils.load_session(session, config.options.before_source, config.options.after_source, config.options.silent)
elseif type(config.options.on_autoload_no_session) == 'function' then elseif type(config.options.on_autoload_no_session) == 'function' then
config.options.on_autoload_no_session() config.options.on_autoload_no_session()
end end
end end
if config.options.autosave and (allow_dir() and not ignore_dir()) then if config.options.autosave and (allow_dir() and not ignore_dir()) then
vim.schedule(function() vim.schedule(function()
M.start() M.start()

View File

@ -77,13 +77,13 @@ end
---@param session table ---@param session table
---@param before_callback function ---@param before_callback function
---@param after_callback function ---@param after_callback function
function M.load_session(session, before_callback, after_callback) function M.load_session(session, before_callback, after_callback, silent)
vim.schedule(function() vim.schedule(function()
if type(before_callback) == "function" then if type(before_callback) == "function" then
before_callback() before_callback()
end end
local ok, result = pcall(vim.cmd, "source " .. e(session)) local ok, result = pcall(vim.cmd, (silent and "silent " or "") .. "source " .. e(session))
if not ok then if not ok then
return M.echoerr("Error loading the session! ", result) return M.echoerr("Error loading the session! ", result)
end end

View File

@ -14,7 +14,8 @@ M.load_session = function(session, config)
utils.load_session( utils.load_session(
session.file_path, session.file_path,
config.telescope.before_source and config.telescope.before_source(session) or _, config.telescope.before_source and config.telescope.before_source(session) or _,
config.telescope.after_source and config.telescope.after_source(session) or _ config.telescope.after_source and config.telescope.after_source(session) or _,
config.silent
) )
end end