-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistent State (session) #401
Comments
Now the question is: what file format ? In the ideal case, like for vim, a script which can be edited. |
This should probably be implemented as a plugin (whenever that functionality is available). That said, it would probably be prudent to use something easy to serialize. TOML is already used for the basic config, so why not stick with that? An example, totally fictional file might store information about the documents themselves like: [[documents]]
path = "/canonical/file/path"
cursor = { line = 90, column = 1 }
alt_document = "/canonical/file/path2" # this is "last_accessed_doc"
# no focused here; would be deserialized as false
[[documents.selections]]
start = { line = 70, column = 10 }
end = { line = 100, column = 1 }
[[documents.selections]]
start = { line = 1, column = 1 }
end = { line = 2, column = 23 }
[[documents]]
path = "/canonical/file/path2"
cursor = { line = 1, column = 1 }
# no alt_document here because it doesn't have one; would be deserialized as None
focused = true # means this document is currently visible
[[documents.selections]]
start = { line = 1, column = 10 }
end = { line = 5, column = 1 }
[[documents.selections]]
start = { line = 10, column = 1 }
end = { line = 10, column = 3 } I don't currently have any ideas on how we would serialize the current layout of views to TOML, though. |
Sublime Text has this awesome "hot exit" feature that allows you to exit without any "Save unsaved files?" confirmation and reopen to exactly the same state, it's very useful for regular use, not just crashes. (quote from ST regarding this feature)
|
For what it's worth, I'd like to propose that this not be a plugin. I know Helix calls itself a text editor, but it definitely seeks to have "MVP IDE" features, and this is something VS Code and other editors do out of the box to various degrees. Additionally, this sort of persistence is really nice to have for a number of reasons, especially if you regularly switch between projects wanting to sort of pick up where you left off. Happy to argue and be wrong, but I think this should be considered core functionality! There are a couple of fairly simple ways I think we could achieve this without too much effort and with 99% of the benefit. I think if you open helix "bare" (that is, without specifying a file argument) in a given directory, it could simply save the state it exits with to a file (either TOML or SQLite I imagine) as it exits. When you open helix "bare" again in that same directory, it loads up that same state. Alternatively, instead of the "bare" logic, it could be a command (which in turn might be triggered with a flag like Likely the terminology here would need to change since Helix would need to know if it's "managing" a session so that when it comes exit time, it knows to write the session to the file. Additionally, maybe the session is written to very often (but certainly not for every state change?) and nothing special needs to happen specifically on exit. It would be worth investigating how other editors (or their plugins) handle this. At a minimum to be useful (at least to me given my current neovim setup), I would expect the following to be stored:
Other things that would be nice:
Other considerations to take into account:
Anyways, this is something I'd like to work on if it's "blessed". |
I am a Jetbrains user myself and currently switch back and forth between Adding persistent state (perhaps even extended to a project level) would really be great. Having a means in the (core) code to be able to dump/restore state I find a big plus to any software. It might even help development as a means to easily create/record test fixtures or to provide/record reproducible bug-reports. |
This was brought up in Matrix, but it might be useful to have some form of manual session management, e.g. |
Yeah the more I've thought about this the more I think that Helix should just provide the primitive capabilities and the user should be able to get Helix to do what it wants either by configuration, environment variables, or command-line flags which could be then be aliased. I think a command line flag that lets you specify commands to run upon starting up would be a good first step, then you could do something like This would at least get us something for power users without too much effort. The next question is the actual implementation of writing the state. I dove into the code to tinker a bit, and it looks like we could theoretically derive So we would define some other struct which contains the bits we actually care about for session storing/saving and would then need a From/Into implementation between the editor struct and this "sub-editor for sessions" struct which then would implement serializable. Then the commands ( I'm pretty new to Rust and VERY new to Helix's codebase, so please let me know if this sounds like a poor solution! Thank you in advance! |
@lytedev That approach sounds reasonable but I'm not a helix maintainer. I'd really like to see session support get added since this is the biggest thing keeping me from fully embracing helix. If the maintainers agree that serializing the Editor object is a good approach, I wouldn't mind working together on this to get it going. |
I don't think these fields should be serialized: count, selected_register, diagnostics, debugger, clipboard_provider, syn_loader, theme_loader, last_theme, theme, status_msg, autoinfo, auto_pairs, idle_timer, and exit_code. |
I took a quick look at what changes might be needed:
|
|
What is the state of this? (When) will this be merged? |
Have you tried looking through the associated issues and PRs? It's going to be merged when the implementation is finished. |
The last linked PR #5608 seems to have been closed and replaced by a new (but not yet linked) PR. Other PRs seem to be closed, many issues are linked. The Github UI is not helpful here 😿 in understanding the overall status of a feature if you are not involved in the development of Helix. That said, I understand that the question might be asking for a status update without much kindness, but on the other hand, the answer doesn't help much in understanding what's going on. The feature is quite large and interrelated with many other features, and so the work is also complicated by the fact that many volunteer developers need to find the energy not only to write the first draft (which is usually fun), but also to refactor and adapt their work to the others (which is less of a Saturday afternoon task). So I guess it's just complicated. Kudos for your work and thanks for |
I have the main changes pushed to a branch, but I've just had a lot going on. |
This comment was marked as spam.
This comment was marked as spam.
I am willing to put a $100 bounty on this feature |
ref #9143 |
it has been 3 years. still no improvement on this feature . |
The features are already implemented in #9143 so you can build that branch and use it if you’re desperate, but it’s not getting merged until buffer switching behaviour is fixed (#7568), and tests, config, and documentation are written because we care about quality more than rushing. If you’re not even willing to put the effort in to check what’s done on the branch, and build it yourself, I don’t think you get to complain that volunteers aren’t implementing fast enough. After all, you could have implemented this yourself anytime in the last 3 years, but you didn’t 🤷♀️. |
I tried Helix two years ago, but I forgot why I gave up on it. Recently, I gave it another try, only to give up again due to the absence of this critical feature. It reminded me that I had abandoned it for the same reason last time. Undo after closing file is incredibly important; even Vim implemented the undofile feature early on because of this necessity. Consider this scenario: you edit a file, save it, then close it or get disconnected via SSH. Later, you realize something is wrong, but you can't remember how the original file looked. You want to recover it, but there's no way to do so. Imagine the frustration you feel at that moment. I apologize for not being a Rust engineer and unable to contribute in that regard. I just want to emphasize how crucial this feature is. I simply want Helix to be better and better. I apologize if my previous comments sounded rude. |
While persistent state would be a nice feature, the problem you're describing would probably be better solved by versioning these files with Git or by using snapshots for example. I would not rely on any editor saved state if keeping the previous versions of files I'm working on is important. |
I agree that persistent undo is something I hope to find there many times after an erroneous quit. But I think it's a different feature maybe? Kudos to all the developers, Helix is very usable even without all these features, but the long tail of quality of live improvements will be faster and easier to implement once the foundation is solid and kept solid by a good process! |
Kirawi and I decided to split the work, so they are working on persistent undo separately from me. You can find their work at #9154. I believe it's in a similar state to mine: The bulk of the work is done, and it's in a usable state, it just needs some polish before it's ready to merge |
I strongly agree with bit about persistent undo being separate. I wouldn't want to sound rude or anything and since I'm just about on the street for devotion to open source, I can understand the limited time of volunteers. But for me personally, this is the one and only reason I haven't switched over to Helix. My experience with other vim editors with swap files was a nightmare. And I have an old laptop that freezes more than I'd like, due to it being the first (and unfortunately) poorly supported Ryzen 5 + AMD. So to have the possibility of losing state due to a freeze is simply unacceptable. Because even though I write to file extremely often, there are occasions where I am working across multiple files and have made multiple decent-sized changes. And it's the worst to have to reimplement at these times (because when it rains it pours effect). So I still tolerate vscode + vscodevim. Fingers crossed that you prioritize this for others like me without the resources to have better hardware! I love the editor though! |
The issue of losing the content of a file on crash during a write was addressed on master via temporary files. It still won't preserve edits though. |
https://github.com/kirawi/helix/tree/undo @kirawi I tried to rebuild this branch , however it did not work. |
Did you enable it in your config? |
no, how ? |
I set it default , and it works now |
Config is handled in |
Yes, the PRs are still in development |
Hi, I don't need some fancy undo session feature. Can helix remember cursor position after quit now? Thanks a lot. |
Thanks a lot for the info. I just use the release binary. Is this included in the latest release? I am not sure how to check this and can NOT find this config option in the doc either. |
It is not, the PR hasn’t been merged. I fixed the issue that was blocking it, but I still need to rebase, polish it a bit, write documentation, and get it reviewed before it can be merged. Then it will be included in the next release after the merge. Given all that, I expect it won’t be in a release for at least another few months (likely a year or so). If the feature is a priority for you though (as it is for me) that branch is stable; I daily drive it with no issues. |
Heads up for those using a build of #9143: I changed the format of the config options, so you will need to change your config when you update. The new format is like so:
|
This feature will allow you to share the same file history between sessions, and could help in situations where the editor crashes. #290 #294
The text was updated successfully, but these errors were encountered: