perspective-el
perspective-el copied to clipboard
Prevent buffers from being added to several perspectives
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
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)'
.
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
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?
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
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.
- What happens when you run this test?
- 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.
- 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.
Hi,
Run your test, which is ok. Perhaps something in my configuration. I will look into this.
Regards
@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.
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
This should have been fixed with all the changes from 2021.