Telescope extension to list sessions
olimorris opened this issue · comments
As discussed in #5:
I thought I could create a mapping directly to lua require("persisted").list() and have it open in a Telescope window. Perhaps you would consider adding in a telescope extension? Then all that would be required for the user would be something along the lines of (note that I use the cartographer plugin for my mappings):
require('telescope').load_extension('persisted') map.n.nore.silent['<leader>tp'] = ':Telescope persisted<cr>'
Will expand functionality in due course to allow for sessions to be deleted
Latest commit:
- Improves performance on bootup - Was previously calling the
list
function on bootup - Have removed the
pwd
value in the telescope table as this is quite difficult to calculate. Will likely add this back by reading the session file manually at some point - Improved aesthetic of Telescope window by making use of all available columns
@olimorris Is this functionality currently working? I have been setting up this plugin and it appears that the telescope picker has no affect on loading the session. I am able to bring up the picker and it shows my sessions, but then upon selecting one it doesn't load the session or anything.
Yeah it should automatically source the session you select. Are you getting any feedback?
I am not getting any feedback at all. It just closes and doesn't load anything
I am using the following settings:
{
dir = vim.fn.expand(vim.fn.stdpath "data" .. "/sessions/"), -- directory where session files are saved
use_git_branch = true, -- create session files based on the branch of the git enabled repository
autosave = false, -- automatically save session files when exiting Neovim
}
@olimorris I tried to use after_source and before source funtion to do this
before_source = function(session)
vim.cmd("source " .. vim.fn.fnameescape(session.file_path))
end, -- function to run before the session is sourced via telescope
after_source = function(session)
vim.cmd("source " .. vim.fn.fnameescape(session.file_path))
end, -- function to run after the session is sourced via telescope
just to get error instead of call it by pcall ( which will skip the error ), and I got this error message
E5108: Error executing lua /home/dat/.config/nvim/lua/configs/persisted.lua:22: Vim(only):E445: Other window contains changes
stack traceback:
[C]: in function 'cmd'
/home/dat/.config/nvim/lua/configs/persisted.lua:22: in function 'after_source'
...t/persisted.nvim/lua/telescope/_extensions/persisted.lua:66: in function 'run_replace_or_original'
...k/packer/opt/telescope.nvim/lua/telescope/actions/mt.lua:65: in function 'key_func'
...ack/packer/opt/telescope.nvim/lua/telescope/mappings.lua:242: in function 'execute_keymap'
[string ":lua"]:1: in main chunk
It has worked for me for days but now it stopped working.
I think its caused by telescope latest update... not sure though.
EDIT:
Ok - pining telescope to commit - nvim-telescope/telescope.nvim@57bd8a5
fixes the issue. I guess I will report it on tele issues?
use {
"nvim-telescope/telescope.nvim",
commit = "57bd8a500213c274558f253478a11fd77e4c9fcb",
Thanks @JoseConseco for flagging. Can confirm I'm now having the issue after the latest Telescope update
Seems like this has been resolved in the latest Telescope update.
I'm getting this error:
Error executing Lua callback: ...t/persisted.nvim/lua/telescope/_extensions/persisted.lua:19: attempt to compare functi
on with number
stack traceback:
...t/persisted.nvim/lua/telescope/_extensions/persisted.lua:19: in function <...t/persisted.nvim/lua/telescope/
_extensions/persisted.lua:8>
...ck/packer/start/telescope.nvim/lua/telescope/command.lua:193: in function 'run_command'
...ck/packer/start/telescope.nvim/lua/telescope/command.lua:253: in function 'load_command'
...te/pack/packer/start/telescope.nvim/plugin/telescope.lua:109: in function <...te/pack/packer/start/telescope
.nvim/plugin/telescope.lua:108>
It's working absolutely fine for me. Could you try to update the plugin and then share your config?
It is related to this telescope config. I haven't run into issues previously and it is valid AFAIK.
layout_config = {
preview_cutoff = 1, -- Preview should always show (unless previewer = false)
width = function(_, max_columns, _)
return math.min(max_columns, 100)
end,
height = function(_, _, max_lines)
return math.min(max_lines, 15)
end,
},
Adding the below snippet here does the trick. Not sure if that is how you want to handle it.
if type(telescope_width) == "function" then
telescope_width = telescope_width(_, cols, _)
end
@ranebrown I've pushed this fix
As of today, I've added the ability to delete sessions via Telescope with <C-d>
. It will prompt you for confirmation before updating the list of sessions.
Let me know if there's any additional functionality that you'd all like.
Hello, thanks for this extension!
Can be name of the session added to the list as a new column (on the left, for example)? If you create multiple sessions in one repo, you won't be able to tell one from another:
Also variant with preview would be dope (like in find_files
) where the last buffer you were editing would be previewed (if it is not possible to parse from session info than random file would be cool too).
There's a bit of work I still need to do with the presentation of the picker and hoping this will achieve your ask. Will look to fix this week
Hello, @olimorris. Telescope extension works fine. Shouldn't it also close previous open buffers once opens another session? Right now when I choose different session the buffers from previous one are still in the editor. Is it expected?
Hello, @olimorris. Telescope extension works fine. Shouldn't it also close previous open buffers once opens another session? Right now when I choose different session the buffers from previous one are still in the editor. Is it expected?
It is right now. You can initiate a callback before the session is loaded to clear out all of the open buffers
For those who are interested in integrating persisted with LunarVim (with autoload
working!):
{
"olimorris/persisted.nvim",
event = "VimEnter", -- this will allow to have autoload feature working
module = "persisted",
config = function()
require("persisted").setup {
autoload = true
}
require("telescope").load_extension("persisted")
end,
}
For those who want telescope removing previous open buffers (from current session) before switching to a new session:
{
"olimorris/persisted.nvim",
event = "VimEnter", -- this will allow to have autoload feature working
module = "persisted",
config = function()
require("persisted").setup {
autoload = true,
telescope = {
before_source = function()
vim.api.nvim_input('<ESC>:%bd<CR>')
end
}
}
require("telescope").load_extension("persisted")
end,
}
@olimorris you can include this example in readme or somewhere if you want.
Thanks for the telescope addition! Really awesome.
Regarding the general persisted config, do you need the below lines?
event = "VimEnter",
module = "persisted",
Could you not just have autoload = true
in the config?
As far as I know module
line allows to load the plugin in async mode instead of sync. So it's not super required (and probably requires additional plugins which I already have).
event
is not needed too but I specified that because official LunarVim documentation has note about it: https://www.lunarvim.org/plugins/02-extra-plugins.html#persistence
The text says that you need to specify:
event = "BufReadPre", -- this will only start session saving when an actual file was opened
But this event makes autoload unusable in your version of plugin (while it somehow partially working in original plugin you got code from).
Since I didn't know about that incompatibility I lost some time trying to figure out why the autoload not autoloading at all:)
So, yeah, both lines are not required, I checked without them and the plugin works fine (in LunarVim at least)
Does anyone have any further suggestions for Telescope integration?
I'll leave this issue open for the next week but keen to hear any further ideas. Currently the deleting of a session is a bit clunky so will likely work on that.
Can the .vim
extension of a session name be hidden, maybe? Or a session given a special name?
Either way thank you for the awesome plugin!
@zetashift great tip. Have added in the latest commit.