evil
evil copied to clipboard
Marks are not persisted between sessions
Originally reported by: César Antáres (Bitbucket: ZzAntares, GitHub: ZzAntares)
Perhaps there is a setting that should be turned on but in vim, setting a local mark will be persisted so the next session you use vim you can jump to previously set marks.
Example
Open a medium sized file in vim and set a mark 50%ma, close vim, reopen vim using same file as before and visit mark using 'a it finds the previously set mark. Do the same thing with evil and it gives Marker 'a' is not set in this buffer.
Info
- GNU Emacs 24.5.1 (x86_64-apple-darwin15.4.0, Carbon Version 157 AppKit 1404.46)
- Evil version 1.2.12
- I use both emacs on terminal and on X (depends on my mood)
- Bitbucket: https://bitbucket.org/lyro/evil/issue/674
Original comment by VanLaser (Bitbucket: VanLaser, GitHub: VanLaser):
Also the saveplace package might help (it remembers last cursor position, for any file, and restores it when the file is revisited) so it's close to this use case.
Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):
You may have a look at the recentf package (part of Emacs) how they implemented persistence storage.
Original comment by César Antáres (Bitbucket: ZzAntares, GitHub: ZzAntares):
Ok thanks I thought maybe there was a secret option to turn this feature on.
If you could point me in the right direction I could try to write such patch, though I'm just learning elisp so I'll no count on that.
Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):
Of course this does not work because marks are never stored in file, that's just not implemented (yet) ;)
It should certainly be doable and not be too difficult. We are just waiting for someone to provide a patch ... ;)
desktop.el users can do (add-to-list 'desktop-locals-to-save 'evil-markers-alist) or (cl-pushnew 'evil-markers-alist desktop-locals-to-save).
Note that I believe that this works for local markers but does not work for global markers because the global markers will be loaded before any buffer has been opened. There appears to be some attempt to defer this loading by desktop.el but it doesn't appear to be enough.
; .emacs.desktop
(setq evil-markers-alist (list
'(40 . evil-backward-sentence)
'(41 . evil-forward-sentence)
'(123 . evil-backward-paragraph)
'(125 . evil-forward-paragraph)
'(39 . evil-jump-backward-swap)
'(96 . evil-jump-backward-swap)
'(60 . evil-visual-beginning)
'(62 . evil-visual-goto-end)
'(46 lambda () (let (last-command) (goto-last-change nil)))
(desktop-list* 114 (let ((mk (make-marker)))
(add-hook 'desktop-delay-hook
`(lambda () (set-marker ,mk ,128 (get-buffer ,"game.rs"))))
mk))))
Any updates?
The best solution, IMO, is to store the marks in _{original_file_name}.evilmarks as JSON (or sth).
Using packages that periodically save and load variables doesn't work well when two emacs sessions are running simultaneously, but just writing each mark into the file as it is created by the user will not have a conflict with simultaneous emacs sessions.
I have tried persisting both the local and the global marks across multiple emacs sessions. The code seems to work, but I am not sure if it is secure.
@NightMachinery nice work! If you want to make a PR to evil, I'd be happy to put it behind a feature flag and test it myself for a while. What sort of security concerns do you have?
@tomdl89 Thanks! I have a conference deadline in a month, but I can make a PR after that. It would also make for a good testing period anyway.
I use read to read the data from the storage files (written using prin1). I am not sure if that is secure. I tried switching to JSON, but the LLMs failed badly in doing that, which means I have to do that myself. In general, the code was mostly put together using LLMs, and I did not check for security problems extensively.
@tomdl89 I have been testing my persistence code, and one rather annoying issue is with serializing the markers. I am currently storing them as points:
((97 "/Users/evar/tmp/tmp.org" . 6) (122 "/Users/evar/tmp/tmp.org" . 1))
These pointers are often wrong in org-mode files where I run babel code cells which produce a lot of output.
But I guess I need to store them like bookmarks:
("timetracker.py"
(filename . ".../timetracker.py")
(front-context-string . "\",\n \"lw\": \"wa")
(rear-context-string . "e_forums_twitter")
(position . 2444))
Any feedback on the best way to proceed?