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:
parent
e9c088cf3b
commit
c309e61eff
2 changed files with 24 additions and 1 deletions
|
@ -12,3 +12,24 @@
|
||||||
"Open an ibuffer window for the current workspace"
|
"Open an ibuffer window for the current workspace"
|
||||||
(interactive)
|
(interactive)
|
||||||
(+ibuffer-workspace (+workspace-current-name)))
|
(+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))))
|
||||||
|
|
|
@ -44,7 +44,9 @@
|
||||||
"Filter for workspace buffers"
|
"Filter for workspace buffers"
|
||||||
(:reader (+workspace-get (read-string "workspace name: "))
|
(:reader (+workspace-get (read-string "workspace name: "))
|
||||||
:description "workspace")
|
:description "workspace")
|
||||||
(memq buf (+workspace-buffer-list qualifier))))
|
(memq buf (+workspace-buffer-list qualifier)))
|
||||||
|
|
||||||
|
(define-key ibuffer-mode-map [remap ibuffer-visit-buffer] #'+ibuffer/visit-workspace-buffer))
|
||||||
|
|
||||||
(when (featurep! :completion ivy)
|
(when (featurep! :completion ivy)
|
||||||
(defadvice! +ibuffer--use-counsel-maybe-a (_file &optional _wildcards)
|
(defadvice! +ibuffer--use-counsel-maybe-a (_file &optional _wildcards)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue