Files
doomemacs/modules/emacs/ibuffer/autoload/workspaces.el
Henrik Lissner 0a715cc3f2 refactor: (if|when)-let -> (if|when)-let*
With the former macros' future in the air (and likely to be targeted in
future, potentially breaking changes), I'll deal with this now than have
it bite me later.

Ref: https://lists.gnu.org/archive/html/emacs-devel/2024-10/msg00637.html
2025-01-08 19:33:37 -05:00

35 lines
1.3 KiB
EmacsLisp

;;; emacs/ibuffer/autoload/workspaces.el -*- lexical-binding: t; -*-
;;;###if (modulep! :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)))
(unless (buffer-live-p buf)
(user-error "Not a valid or live buffer: %s" buf))
(if-let* ((workspaces
(cl-loop for wk in (+workspace-list)
if (+workspace-contains-buffer-p buf wk)
collect wk)))
(+workspace-switch
(if (and (not select-first) (cdr workspaces))
(or (completing-read "Select workspace: " (mapcar #'persp-name workspaces))
(user-error "Aborted"))
(persp-name (car workspaces))))
;; Or add the buffer to the current workspace
(persp-add-buffer buf))
(switch-to-buffer buf)))