Giter VIP home page Giter VIP logo

Comments (15)

olimorris avatar olimorris commented on August 22, 2024 1

This is my hook:

  {
    name = "PersistedHooks",
    {
      "User",
      function(session)
        require("persisted").save()

        -- Delete all of the open buffers
        vim.api.nvim_input("<ESC>:%bd!<CR>")

        -- Don't start saving the session yet
        require("persisted").stop()
      end,
      opts = { pattern = "PersistedTelescopeLoadPre" },
    },
  },

That seems to do everything you're asking. It's in a different format as I use the legendary.nvim plugin

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024 1

Think I've solved it. If you update the plugin and try require("persisted").save({ session = vim.g.persisted_loaded_session })

After a session loads, the global variable gets updated with the path to that session allowing you to manually save it.

thank you!, this save me a ton, probably others.

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

If i remove pcall(vim.cmd, "SessionSave"), it seems to work but i.e: you had sesison of folder1 with two buffers buf1,buf2
then nvim under folder1 will restore two buffers as expected, then you open buf3 and call :Telescope persisted to switch to another session --> now session folder1 still only have two buffers --> show be 3.

My setup works before and current idk from neovim or persisted, it stop working or become junky.

from persisted.nvim.

olimorris avatar olimorris commented on August 22, 2024

@tmpm697 can you use the minimal.lua file in the initial bug report and share it so I can try and recreate it.

It's like searching for a needle in a haystack without it.

from persisted.nvim.

olimorris avatar olimorris commented on August 22, 2024

Will reopen when you can recreate with a minimal.lua file

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

just tested with only two plugins telescope.nvim and persisted.nvim the issue still happnes, overlap/overwrite/mess up saved sessions.

prepare:

  1. clone persisted.nvim/, plenary.nvim/, telescope.nvim/ to ~/.local/share/nvim/site/pack/default/start
  2. vi init.lua

minimal init.lua:

-- other require() for mapping, options and autocmd
autocmd({ "User" }, {
	pattern = "PersistedTelescopeLoadPre",
	group = augroup,
	callback = function()
		vim.schedule(function()
			pcall(vim.cmd, "silent %bd!")
		end)
	end,
})

-- require for telescope.nvim

require("persisted").setup({
  save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved
  silent = true, -- silent nvim message when sourcing session file
  use_git_branch = false, -- create session files based on the branch of the git enabled repository
  autosave = true, -- automatically save session files when exiting Neovim
  autoload = true, -- automatically load the session for the cwd on Neovim startup
  on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load
  follow_cwd = true, -- change session file name to match current working directory if it changes
  allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from
  ignored_dirs = { "/tmp" }, -- table of dirs that are ignored when auto-saving and auto-loading
  should_autosave = nill
  telescope = { -- options for the telescope extension
    reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted
  },
})
require("telescope").load_extension("persisted") -- To load the telescope extension

and default telescope.nvim setup (if you also need it, please let me know)

steps:

  1. cd to folderA (can have path like /path/to/folderA) and open some files via :e filenames
  2. quit (:wq) to trigger auto save --> new session created and saved to ~/.local/share/nvim/sessions/
  3. cd to folderB and open some files
  4. quit to trigger auto save
  5. exit nvim
  6. cd to folderA
  7. switch to folderB using telescope
  8. quit to trigger auto save ---> Now saved session file from folderB will overwrite saved session file from folderA, switch between session A and B now only see session B

both follow_cwd = true or follow_cwd = false give same result

expected: with above settings, switch session will clean up current buffers and restore switching session, switch back and forth does not messup saved sessions.

I did not observe this issue until recent refactor that introduce: https://github.com/olimorris/persisted.nvim#events--callbacks
@olimorris

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

@olimorris can you re-open this?

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

Thanks, I'll play around and give it a try.

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

yes, the only need to change to make this work is:

require("persisted").stop()

have no idea but if not this cause so much trouble for me. overlapping session make it unusable for a quit of time.

thanks.

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

but for example, when i switch to a session and start to open some buffers there like:

  1. at folderA (sessionA)
  2. switch to folderB (sessionB)
  3. start to open some buffers in this sessionB
  4. switch to folderC (sessionC)
  5. now switch back to folderB (sessionB) ---> opened buffers at step 3 did not registered to sessionB (they're not saved to sessionB)

How to have buffers in step 3 in sessionB between switch?

should I open new issue?

from persisted.nvim.

olimorris avatar olimorris commented on August 22, 2024

You'll need to manually save the session before you switch. In your steps above I can't see where you're saving it

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

You'll need to manually save the session before you switch. In your steps above I can't see where you're saving it

can i autosave it when i switch session at step 4? manually save session is not ideal for me.

if yes, what should this can be changed to?

      function(session)
        require("persisted").save()
        vim.api.nvim_input("<ESC>:%bd!<CR>")
        require("persisted").stop()
      end,

EDIT: afiak if autosave look for current cwd to save session, the target session will be overwrite by current one --> this is the #1 issue

from persisted.nvim.

olimorris avatar olimorris commented on August 22, 2024

Autosave will only work when you exit Neovim.

But I've just pushed a commit through as you were right it won't actually save the correct session. If you try this:

function(session)
  require("persisted").save({ session = session.data.file_path })

  -- Delete all of the open buffers
  vim.api.nvim_input("<ESC>:%bd!<CR>")

  -- Don't start saving the session yet
  require("persisted").stop()
end,

It should now work.

from persisted.nvim.

tmpm697 avatar tmpm697 commented on August 22, 2024

Does not work for me, use 06946ed commit and

function(session)
  require("persisted").save({ session = session.data.file_path })

  -- Delete all of the open buffers
  vim.api.nvim_input("<ESC>:%bd!<CR>")

  -- Don't start saving the session yet
  require("persisted").stop()
end,

clean up all sessions, switch from sessionB to sessionA will overwrite sessionA by sessionB.

from persisted.nvim.

olimorris avatar olimorris commented on August 22, 2024

Think I've solved it. If you update the plugin and try require("persisted").save({ session = vim.g.persisted_loaded_session })

After a session loads, the global variable gets updated with the path to that session allowing you to manually save it.

from persisted.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.