aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConstantine Vetoshev <vetoshev@gmail.com>2026-03-29 08:04:49 -0700
committerConstantine Vetoshev <vetoshev@gmail.com>2026-03-29 08:08:59 -0700
commit0e632bb8482f94f45a7b1209bb2bd38aadf84003 (patch)
treebc4f2e0da2eadedf9506c2bb40627047cb85f867
parent64ef5eaaab9e7564e8b9788ce6d0e2359daf5dca (diff)
Fix consult preview importing buffers into perspectives.
-rw-r--r--CHANGELOG.md7
-rw-r--r--perspective.el25
-rw-r--r--test/test-perspective.el17
3 files changed, 42 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c32aece..a69daa0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,13 @@ Perspective was started in 2008 and this log was only added in 2021.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
+## Unreleased
+
+### Fixed
+
+- Temporary `switch-to-buffer` displays with non-nil `norecord` no longer add the displayed buffer to the current perspective. This fixes `consult-buffer` preview importing previewed buffers ([#225](https://github.com/nex3/perspective-el/issues/225)).
+
+
## [2.21] — 2026-02-10
### Fixed
diff --git a/perspective.el b/perspective.el
index cd98bd6..04fdbc0 100644
--- a/perspective.el
+++ b/perspective.el
@@ -507,6 +507,11 @@ FRAME defaults to the currently selected frame."
"Whether a perspective error should cause persp-mode to be disabled.
Dynamically bound by `persp-protect'.")
+(defvar persp--inhibit-buffer-association nil
+ "When non-nil, suppress automatic association of displayed buffers.
+Dynamically bound around temporary buffer displays, such as
+`switch-to-buffer' calls with non-nil NORECORD.")
+
(defface persp-selected-face
'((t (:weight bold :foreground "Blue")))
"The face used to highlight the current perspective on the modeline.")
@@ -1319,21 +1324,26 @@ is non-nil or with prefix arg, don't switch to the new perspective."
(persp-update-modestring)
(persp-activate persp))))
-(defadvice switch-to-buffer (after persp-add-buffer-adv)
+(defadvice switch-to-buffer (around persp-add-buffer-adv)
"Add BUFFER to the current perspective.
See also `persp-add-buffer'."
- (persp-protect
- (let ((buf (ad-get-arg 0)))
- (when buf
- (persp-add-buffer buf)))))
+ (let ((persp--inhibit-buffer-association
+ (or persp--inhibit-buffer-association
+ (ad-get-arg 1))))
+ ad-do-it
+ (persp-protect
+ (let ((buf (ad-get-arg 0)))
+ (when (and buf (not persp--inhibit-buffer-association))
+ (persp-add-buffer buf))))))
(defadvice display-buffer (after persp-add-buffer-adv)
"Add BUFFER to the perspective for the frame on which it's displayed.
See also `persp-add-buffer'."
(persp-protect
- (when ad-return-value
+ (when (and ad-return-value
+ (not persp--inhibit-buffer-association))
(let ((buf (ad-get-arg 0))
(frame (window-frame ad-return-value)))
(when (and buf frame)
@@ -1347,7 +1357,8 @@ See also `persp-add-buffer'."
(persp-protect
(let ((buf (ad-get-arg 1))
(frame (window-frame (ad-get-arg 0))))
- (when (and buf frame)
+ (when (and buf frame
+ (not persp--inhibit-buffer-association))
(with-selected-frame frame
(persp-add-buffer buf))))))
diff --git a/test/test-perspective.el b/test/test-perspective.el
index 20fd38c..6c55ca5 100644
--- a/test/test-perspective.el
+++ b/test/test-perspective.el
@@ -2113,6 +2113,23 @@ buffers into any perspective."
(should (kill-buffer "*dummy*"))
(should-not (get-buffer "*dummy*"))))
+(ert-deftest basic-switch-to-buffer-norecord-does-not-add-buffer ()
+ "Test that temporary `switch-to-buffer' displays do not add buffers."
+ (persp-test-with-persp
+ (let ((dummy-buffer (get-buffer-create "*dummy*")))
+ (persp-switch "A")
+ (switch-to-buffer dummy-buffer)
+ (should (persp-test-buffer-in-persps dummy-buffer "A"))
+ (persp-switch "main")
+ (should-not (persp-is-current-buffer dummy-buffer))
+ ;; `consult--buffer-state' previews use `switch-to-buffer' with
+ ;; NORECORD non-nil. That should not associate the buffer with
+ ;; the current perspective.
+ (switch-to-buffer dummy-buffer t)
+ (should (eq (current-buffer) dummy-buffer))
+ (should-not (persp-is-current-buffer dummy-buffer))
+ (should (persp-test-buffer-in-persps dummy-buffer "A")))))
+
(defmacro persp-test-make-sample-environment ()
"Make a test environment with the following window layout: