bloznelis / before.nvim

Jump to the last edit in Neovim
MIT License
114 stars 4 forks source link

Save between sessions #5

Open srcrip opened 6 months ago

srcrip commented 6 months ago

It should be pretty easy to add in. There's a temp directory that you can access for neovim that you can serialize all this too.

mikavilpas commented 6 months ago

I like this idea. g; seems to work based on a previous session by default (not sure about the details).

srcrip commented 6 months ago

I started looking into it a little bit, but one thing thats puzzling to me is the way past edits get jumped to. Why loop through all the edits to try to find the right place? Why not just store an index in memory of your current location in the list?

srcrip commented 6 months ago

if anyone wants to clean #8 up, I put forth some initial ideas of what could be done there.

saving to a file is easy, nothing to really say about that. you do need to start tracking file names, but thats not hard. the serialization and deserialization is also pretty trivial.

bloznelis commented 6 months ago

Why loop through all the edits to try to find the right place?

Because you can't know how many invalid (for example, out of buffer range) locations you are storing.

ColinKennedy commented 6 months ago

Rather than using a temp directory or viminfo or some other "global" location it'd be nice if this could work with Vim sessions (:help mksession). Reason: Edits frequently are concentrated in pockets. e.g. this repository has A B C edits, this other repository has X Y edits, and A B C X Y don't relate to one another so it wouldn't make sense to have those as a single, global list. Having separate edit_locations per session means you can keep these histories separate. Combining before.nvim with Vim's session and https://github.com/rmagatti/auto-session would be a great pairing. In contrast, viminfo / temp directories are context-less. You'd to build it manually for edits to be project-based.

mikavilpas commented 6 months ago

Can you save plugin settings to session files?

I looked at how harpoon saves its sessions and looks like it's custom json https://github.com/ThePrimeagen/harpoon/blob/ccae1b9bec717ae284906b0bf83d720e59d12b91/lua/harpoon/init.lua#L169


// /Users/mikavilpas/.local/share/nvim/harpoon.json
// 
{
//..... many other projects' settings
  "/Users/mikavilpas/dotfiles/.config/nvim": {
    "__harpoon_files": [
      "{\"context\":{\"col\":36,\"row\":7},\"value\":\"lua\\/plugins\\/range-highlight.lua\"}",
      "{\"value\":\"lua\\/plugins\\/my-telescope-copy-relative-path.lua\",\"context\":{\"col\":0,\"row\":25}}",
      "{\"context\":{\"col\":34,\"row\":31},\"value\":\"lua\\/plugins\\/telescope.lua\"}"
    ]
  },
}
ColinKennedy commented 6 months ago

I wouldn't use harpoon as an example of how to write sustainable plugins. They're going through a rewrite due to the project being over-scoped.

To answer your question more directly, I'm not sure how plugins are meant to append to session files. I added https://github.com/neovim/neovim/issues/27761 to get clarification. There is https://github.com/tpope/vim-obsession of course but that's a wrap of :mksession. There might not be an easy way to append (yet)

srcrip commented 6 months ago

I would not personally recommend going with vim sessions. vim session files are meant to restore all of vim-state to some past state. I don't really think its the right choice for this kind of application. Serializing to a text file in the cache directory is an approach that many other plugins do

bloznelis commented 6 months ago

Serializing to a text file in the cache directory is an approach that many other plugins do

Yep, I think we should do it like this. Just maybe not JSON?

srcrip commented 6 months ago

Yeah I don't think json is really needed. if you check out my example PR you'll see I just saved it in a format where each entry was on its own line, with each category separated by a : character

srcrip commented 6 months ago

My proof-of-concept kind of works, but it randomly fails to load correctly so I'm not 100% sure what the issue is there yet