From 59f397468593c3f2bf7720bec874d1daf9998edd Mon Sep 17 00:00:00 2001 From: Cameron Ring Date: Mon, 14 Oct 2024 13:44:58 -0700 Subject: [PATCH] fix: #386 use right session name in auto create When auto-saving, if the session has been manually named use that session name instead of the cwd session name. Fixes manually named session not auto-saving on exit. --- lua/auto-session/init.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lua/auto-session/init.lua b/lua/auto-session/init.lua index 80a424d..d959196 100644 --- a/lua/auto-session/init.lua +++ b/lua/auto-session/init.lua @@ -298,8 +298,16 @@ function AutoSession.AutoSaveSession() return false end + -- If there's a manually named session, use that on exit instead of one named for cwd + local current_session = nil + + if AutoSession.manually_named_session then + current_session = Lib.escaped_session_name_to_session_name(vim.fn.fnamemodify(vim.v.this_session, ":t")) + Lib.logger.debug("Using existing session name: " .. current_session) + end + if not is_auto_create_enabled() then - local session_file_name = get_session_file_name() + local session_file_name = get_session_file_name(current_session) if vim.fn.filereadable(AutoSession.get_root_dir() .. session_file_name) == 0 then Lib.logger.debug "Create not enabled and no existing session, not creating session" return false @@ -314,13 +322,6 @@ function AutoSession.AutoSaveSession() end end - -- If there's a manually named session, use that on exit instead of one named for cwd - local current_session = nil - if AutoSession.manually_named_session then - current_session = Lib.escaped_session_name_to_session_name(vim.fn.fnamemodify(vim.v.this_session, ":t")) - Lib.logger.debug("Using existing session name: " .. current_session) - end - -- Don't try to show a message as we're exiting return AutoSession.SaveSession(current_session, false) end