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

Workaround for switch buffer? #8

Open
JordanAnthonyKing opened this issue Dec 5, 2024 · 9 comments
Open

Workaround for switch buffer? #8

JordanAnthonyKing opened this issue Dec 5, 2024 · 9 comments

Comments

@JordanAnthonyKing
Copy link

If you have two windows open, and a buffer was previously opened in one of them, when you switch to that buffer instead of opening in the current window it will be opened in the window it was open in previously and focus will be shifted to that window. Is there a workaround for this?

@FrostyX
Copy link
Owner

FrostyX commented Dec 5, 2024

Hello @JordanAnthonyKing, thank you for the report. I am not 100% sure that I understand correctly, so let me write a step-by-step how I tried to reproduce this, and please confirm that it is correct, or tell me what I am doing wrong.

  1. I vertically split an Emacs frame so that I have two windows
  2. I focus the left window and use M-x switch-to-buffer to select a buffer named foo
  3. I focus the right window and use M-x switch-to-buffer to select a buffer named bar
  4. I remain in the right window and use M-x switch-to-buffer to select a buffer named foo (which is already visible in the left window)

What you expect to happen:
Both windows should show the same foo buffer and your focus should remain in the current window
(this exactly happens to me btw)

What I understand, happens for you:
Your focus is changed to the left window, while the right window still shows the bar buffer?

@JordanAnthonyKing
Copy link
Author

JordanAnthonyKing commented Dec 5, 2024

Apologies, I reenabled this package today and I'm not seeing that behaviour anymore. That said, is there a workaround for switch-to-buffer-other-window?

@FrostyX
Copy link
Owner

FrostyX commented Dec 5, 2024

Apologies, I reenabled this package today and I'm not seeing that behaviour anymore.

Ok, nice.

That said, is there a workaround for switch-to-buffer-other-window?

Depends on how it behaves for you now and what do you want it to do. When current-window-only-mode is enabled, then doing M-x switch-to-buffer-other-window and selecting a buffer should open the buffer in the current window, not the other window. And at least for me, it works like that.

@JordanAnthonyKing
Copy link
Author

Yes that's how it works for me but I'd like it to retain its old behaviour. Maybe advise those functions to quickly disable and reenable the mode?

@FrostyX
Copy link
Owner

FrostyX commented Dec 6, 2024

I see. You can try this:

(defun switch-to-buffer-other-window-force ()
  (interactive)
  (let ((override #'current-window-only--switch-to-buffer-other-window))
    (advice-remove 'switch-to-buffer-other-window override)
    (call-interactively #'switch-to-buffer-other-window)
    (advice-add 'switch-to-buffer-other-window :override override)))

This should work for your use-case. The implementation probably could be easier but I am too big a of an Emacs Lisp noob for that.

Can you please test, so that I can then recommend this workaround in
https://github.com/FrostyX/current-window-only/tree/main?tab=readme-ov-file#tips-and-tricks

@JordanAnthonyKing
Copy link
Author

What I understand, happens for you: Your focus is changed to the left window, while the right window still shows the bar buffer?

Apologies, I am now observing this behaviour again, but it's "randomly" started after a prolonged period messing about. Is there any info I can provide you with to help pin this down?

@FrostyX
Copy link
Owner

FrostyX commented Dec 9, 2024

I have no idea how that can happen. AFAIK by default switch-to-buffer always open buffers in the current window, even if they are opened elsewhere. At least when I use my minimal (Evil enabled) config, it behaves this way.
https://github.com/frostyx/dotfiles/blob/master/.emacs.d/minimal.el

Is it possible you have some other package enabled, that modifies the behavior?

@JordanAnthonyKing
Copy link
Author

Okay, it seems to happen only when that buffer is visible in the other window, does that help narrow it down?

@FrostyX
Copy link
Owner

FrostyX commented Dec 10, 2024

Not really, that what I've been trying from the beginning as described in #8 (comment)

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

No branches or pull requests

2 participants