-
Notifications
You must be signed in to change notification settings - Fork 15
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
Idea: "soft-revert" activity without changing point(s) in open buffers #41
Comments
That's a nice idea. I'd probably use it myself sometimes. I'm not sure how easy it would be to implement, because each buffer's bookmark restores its position, so we'd have to probably map across all buffers and save their point positions, then restore the ones in the visible buffers after reverting the activity. A little messy but probably doable. |
Could you perhaps take the default activity state, compare any buffers it contains to [1] Or at least the relevant bookmarks are copied |
Something like that would probably work most of the time, but doing so would mean using a heuristic to determine which live buffer is equivalent to the one in the saved state (since the bookmark would not be jumped to first), and that could potentially not work as desired, e.g. if a different buffer had the same name. Another complication is that each bookmark handler function is opaque: How it decides which buffer to switch to and/or create is up to its implementation; the only thing that matters is that when it returns, the current buffer is the one its record is jumping to. So it's not technically possible for us to know whether the buffer we guess is equivalent is the one the bookmark would have jumped to. It might work to copy the state and its bookmark records, and remove the position information from them, and then allow them to be jumped to normally, hoping that the handler function would leave the buffer's point alone. But, again, whether that works would depend on each handler function's implementation. I can think of some of my own that recreate the buffer's contents from scratch, erasing it first, and make no effort to save the point position if the buffer already exists, so I don't think we could count on that behavior. |
In case anyone is interested in this functionality, I implemented the following and bound it to my revert key. Works well. (defun my/activities-soft-revert ()
"Revert, then restore point and window start for formerly visible buffers."
(interactive)
(let ((old (cl-loop for win in (window-list)
collect (list (window-buffer win)
(window-point win)
(window-start win)))))
(call-interactively #'activities-revert)
(run-at-time 0 nil
(lambda ()
(cl-loop
for win in (window-list)
with selected = (selected-window)
for buf = (window-buffer win)
for rec = (alist-get buf old)
if rec do
(if (eq win selected) (goto-char (car rec))
(set-window-point win (car rec)))
(set-window-start win (cadr rec))))))) |
My favorite feature of activities is the ability to
revert
at any time, always there to save you when your activity has "gotten away from you", and you've introduced new or extraneous windows and buffers into the mix, or drifted away. But usually this comes from opening other windows I no longer need, andrevert
is just a quick way to sweep those away and restore my window/buffer setup.In that case, I'd prefer for the current point in each of the already displayed buffers to be left unchanged — a "soft-revert" if you will. Soft revert is basically just like normal revert, except point is left alone (for already visited buffers, that is). Perhaps a prefix arg to
revert
would be a good interface forsoft-revert
? Or a separate (lesser used) command? Or an option (I would pretty much always prefer for point in opened buffers to remain unchanged)?The text was updated successfully, but these errors were encountered: