Skip to content

Commit

Permalink
Merge pull request #120 from WhoIsSethDaniel/completion_for_restore
Browse files Browse the repository at this point in the history
* Add new command :RestoreSessionFromFile.
  • Loading branch information
rmagatti authored Mar 15, 2022
2 parents da8a37d + 735d82a commit ba16062
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Auto Session exposes two commands that can be used or mapped to any keybindings
:SaveSession ~/my/custom/path " saves or creates a session in the specified directory path.
:RestoreSession " restores a previously saved session based on the `cwd`.
:RestoreSession ~/my/custom/path " restores a previously saved session based on the provided path.
:RestoreSessionFromFile ~/session/path " restores any currently saved session
:DeleteSession " deletes a session in the currently set `auto_session_root_dir`.
:DeleteSession ~/my/custom/path " deleetes a session based on the provided path.
```
Expand Down
10 changes: 7 additions & 3 deletions lua/auto-session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ local function bypass_save_by_filetype()

for _, ft_to_bypass in ipairs(file_types_to_bypass) do
if buf_ft == ft_to_bypass then
Lib.logger.debug("bypass_save_by_filetype: true")
Lib.logger.debug "bypass_save_by_filetype: true"
return true
end
end
end

Lib.logger.debug("bypass_save_by_filetype: false")
Lib.logger.debug "bypass_save_by_filetype: false"
return false
end

Expand Down Expand Up @@ -310,6 +310,10 @@ local function extract_dir_or_file(sessions_dir_or_file)
return sessions_dir, session_file
end

function AutoSession.RestoreSessionFromFile(session_file)
AutoSession.RestoreSession(string.format(AutoSession.get_root_dir() .. "%s.vim", session_file:gsub("/", "%%")))
end

-- TODO: make this more readable!
-- Restores the session by sourcing the session file if it exists/is readable.
function AutoSession.RestoreSession(sessions_dir_or_file)
Expand All @@ -326,7 +330,7 @@ function AutoSession.RestoreSession(sessions_dir_or_file)
if not success then
Lib.logger.error([[
Error restoring session! The session might be corrupted.
Disabling auto save. Please check for errors in your config. Error:
Disabling auto save. Please check for errors in your config. Error:
]] .. result)
AutoSession.conf.auto_save_enabled = false
return
Expand Down
2 changes: 2 additions & 0 deletions plugin/auto-session.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let g:in_pager_mode = 0

let LuaSaveSession = luaeval('require("auto-session").SaveSession')
let LuaRestoreSession = luaeval('require("auto-session").RestoreSession')
let LuaRestoreSessionFromFile = luaeval('require("auto-session").RestoreSessionFromFile')
let LuaDeleteSessionByName = luaeval('require("auto-session").DeleteSessionByName')
let LuaDisableAutoSave = luaeval('require("auto-session").DisableAutoSave')

Expand All @@ -20,6 +21,7 @@ endfunction
" Available commands
command! -nargs=* SaveSession call LuaSaveSession(expand('<args>'))
command! -nargs=* RestoreSession call LuaRestoreSession(expand('<args>'))
command! -nargs=1 -complete=custom,CompleteSessions RestoreSessionFromFile call LuaRestoreSessionFromFile(expand('<args>'))
command! -nargs=* -complete=custom,CompleteSessions DeleteSession call LuaDeleteSessionByName(<f-args>)
command! -nargs=* DisableAutoSave call LuaDisableAutoSave()

Expand Down

0 comments on commit ba16062

Please sign in to comment.