Add +workspace-buffer-list & +workspace-list-names
...and change +workspace-list to return a list of persp structs, rather than names.
This commit is contained in:
parent
4c11377e18
commit
ba32bf6e4d
1 changed files with 36 additions and 12 deletions
|
@ -17,9 +17,32 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +workspace-list ()
|
(defun +workspace-list ()
|
||||||
"Retrieve a list of names of open workspaces (strings)."
|
"Return a list of workspace structs."
|
||||||
|
(mapcar #'persp-get-by-name (+workspace-list-names)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +workspace-list-names ()
|
||||||
|
"Return a list of workspace names (strings)."
|
||||||
(delete persp-nil-name (persp-names-current-frame-fast-ordered)))
|
(delete persp-nil-name (persp-names-current-frame-fast-ordered)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +workspace-buffer-list (&optional persp)
|
||||||
|
"Return a list of buffers in PERSP (defaults to the current perspective).
|
||||||
|
|
||||||
|
PERSP can be a string (name of a workspace) or a perspective hash (satisfies
|
||||||
|
`+workspace-p').
|
||||||
|
|
||||||
|
If PERSP is t, then return a list of orphaned buffers associated with no
|
||||||
|
perspectives."
|
||||||
|
(cond ((not persp)
|
||||||
|
(persp-buffer-list-restricted))
|
||||||
|
((eq persp t)
|
||||||
|
(cl-remove-if #'persp--buffer-in-persps (doom-buffer-list)))
|
||||||
|
((+workspace-p persp)
|
||||||
|
(safe-persp-buffers persp))
|
||||||
|
((stringp persp)
|
||||||
|
(safe-persp-buffers (+workspace-get persp t)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +workspace-p (obj)
|
(defun +workspace-p (obj)
|
||||||
"Return t if OBJ is a perspective hash table."
|
"Return t if OBJ is a perspective hash table."
|
||||||
|
@ -34,7 +57,7 @@
|
||||||
(setq name (symbol-name name)))
|
(setq name (symbol-name name)))
|
||||||
(unless (stringp name)
|
(unless (stringp name)
|
||||||
(error "Expected a string, got a %s" (type-of name)))
|
(error "Expected a string, got a %s" (type-of name)))
|
||||||
(member name (+workspace-list)))
|
(member name (+workspace-list-names)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +workspace-get (name &optional noerror)
|
(defun +workspace-get (name &optional noerror)
|
||||||
|
@ -133,7 +156,7 @@ perspective or its hash table."
|
||||||
(persp-frame-switch name))
|
(persp-frame-switch name))
|
||||||
|
|
||||||
(defun +workspace--generate-id ()
|
(defun +workspace--generate-id ()
|
||||||
(or (cl-loop for name in (+workspace-list)
|
(or (cl-loop for name in (+workspace-list-names)
|
||||||
when (string-match-p "^#[0-9]+$" name)
|
when (string-match-p "^#[0-9]+$" name)
|
||||||
maximize (string-to-number (substring name 1)) into max
|
maximize (string-to-number (substring name 1)) into max
|
||||||
finally return (if max (1+ max)))
|
finally return (if max (1+ max)))
|
||||||
|
@ -189,7 +212,7 @@ workspace."
|
||||||
(list
|
(list
|
||||||
(if current-prefix-arg
|
(if current-prefix-arg
|
||||||
(+workspace-current-name)
|
(+workspace-current-name)
|
||||||
(completing-read "Workspace to save: " (+workspace-list)))))
|
(completing-read "Workspace to save: " (+workspace-list-names)))))
|
||||||
(if (+workspace-save name)
|
(if (+workspace-save name)
|
||||||
(+workspace-message (format "'%s' workspace saved" name) 'success)
|
(+workspace-message (format "'%s' workspace saved" name) 'success)
|
||||||
(+workspace-error (format "Couldn't save workspace %s" name))))
|
(+workspace-error (format "Couldn't save workspace %s" name))))
|
||||||
|
@ -232,7 +255,7 @@ workspace to delete."
|
||||||
(list
|
(list
|
||||||
(if current-prefix-arg
|
(if current-prefix-arg
|
||||||
(completing-read (format "Delete workspace (default: %s): " current-name)
|
(completing-read (format "Delete workspace (default: %s): " current-name)
|
||||||
(+workspace-list)
|
(+workspace-list-names)
|
||||||
nil nil current-name)
|
nil nil current-name)
|
||||||
current-name))))
|
current-name))))
|
||||||
(condition-case ex
|
(condition-case ex
|
||||||
|
@ -248,7 +271,8 @@ workspace to delete."
|
||||||
(defun +workspace/kill-session ()
|
(defun +workspace/kill-session ()
|
||||||
"Delete the current session, clears all workspaces, windows and buffers."
|
"Delete the current session, clears all workspaces, windows and buffers."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless (cl-every '+workspace-delete (delete +workspaces-main (+workspace-list)))
|
(unless (cl-every #'+workspace-delete
|
||||||
|
(delete +workspaces-main (+workspace-list-names)))
|
||||||
(+workspace-error "Could not clear session"))
|
(+workspace-error "Could not clear session"))
|
||||||
(+workspace-switch +workspaces-main t)
|
(+workspace-switch +workspaces-main t)
|
||||||
(doom/kill-all-buffers)
|
(doom/kill-all-buffers)
|
||||||
|
@ -288,12 +312,12 @@ pre-existing workspace."
|
||||||
end of the workspace list."
|
end of the workspace list."
|
||||||
(interactive
|
(interactive
|
||||||
(list (or current-prefix-arg
|
(list (or current-prefix-arg
|
||||||
(completing-read "Switch to workspace: " (+workspace-list)))))
|
(completing-read "Switch to workspace: " (+workspace-list-names)))))
|
||||||
(when (and (stringp index)
|
(when (and (stringp index)
|
||||||
(string-match-p "^[0-9]+$" index))
|
(string-match-p "^[0-9]+$" index))
|
||||||
(setq index (string-to-number index)))
|
(setq index (string-to-number index)))
|
||||||
(condition-case ex
|
(condition-case ex
|
||||||
(let ((names (+workspace-list))
|
(let ((names (+workspace-list-names))
|
||||||
(old-name (+workspace-current-name)))
|
(old-name (+workspace-current-name)))
|
||||||
(cond ((numberp index)
|
(cond ((numberp index)
|
||||||
(let ((dest (nth index names)))
|
(let ((dest (nth index names)))
|
||||||
|
@ -316,7 +340,7 @@ end of the workspace list."
|
||||||
(defun +workspace/switch-to-last ()
|
(defun +workspace/switch-to-last ()
|
||||||
"Switch to the last workspace."
|
"Switch to the last workspace."
|
||||||
(interactive)
|
(interactive)
|
||||||
(+workspace/switch-to (car (last (+workspace-list)))))
|
(+workspace/switch-to (car (last (+workspace-list-names)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +workspace/cycle (n)
|
(defun +workspace/cycle (n)
|
||||||
|
@ -326,7 +350,7 @@ end of the workspace list."
|
||||||
(if (equal current-name persp-nil-name)
|
(if (equal current-name persp-nil-name)
|
||||||
(+workspace-switch +workspaces-main t)
|
(+workspace-switch +workspaces-main t)
|
||||||
(condition-case ex
|
(condition-case ex
|
||||||
(let* ((persps (+workspace-list))
|
(let* ((persps (+workspace-list-names))
|
||||||
(perspc (length persps))
|
(perspc (length persps))
|
||||||
(index (cl-position current-name persps)))
|
(index (cl-position current-name persps)))
|
||||||
(when (= perspc 1)
|
(when (= perspc 1)
|
||||||
|
@ -356,7 +380,7 @@ the workspace and move to the next."
|
||||||
(if (bound-and-true-p evil-mode)
|
(if (bound-and-true-p evil-mode)
|
||||||
(evil-window-delete)
|
(evil-window-delete)
|
||||||
(delete-window)))
|
(delete-window)))
|
||||||
((> (length (+workspace-list)) 1)
|
((> (length (+workspace-list-names)) 1)
|
||||||
(+workspace/delete current-persp-name))))))
|
(+workspace/delete current-persp-name))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -376,7 +400,7 @@ the workspace and move to the next."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun +workspace--tabline (&optional names)
|
(defun +workspace--tabline (&optional names)
|
||||||
(let ((names (or names (+workspace-list)))
|
(let ((names (or names (+workspace-list-names)))
|
||||||
(current-name (+workspace-current-name)))
|
(current-name (+workspace-current-name)))
|
||||||
(mapconcat
|
(mapconcat
|
||||||
#'identity
|
#'identity
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue