diff --git a/README.md b/README.md index ea1119a..b5b5a65 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ The plugin saves the sessions in the specified folder (see [configuration](#conf Use the command `:SessionManager[!]` with one of the following arguments: -| Argument | Description | -| -----------------------------| -------------------------------------------------------------------------------------------- | -| `load_session` | Select and load session. (Your current session won't appear on the list). | -| `load_last_session` | Will remove all buffers and `:source` the last saved session. (returns true if the session was restored and false otherwise) | -| `load_current_dir_session` | Will remove all buffers and `:source` the last saved session file of the current directory. (returns true if the session was restored and false otherwise) | -| `save_current_session` | Works like `:mksession`, but saves/creates current directory as a session in `sessions_dir`. | -| `delete_session` | Select and delete session. | -| `delete_current_dir_session`| Deletes the session associated with the current directory. | +| Argument | Description | +| -----------------------------| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `load_session` | Select and load session. (Your current session won't appear on the list). | +| `load_last_session` | Removes all buffers and tries to `:source` the last saved session. Returns `true` if the session was restored and `false` otherwise. | +| `load_current_dir_session` | Removes all buffers and tries to `:source` the last saved session file of the current directory. Returns `true` if the session was restored and `false` otherwise. | +| `save_current_session` | Works like `:mksession`, but saves/creates current directory as a session in `sessions_dir`. | +| `delete_session` | Select and delete session. | +| `delete_current_dir_session` | Deletes the session associated with the current directory. | When `!` is specified, the modified buffers will not be saved. @@ -36,7 +36,7 @@ require('session_manager').setup({ sessions_dir = Path:new(vim.fn.stdpath('data'), 'sessions'), -- The directory where the session files will be saved. session_filename_to_dir = session_filename_to_dir, -- Function that replaces symbols into separators and colons to transform filename into a session directory. dir_to_session_filename = dir_to_session_filename, -- Function that replaces separators and colons into special symbols to transform session directory into a filename. Should use `vim.uv.cwd()` if the passed `dir` is `nil`. - autoload_mode = config.AutoloadMode.LastSession, -- Define what to do when Neovim is started without arguments. + autoload_mode = config.AutoloadMode.LastSession, -- Define what to do when Neovim is started without arguments. See "Autoload mode" section below. autosave_last_session = true, -- Automatically save last session on exit and on session switch. autosave_ignore_not_normal = true, -- Plugin will not save a session when no buffers are opened, or all of them aren't writable or listed. autosave_ignore_dirs = {}, -- A list of directories where the session will not be autosaved. @@ -54,16 +54,16 @@ require('session_manager').setup({ If Neovim is started without arguments the value of the autoload_mode option is used to determine which session to initially load. The following modes are supported: -| Mode | Description | -| --- | --- | -| Disabled | No session will be loaded. | -| CurrentDir | The session in the current working directory will be loaded. | -| LastSession | The last session will be loaded. This is the default.| +| Mode | Description | +| ----------- | ------------------------------------------------------------ | +| Disabled | No session will be loaded. | +| CurrentDir | The session in the current working directory will be loaded. | +| LastSession | The last session will be loaded. This is the default. | -Autoload_mode can be set to either a single mode or an array of modes, in which +`autoload_mode` can be set to either a single mode or an array of modes, in which case each mode will be tried until one succeeds e.g. -``` +```lua autoload_mode = { config.AutoloadMode.CurrentDir, config.AutoloadMode.LastSession } ``` diff --git a/lua/session_manager/init.lua b/lua/session_manager/init.lua index b66df4a..dbf0a4e 100644 --- a/lua/session_manager/init.lua +++ b/lua/session_manager/init.lua @@ -40,7 +40,7 @@ function session_manager.load_session(discard_current) end) end ---- Loads saved used session. +--- Tries to load the last saved session. ---@param discard_current boolean?: If `true`, do not check for unsaved buffers. ---@return boolean: `true` if session was loaded, `false` otherwise. function session_manager.load_last_session(discard_current) @@ -52,7 +52,7 @@ function session_manager.load_last_session(discard_current) return false end ---- Loads a session for the current working directory. +--- Tries to load a session for the current working directory. ---@return boolean: `true` if session was loaded, `false` otherwise. function session_manager.load_current_dir_session(discard_current) local cwd = vim.uv.cwd() @@ -85,10 +85,12 @@ function session_manager.autoload_session() if vim.fn.argc() > 0 or vim.g.started_with_stdin then return end + local modes = config.autoload_mode if not vim.isarray(config.autoload_mode) then modes = { config.autoload_mode } end + for _, mode in ipairs(modes) do if autoloaders[mode]() then return