doomemacs/modules/emacs/ibuffer/autoload/workspaces.el
Henrik Lissner c309e61eff
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>
2022-04-03 20:51:54 +02:00

35 lines
1.4 KiB
EmacsLisp

;;; emacs/ibuffer/autoload/workspaces.el -*- lexical-binding: t; -*-
;;;###if (featurep! :ui workspaces)
;;;###autoload
(defun +ibuffer-workspace (workspace-name)
"Open an ibuffer window for a workspace"
(ibuffer nil (format "%s buffers" workspace-name)
(list (cons 'workspace-buffers (+workspace-get workspace-name)))))
;;;###autoload
(defun +ibuffer/open-for-current-workspace ()
"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))))