echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
5.18k stars 187 forks source link

Session management ala Startify #69

Closed dathinaios closed 2 years ago

dathinaios commented 2 years ago

Contributing guidelines

Module(s)

mini.sessions

Description

Coming from Startify I am used to saving and loading sessions using the commands SSave and SLoad which were really convenient including knowing the available sessions on TAB. How is that to be done with mini.sessions. If it is not built in how do I get this functionality?

Thank you for the useful plugin 🙂

dathinaios commented 2 years ago

Ok, I see that this is simply a matter of using mks! ~/.dotfiles/dotvim/sessions/ (that is just where I personally keep my sessions) to save and so ~/.dotfiles/dotvim/sessions/<Session name> to recall. Simple enough to define some mapping for this but it would be nice to have an MSSave, MSLoad etc. command. My instinct was to search with telescope on all commands for "session" and it would be nice to have found all that directly.

echasnovski commented 2 years ago

You have two ways:

As a general principle 'mini.nvim' does not supply any Neovim commands. Each module creates a global Lua object (MiniSessions for 'mini.sessions') which can be used with :lua MiniSessions....

dathinaios commented 2 years ago

Thank you! The .select approach is quite elegant. I mapped it to a key and I am getting the selection window but when I hit <CR> to action it, it throws an error:

E5108: Error executing lua ...m/site/pack/packer/start/mini.nvim/lua/mini/sessions.lua:577: (mini.sessions) There are unsaved buffers: 44.
stack traceback:
        [C]: in function 'error'
        ...m/site/pack/packer/start/mini.nvim/lua/mini/sessions.lua:577: in function 'error'
        ...m/site/pack/packer/start/mini.nvim/lua/mini/sessions.lua:182: in function <...m/site/pack/packer/start/mini.nvim/lua/mini/sessions.lua:154>
        ...m/site/pack/packer/start/mini.nvim/lua/mini/sessions.lua:371: in function 'on_choice'
        ...e-ui-select.nvim/lua/telescope/_extensions/ui-select.lua:122: in function 'run_replace_or_original'
        ...packer/start/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:242: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk

My mapping is simply:

  nmap <Leader>:sl :lua MiniSessions.select('read')<CR>
  nmap <Leader>:ss :lua MiniSessions.select('write')<CR>
  nmap <Leader>:sd :lua MiniSessions.select('delete')<CR>

I do have a workaround so no big deal. Here it is for reference:

  nmap <Leader>:ss :mks! ~/.dotfiles/dotvim/sessions/
  nmap <Leader>:sl :so ~/.dotfiles/dotvim/sessions/
  nmap <Leader>:sd :!rm ~/.dotfiles/dotvim/sessions/

and then I just hit <TAB>.

echasnovski commented 2 years ago

Well, error message says it all. You have unsaved buffer number 44. By default, MiniSessions.read() doesn't work if there is at least one unsaved buffer. That is something 'vim-startify' does, if I remember correctly. To ignore that, set force option to true: either in config.force.read inside setup() or as extra argument to select().

dathinaios commented 2 years ago

Indeed, but I don't have any unsaved buffers. I use auto-save + unlimited undo so that never happens. I did double check though just in case though and the error persists.

echasnovski commented 2 years ago

That is very strange. I can reproduce this issue only if there is unsaved buffer. How did you check for unsaved buffers? I recommend using :bmodified!: in case of no modified buffers it gives a E84: No modified buffer found.

If indeed no unsaved buffers, I would be grateful if you come up with reproducible example for this and create an issue.

dathinaios commented 2 years ago

Yes, it does return E84: No modified buffer found. I will create an issue though not sure what a reproducible example would be. All I am doing is trying to use lua MiniSessions.select('read') and lua MiniSessions.select('write').

dathinaios commented 2 years ago

I created issue #71. Seems to be related to Telescope.