From 2896acc6bded7660db667bde2101d93d778c241a Mon Sep 17 00:00:00 2001 From: Matthew White Date: Fri, 30 Jul 2021 21:19:41 +0000 Subject: persp-set-buffer: use BUFFER-OR-NAME as argument, discard killed Follow the style used for 'persp-add-buffer'. BUFFER-OR-NAME is a standard name for an argument that could either be a buffer or the buffer's name. The logic of the function remains unchanged except that a killed buffer passed as argument is discarded now. --- CHANGELOG.md | 5 +++++ perspective.el | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 241bcce..0760595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `persp-get-buffers`: get any perspective's list of buffers. +### Changed + +- `persp-set-buffer`: follow the coding style of `persp-add-buffer`. + + ### Fixed - `persp-add-buffer`: discard unexisting buffer as argument. diff --git a/perspective.el b/perspective.el index 9cdb23a..69e2b19 100644 --- a/perspective.el +++ b/perspective.el @@ -791,19 +791,20 @@ See also `persp-switch' and `persp-remove-buffer'." (unless (persp-is-current-buffer buffer) (push buffer (persp-current-buffers)))))) -(defun persp-set-buffer (buffer-name) - "Associate BUFFER-NAME with the current perspective and remove it from any other." +(defun persp-set-buffer (buffer-or-name) + "Associate BUFFER-OR-NAME with the current perspective and remove it from any other." (interactive (list (let ((read-buffer-function nil)) (read-buffer "Set buffer to perspective: ")))) - (cond ((get-buffer buffer-name) - (persp-add-buffer buffer-name) - (cl-loop for other-persp = (persp-buffer-in-other-p (get-buffer buffer-name)) - while other-persp - do (with-perspective (cdr other-persp) - (persp-remove-buffer buffer-name)))) - (t (message "buffer %s doesn't exist" buffer-name)))) + (let ((buffer (get-buffer buffer-or-name))) + (if (not (buffer-live-p buffer)) + (message "buffer %s doesn't exist" buffer-or-name) + (persp-add-buffer buffer) + (cl-loop for other-persp = (persp-buffer-in-other-p buffer) + while other-persp + do (with-perspective (cdr other-persp) + (persp-remove-buffer buffer)))))) (cl-defun persp-buffer-in-other-p (buffer) "Returns nil if BUFFER is only in the current perspective. -- cgit v1.0