diff options
| author | Matthew White <mehw.is.me@inventati.org> | 2021-07-30 21:19:41 +0000 |
|---|---|---|
| committer | Matthew White <mehw.is.me@inventati.org> | 2021-10-20 23:01:53 +0200 |
| commit | 2896acc6bded7660db667bde2101d93d778c241a (patch) | |
| tree | 35072a36c7424db1a1e8cd5fa91b13c97c9d4150 | |
| parent | 8b1d213178e5a83d7c6d5424d99abd6928c6640f (diff) | |
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.
| -rw-r--r-- | CHANGELOG.md | 5 | ||||
| -rw-r--r-- | 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. |
