From b3f589a696c1b4ea4d2880403498e417b4c3ecd5 Mon Sep 17 00:00:00 2001 From: Ronnie Magatti Date: Sat, 30 Mar 2024 22:20:50 -0600 Subject: [PATCH 1/2] Add ability to control whether to silently restore session or not Fixes #278 --- lua/auto-session/init.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/auto-session/init.lua b/lua/auto-session/init.lua index 586790d..d50f986 100644 --- a/lua/auto-session/init.lua +++ b/lua/auto-session/init.lua @@ -36,7 +36,6 @@ end ---@class defaultConf ---@field log_level string|integer "debug", "info", "warn", "error" or vim.log.levels.DEBUG, vim.log.levels.INFO, vim.log.levels.WARN, vim.log.levels.ERROR ---@field auto_session_enable_last_session boolean ----@field auto_session_last_session_dir string ---@field auto_session_root_dir string root directory for session files, by default is `vim.fn.stdpath('data')/sessions/` ---@field auto_session_enabled boolean enable auto session ---@field auto_session_create_enabled boolean|nil Enables/disables auto creating new sessions @@ -58,13 +57,14 @@ local defaultConf = { auto_restore_enabled = nil, -- Enables/disables auto restore feature auto_session_suppress_dirs = nil, -- Suppress session restore/create in certain directories auto_session_allowed_dirs = nil, -- Allow session restore/create in certain directories - auto_session_use_git_branch = vim.g.auto_session_use_git_branch or false, + auto_session_use_git_branch = vim.g.auto_session_use_git_branch or false, -- Include git branch name in session name } ---Lua Only Configs for Auto Session ---@class luaOnlyConf ---@field cwd_change_handling CwdChangeHandling ---@field bypass_session_save_file_types? table List of file types to bypass auto save when the only buffer open is one of the file types listed +---@field silent_restore boolean Whether to restore sessions silently or not local luaOnlyConf = { bypass_session_save_file_types = nil, -- Bypass auto save when only buffer open is one of these file types ---CWD Change Handling Config @@ -96,6 +96,7 @@ local luaOnlyConf = { control_filename = "session_control.json", -- File name of the session control file }, }, + silent_restore = true } -- Set default config on plugin load @@ -655,7 +656,7 @@ function AutoSession.RestoreSession(sessions_dir_or_file) local pre_cmds = AutoSession.get_cmds "pre_restore" run_hook_cmds(pre_cmds, "pre-restore") - local cmd = "silent source " .. file_path + local cmd = AutoSession.conf.silent_restore and "silent source " or "source " .. file_path local success, result = pcall(vim.cmd, cmd) if not success then From dcf788a380786e57020fd2e95a4a052feef12aee Mon Sep 17 00:00:00 2001 From: rmagatti Date: Sun, 31 Mar 2024 04:21:24 +0000 Subject: [PATCH 2/2] chore(docs): auto-generate vimdoc --- doc/auto-session.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/auto-session.txt b/doc/auto-session.txt index 23995ad..458aded 100644 --- a/doc/auto-session.txt +++ b/doc/auto-session.txt @@ -4,7 +4,6 @@ defaultConf *defaultConf* Fields: ~ {log_level} (string|integer) "debug", "info", "warn", "error" or vim.log.levels.DEBUG, vim.log.levels.INFO, vim.log.levels.WARN, vim.log.levels.ERROR {auto_session_enable_last_session} (boolean) - {auto_session_last_session_dir} (string) {auto_session_root_dir} (string) root directory for session files, by default is `vim.fn.stdpath('data')/sessions/` {auto_session_enabled} (boolean) enable auto session {auto_session_create_enabled} (boolean|nil) Enables/disables auto creating new sessions @@ -21,6 +20,7 @@ luaOnlyConf *luaOnlyConf* Fields: ~ {cwd_change_handling} (CwdChangeHandling) {bypass_session_save_file_types?} (table) List of file types to bypass auto save when the only buffer open is one of the file types listed + {silent_restore} (boolean) Whether to restore sessions silently or not CwdChangeHandling *CwdChangeHandling*