2021-07-09 20:16:11 +03:00
|
|
|
;;; completion/vertico/autoload/workspaces.el -*- lexical-binding: t; -*-
|
2021-05-21 16:38:54 +03:00
|
|
|
;;;###if (featurep! :ui workspaces)
|
|
|
|
|
|
|
|
;;;###autoload
|
2021-07-09 20:28:40 +03:00
|
|
|
(defun +vertico--workspace-nth-source (n)
|
2021-05-21 16:38:54 +03:00
|
|
|
"Generate a consult buffer source for buffers in the NTH workspace"
|
|
|
|
(cond ((numberp n)
|
2021-05-23 10:54:50 +03:00
|
|
|
`(:name ,(nth n (+workspace-list-names))
|
|
|
|
:hidden ,(not (string= (+workspace-current-name) (nth n (+workspace-list-names))))
|
|
|
|
:narrow ,(string-to-char (number-to-string (1+ n)))
|
2021-05-21 16:38:54 +03:00
|
|
|
:category buffer
|
|
|
|
:state ,#'consult--buffer-state
|
2021-09-21 17:57:50 +03:00
|
|
|
:items ,(lambda ()
|
|
|
|
(consult--buffer-query
|
|
|
|
:sort 'visibility
|
|
|
|
:as #'buffer-name
|
|
|
|
:predicate (lambda (buf)
|
|
|
|
(+workspace-contains-buffer-p
|
|
|
|
buf
|
|
|
|
(nth n (+workspace-list))))))))
|
2021-05-21 16:38:54 +03:00
|
|
|
((eq n 'final)
|
|
|
|
`(:name ,(car (last (+workspace-list-names)))
|
|
|
|
:hidden t
|
|
|
|
:narrow ?0
|
|
|
|
:category buffer
|
|
|
|
:state ,#'consult--buffer-state
|
2021-09-21 17:57:50 +03:00
|
|
|
:items ,(lambda ()
|
|
|
|
(consult--buffer-query
|
|
|
|
:sort 'visibility
|
|
|
|
:as #'buffer-name
|
|
|
|
:predicate (lambda (buf)
|
|
|
|
(+workspace-contains-buffer-p
|
|
|
|
buf
|
|
|
|
(car (last (+workspace-list)))))))))
|
2021-05-21 16:38:54 +03:00
|
|
|
(t
|
|
|
|
(user-error "invalid workspace source %s" n))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2021-07-09 20:28:40 +03:00
|
|
|
(defun +vertico--workspace-generate-sources ()
|
2021-05-21 16:38:54 +03:00
|
|
|
"Generate list of consult buffer sources for all workspaces"
|
2021-07-09 20:28:40 +03:00
|
|
|
(mapcar #'+vertico--workspace-nth-source '(0 1 2 3 4 5 6 7 8 final)))
|
2021-05-21 16:38:54 +03:00
|
|
|
|
|
|
|
(autoload 'consult--multi "consult")
|
|
|
|
;;;###autoload
|
2021-07-09 20:28:40 +03:00
|
|
|
(defun +vertico/switch-workspace-buffer ()
|
2021-05-21 16:38:54 +03:00
|
|
|
"Switch to another buffer in the same workspace.
|
|
|
|
|
|
|
|
Use consult narrowing with another workspace number to open a buffer from that workspace
|
|
|
|
BUG but it opens it in the current workspace (ivy also does this, but who cares)"
|
|
|
|
(interactive)
|
2021-07-09 20:28:40 +03:00
|
|
|
(when-let (buffer (consult--multi (+vertico--workspace-generate-sources)
|
2021-05-21 16:38:54 +03:00
|
|
|
:require-match
|
|
|
|
(confirm-nonexistent-file-or-buffer)
|
|
|
|
:prompt (format "Switch to buffer (%s): "
|
2021-09-21 17:57:50 +03:00
|
|
|
(+workspace-current-name))
|
|
|
|
:history 'consult--buffer-history
|
|
|
|
:sort nil))
|
2021-05-21 16:38:54 +03:00
|
|
|
;; When the buffer does not belong to a source,
|
|
|
|
;; create a new buffer with the name.
|
|
|
|
(unless (cdr buffer)
|
|
|
|
(funcall consult--buffer-display (car buffer)))))
|
2021-06-08 03:58:15 +03:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-07-28 13:09:44 -04:00
|
|
|
(defun +vertico/embark-open-in-new-workspace (x)
|
2021-06-08 03:58:15 +03:00
|
|
|
"Open X (a file) in a new workspace."
|
2021-07-28 13:09:44 -04:00
|
|
|
(interactive)
|
2021-06-08 03:58:15 +03:00
|
|
|
(+workspace/new)
|
|
|
|
(find-file x))
|