feat(ibuffer): switch to buffer in its workspace

Adds +ibuffer/visit-workspace-buffer, which will switch to a buffer's
containing workspace before switching to the buffer. This will prompt if
a buffer is present in multiple workspaces. If given the prefix
argument, it will auto-select the first workspace.

Fix: #5061
Close: #5351
Co-authored-by: petr-tik <petr-tik@users.noreply.github.com>
This commit is contained in:
Henrik Lissner 2022-04-03 20:41:03 +02:00
parent e9c088cf3b
commit c309e61eff
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 24 additions and 1 deletions

View file

@ -12,3 +12,24 @@
"Open an ibuffer window for the current workspace"
(interactive)
(+ibuffer-workspace (+workspace-current-name)))
;;;###autoload
(defun +ibuffer/visit-workspace-buffer (&optional select-first)
"Visit buffer, but switch to its workspace if it exists."
(interactive "P")
(let ((buf (ibuffer-current-buffer t)))
(if (not (buffer-live-p buf))
(user-error "Not a valid or live buffer: %s" buf)
(when-let (workspaces
(cl-loop for wk in (+workspace-list)
if (+workspace-contains-buffer-p buf wk)
collect wk))
(+workspace-switch
(persp-name
(if (and (not select-first) (cdr workspaces))
(+workspace-get
(or (completing-read "Select workspace: " (mapcar #'persp-name workspaces))
(user-error "Aborted")))
(car workspaces)))))
(persp-add-buffer buf) ; then add the buffer to the current workspace
(switch-to-buffer buf))))