Skip to content
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

Open
jdtsmith opened this issue Feb 22, 2024 · 4 comments
Open
Labels
enhancement New feature or request
Milestone

Comments

@jdtsmith
Copy link
Contributor

jdtsmith commented Feb 22, 2024

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, and revert 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 for soft-revert? Or a separate (lesser used) command? Or an option (I would pretty much always prefer for point in opened buffers to remain unchanged)?

@alphapapa
Copy link
Owner

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.

@alphapapa alphapapa added the enhancement New feature or request label Feb 22, 2024
@alphapapa alphapapa added this to the Future milestone Feb 22, 2024
@jdtsmith
Copy link
Contributor Author

jdtsmith commented Feb 24, 2024

Could you perhaps take the default activity state, compare any buffers it contains to (buffer-list), and if any are found in common, create a new "lightly modified default" activity state which is a copy[1] of the true default? Then, in this new state, bookmark-set-position on the relevant bookmarks to match the (window-)point of their already-active buffer(s), and load this "mostly default" state, just as normal.

[1] Or at least the relevant bookmarks are copied

@alphapapa
Copy link
Owner

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.

@jdtsmith
Copy link
Contributor Author

jdtsmith commented May 21, 2024

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)))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants