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

Prevent buffers from being added to several perspectives #164

Open
deb75 opened this issue Sep 22, 2021 · 8 comments
Open

Prevent buffers from being added to several perspectives #164

deb75 opened this issue Sep 22, 2021 · 8 comments
Labels

Comments

@deb75
Copy link

deb75 commented Sep 22, 2021

Hello,

I have just begun to use perspective, perhaps this question is just due to my lack of practice.

Sometimes when I switch from one perspective to another, I notice with persp-ibuffer that some buffers
from previous perspective do appear in the current one, although I did not want to add thess buffers to the
current perspective.

How can I make sure that buffers (files) belonging to one perspective will not mix with other perspectives.
As for now, i have to issue C-x x A all the time. Is there any settings to do this once for all ?

Regards

@gcv
Copy link
Collaborator

gcv commented Sep 22, 2021

Perspective always adds a buffer to the current perspective when the buffer is displayed. Meaning, if you switch to a buffer which is not in the current perspective, it will then be added to the current perspective. This also happens if you use a previewing buffer switcher like counsel-switch-buffer, which can be unexpected and the reason why Perspective provides persp-counsel-switch-buffer as a replacement.

If you're absolutely certain that buffers are being added to the current perspective even though you did not at any point display them, then that's a bug and I'll need a test case reproducible with emacs -Q -l /path/to/perspective.el --eval '(persp-mode)'.

@deb75
Copy link
Author

deb75 commented Sep 22, 2021

Thanks for your answeer.

For example, if I kill a buffer in a given perspective, another buffer will be automatically displayed which may belong to another perspective. Then, this buffer is unexpectedly added to the current perspective.

Reading what you say, it does not seem to be a bug. But, I wish it could be prevented. Is there a way to prevent any displayed buffer from being automatically added ?

Regards

@gcv
Copy link
Collaborator

gcv commented Sep 23, 2021

The behavior you’re describing, i.e., pulling in a buffer from a different perspective after killing a buffer, should not happen. A series of bugs did cause it to occur in rare situations, but I fixed all the ones I knew about quite a long time ago. If it happens to you regularly, that’s definitely a bug and needs to be investigated.

What version of Perspective do you have installed? Also, could you please double-check that you have Perspective installed, and not the persp-mode fork?

@deb75
Copy link
Author

deb75 commented Sep 23, 2021

Yes I am sure it is perspective, latest melpa version, not persp-mode.

Let's say I start from a clean perspective "state", that is to say all buffers are in the correct perspective (checking with persp-ibuffer).

Then, I start gnus in the main perspective which has no opened buffer, apart from the scratch. When I close gnus, emacs displays automatically one of the opened buffers, which is then added to the main perspective.

I think I can reproduce this quite well. Also, following on this example, if I try to close the unexpected buffer in the main perspective with C-x x k, emacs again drops another buffer which is again unexpectedly added to the main perspective.

Regards

EDIT : emacs 28.0.50 mingw64 / windows 10

@gcv
Copy link
Collaborator

gcv commented Sep 23, 2021

I want to get to the bottom of this, but I can't reproduce it on Emacs 27.2. Here is a scripted test case. To run it, launch Emacs like this:

/path/to/emacs -Q -l /path/to/perspective-el/perspective.el --eval '(persp-mode)'

This will start Emacs with no custom configurations which may interfere, but will activate Perspective.

Next, save the following code to a file called test-script.el somewhere:

(setq backup-inhibited t)
(setq auto-save-default nil)

(require 'ibuffer)
(global-set-key (kbd "C-x C-b") #'persp-ibuffer)

(persp-switch "one")
(find-file "/tmp/persp-one-file-1.txt")
(insert "persp: one\nfile 1\n")
(persp-switch "two")
(find-file "/tmp/persp-two-file-2.txt")
(insert "persp: two\nfile 2\n")
(persp-switch "three")
(gnus nil t)

Since you use Windows, you may have to change the find-file lines to point to different file paths since I don't know if /tmp will mean anything to Emacs on Windows.

Load this file: press M-: and then run (load-file "/path/to/test-script.el")

(This script also binds C-x C-b to persp-ibuffer for ease of testing.)

Now you should be looking at an empty Gnus buffer. At this point, whether I hit q or C-x k to exit Gnus, the buffer which pops up is *scratch* (three), exactly as expected, and not any buffer from the other two perspectives.

  1. What happens when you run this test?
  2. What happens if you try Emacs 27.2 instead of 28? I don't run unreleased versions of Emacs, but am willing to fix bugs introduced by them when reported.
  3. If all this works as expected, please modify the provided test script until you can consistently reproduce the problem so I can reproduce it myself.

@deb75
Copy link
Author

deb75 commented Sep 23, 2021

Hi,

Run your test, which is ok. Perhaps something in my configuration. I will look into this.

Regards

@gcv gcv added the bug label Nov 2, 2021
@gcv
Copy link
Collaborator

gcv commented Nov 22, 2021

@deb75: Please grab the latest Perspective from MELPA and set persp-feature-flag-prevent-killing-last-buffer-in-perspective to t, either in the :custom section of your use-package form or with this:

(customize-set-variable 'persp-feature-flag-prevent-killing-last-buffer-in-perspective t)

Then restart Emacs.

There's a lot of new code there to try to keep this problem from happening in the edge case of killing the last buffer in a perspective affecting other perspectives.

@deb75
Copy link
Author

deb75 commented Nov 22, 2021

Thanks a lot for coping with this issue which was preventing me from using perspective.

I will give it a try as soon as I can and, let you know if the issue persists.

Regards

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

No branches or pull requests

2 participants