Skip to content

Commit

Permalink
feat: prompt for name if none provided when saving. (#62)
Browse files Browse the repository at this point in the history
* feat: prompt for name if none provided when saving.

* docs: add note about PossessionSave prompting for name

* feat: use vim.ui.input instead of vim.fn when prompting for session name

* fix: keep the "no-name" error message for other commands than save

---------

Co-authored-by: Jędrzej Boczar <[email protected]>
  • Loading branch information
josh-nz and jedrzejboczar authored Jun 11, 2024
1 parent 9851b91 commit 3ae6124
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion doc/possession.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ currently loaded session is used (unless noted otherwise).

Save the current session information under `session_dir`. Use
`:PossessionSave! [{name}]` to avoid asking for confirmation when overwriting
existing session file.
existing session file. If [{name}] is not provided and a session does not
already exist, you will be prompted for a name.

*:PossessionLoad*
:PossessionLoad [{name}]~
Expand Down
9 changes: 7 additions & 2 deletions lua/possession/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ end
---@param name? string
---@param no_confirm? boolean
function M.save(name, no_confirm)
name = name_or(name, get_current)
name = name_or(name, session.get_session_name)
local save = function(session_name)
session.save(session_name, { no_confirm = no_confirm })
end
if name then
session.save(name, { no_confirm = no_confirm })
save(name)
else
vim.ui.input({ prompt = 'Session name: ' }, save)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lua/possession/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function M.save(name, opts)
local path = paths.session(name)
local short = paths.session_short(name)
local commit = function(ok)
utils.clear_prompt()
if ok then
vim.fn.mkdir(config.session_dir, 'p')
path:write(vim.json.encode(session_data), 'w')
Expand All @@ -117,7 +118,7 @@ function M.save(name, opts)

utils.info('Saved as "%s"', short)
else
utils.info('Aborting')
utils.info('Aborting save')
end

if not opts.vimscript then
Expand Down Expand Up @@ -342,7 +343,7 @@ function M.delete(name, opts)
utils.info('Deleted "%s"', short)
end
else
utils.info('Aborting')
utils.info('Aborting delete')
end

if opts.callback then
Expand Down

0 comments on commit 3ae6124

Please sign in to comment.