alphapapa / activities.el

Activities for Emacs (suspend and resume activities, i.e. frames/tabs and their windows, buffers)
GNU General Public License v3.0
205 stars 12 forks source link

Point moves unexpectedly in buffers shared between activity tabs #120

Open danielcmccarthy opened 2 weeks ago

danielcmccarthy commented 2 weeks ago

When I have a buffer visible in multiple activity tabs, I've noticed that if I jump to the beginning of the buffer in one tab and wait a second, point will move to where it was in the previous activity. I was able to reproduce it with emacs -q:

  1. Create two activities, "thing 1" and "thing 2", both visiting the same file, e.g. etc/NEWS
  2. In thing 2, M->
  3. Switch to thing 1, do M-<, and wait a second. Point will jump to the position you left it at in thing 2.

It doesn't happen if activities-tabs-mode is disabled, and it doesn't happen unless point is at the beginning of the buffer.

Thanks for making this package!

alphapapa commented 2 weeks ago

Hi Daniel,

You seem to have found a behavior I've noticed myself but couldn't quite put my finger on. I think this is related to the fact that, while buffers have points, windows also have their own points, and moving one does not necessarily move the other; so if the same buffer is in two windows, there may be some conflict.

It may also be relevant what the buffer's major mode is, and possibly its bookmark make-record function. Have you noticed any pattern related to what mode the buffer is in?

OTOH it may not have anything to do with the mode and bookmark function. It might be simply that, when the activities are automatically saved, and the other activity is switched to (which happens invisibly), and the other window showing that buffer becomes visible, the window point is moved, or something like that. So maybe we could solve that by preserving the original window point, or something like that.

Thanks for reporting this.

danielcmccarthy commented 2 weeks ago

I stumbled on this with a work journal in diary-mode. But I was able to reproduce it just now with /etc/NEWS in fundamental-mode, too.

I was curious about window points, so I tried a new test. After moving to the beginning of the buffer, but before the activity timer went off, I evaluated:

(set-window-point (selected-window) 1)

But that didn't help.

On Thu, Sep 26, 2024 at 11:32 AM Adam Porter @.***> wrote:

Hi Daniel,

You seem to have found a behavior I've noticed myself but couldn't quite put my finger on. I think this is related to the fact that, while buffers have points, windows also have their own points, and moving one does not necessarily move the other; so if the same buffer is in two windows, there may be some conflict.

It may also be relevant what the buffer's major mode is, and possibly its bookmark make-record function. Have you noticed any pattern related to what mode the buffer is in?

OTOH it may not have anything to do with the mode and bookmark function. It might be simply that, when the activities are automatically saved, and the other activity is switched to (which happens invisibly), and the other window showing that buffer becomes visible, the window point is moved, or something like that. So maybe we could solve that by preserving the original window point, or something like that.

Thanks for reporting this.

— Reply to this email directly, view it on GitHub https://github.com/alphapapa/activities.el/issues/120#issuecomment-2377304607, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIXLZODSAAFDAHQBSWAOQLZYQSKNAVCNFSM6AAAAABO436OGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZXGMYDINRQG4 . You are receiving this because you authored the thread.Message ID: @.***>

alphapapa commented 2 weeks ago

@danielcmccarthy Please install from this branch and let me know if it fixes the problem for you: https://github.com/alphapapa/activities.el/compare/wip/fix-120-window-point

danielcmccarthy commented 1 week ago

That fixes the sudden jumping after M-<. But now point moves when I switch from thing 1 to thing 2, then back. It looks like that happens on master, too; I don't think I noticed that before.

alphapapa commented 1 week ago

But now point moves when I switch from thing 1 to thing 2, then back. It looks like that happens on master, too; I don't think I noticed that before.

Sorry, I don't understand what you mean.

danielcmccarthy commented 1 week ago

Sorry, let me try again. With two activity tabs viewing the same buffer:

  1. In A1, set point anywhere except the beginning.
  2. in A2, go to the beginning.
  3. Switch to A1, then back to A2. A2's point will now be what it was in A1.

Let me know if you'd like me to try anything else.

alphapapa commented 1 week ago

It would help to have a bit more detail. I feel like step 3 there omits some information. For example, after each switch, please say where the point is. And please say how much time elapsed between each step (i.e. whether the activity-save timer would have activated between the steps).

danielcmccarthy commented 1 week ago

In step 1, before switching away from A1, point was at the end of the buffer. But I also tried the steps starting with a random place picked with the mouse and got the same behavior. I didn't wait long before switching, maybe a second or two.

Step 2: after moving to the buffer beginning I waited about 5 seconds, long enough to confirm that the original problem wasn't happening anymore.

Step 3: when switching to A1, A2's point was at the beginning of the buffer; A1's point was wherever I left it in step 1. When switching back to A2, A1's point is unchanged, but A2 now has the point value from A1.

I see now that activities-mode-idle-frequency is 5s, so I tried again waiting 20s between step 2 and 3. No change.

alphapapa commented 1 week ago

I'm sorry if I seem demanding, but would you mind writing out those steps with all of the details in a single list? Having to reconcile the steps from one comment and the details from another is a bit confusing, and these details are vital.

danielcmccarthy commented 1 week ago

No problem:

  1. With activities-tabs-mode enabled, create two activities, A1 and A2, both viewing the same buffer.
  2. In A1, set point to the end of the buffer with M->.
  3. Switch to A2. Set point to the beginning of the buffer with M-<. Wait 10 seconds.
  4. Switch to A1. Point is at the end of the buffer, where we left it. (I tried waiting another 10s here, but it didn't change anything.)
  5. Switch to A2. Point has moved to end-of-buffer: oops.

If A2's point is anywhere other than buffer-beginning, the test behaves as expected. The buffer doesn't seem to matter; I've reproduced this with *scratch*, etc/NEWS, and a text file in fundamental-mode.

I switched between activities by clicking on the the tab bar, rather than a key sequence, in case that matters.