Refactor auto-add-buffer functionality
Use built-in mechanism for auto-adding buffers to current workspace, rather than reinvent the wheel.
This commit is contained in:
parent
537cc9e1ed
commit
83ba527afd
3 changed files with 7 additions and 23 deletions
|
@ -484,17 +484,6 @@ the next."
|
||||||
;; Hooks
|
;; Hooks
|
||||||
;;
|
;;
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +workspaces|auto-add-buffer ()
|
|
||||||
"Auto-associate buffers with perspectives upon opening them.
|
|
||||||
|
|
||||||
Allows a perspective-specific buffer list via `+workspaces-buffer-list'."
|
|
||||||
(when (and persp-mode
|
|
||||||
(not persp-temporarily-display-buffer)
|
|
||||||
(doom-real-buffer-p))
|
|
||||||
(persp-add-buffer (current-buffer) (get-current-persp) nil)
|
|
||||||
(force-mode-line-update t)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +workspaces|delete-associated-workspace (&optional frame)
|
(defun +workspaces|delete-associated-workspace (&optional frame)
|
||||||
"Delete workspace associated with current frame.
|
"Delete workspace associated with current frame.
|
||||||
|
|
|
@ -93,6 +93,12 @@ Uses `+workspaces-main' to determine the name of the main workspace."
|
||||||
persp-auto-resume-time -1 ; Don't auto-load on startup
|
persp-auto-resume-time -1 ; Don't auto-load on startup
|
||||||
persp-auto-save-opt (if noninteractive 0 1)) ; auto-save on kill
|
persp-auto-save-opt (if noninteractive 0 1)) ; auto-save on kill
|
||||||
|
|
||||||
|
;; Ensure buffers we've opened/switched to are auto-added to the current
|
||||||
|
;; perspective
|
||||||
|
(setq persp-add-buffer-on-find-file t
|
||||||
|
persp-add-buffer-on-after-change-major-mode t)
|
||||||
|
(add-hook 'persp-add-buffer-on-after-change-major-mode-filter-functions #'doom-unreal-buffer-p)
|
||||||
|
|
||||||
;; bootstrap
|
;; bootstrap
|
||||||
(defun +workspaces|init-persp-mode ()
|
(defun +workspaces|init-persp-mode ()
|
||||||
(cond (persp-mode
|
(cond (persp-mode
|
||||||
|
@ -100,17 +106,10 @@ Uses `+workspaces-main' to determine the name of the main workspace."
|
||||||
;; kill-buffer-query-functions
|
;; kill-buffer-query-functions
|
||||||
(remove-hook 'kill-buffer-query-functions 'persp-kill-buffer-query-function)
|
(remove-hook 'kill-buffer-query-functions 'persp-kill-buffer-query-function)
|
||||||
(add-hook 'kill-buffer-query-functions 'persp-kill-buffer-query-function t)
|
(add-hook 'kill-buffer-query-functions 'persp-kill-buffer-query-function t)
|
||||||
|
|
||||||
;; Ensure buffers we've opened/switched to are auto-added to the
|
|
||||||
;; current perspective
|
|
||||||
(add-hook 'doom-after-switch-buffer-hook #'+workspaces|auto-add-buffer)
|
|
||||||
|
|
||||||
;; Remap `buffer-list' to current workspace's buffers in
|
;; Remap `buffer-list' to current workspace's buffers in
|
||||||
;; `doom-buffer-list'
|
;; `doom-buffer-list'
|
||||||
(advice-add #'doom-buffer-list :override #'+workspace-buffer-list))
|
(advice-add #'doom-buffer-list :override #'+workspace-buffer-list))
|
||||||
(t
|
((advice-remove #'doom-buffer-list #'+workspace-buffer-list))))
|
||||||
(remove-hook 'doom-after-switch-buffer-hook #'+workspaces|auto-add-buffer)
|
|
||||||
(advice-remove #'doom-buffer-list #'+workspace-buffer-list))))
|
|
||||||
(add-hook 'persp-mode-hook #'+workspaces|init-persp-mode)
|
(add-hook 'persp-mode-hook #'+workspaces|init-persp-mode)
|
||||||
|
|
||||||
(defun +workspaces|leave-nil-perspective (&rest _)
|
(defun +workspaces|leave-nil-perspective (&rest _)
|
||||||
|
|
|
@ -79,10 +79,6 @@
|
||||||
(expect (+workspace-contains-buffer-p in1)))
|
(expect (+workspace-contains-buffer-p in1)))
|
||||||
(it "returns nil for buffers outside of current workspace"
|
(it "returns nil for buffers outside of current workspace"
|
||||||
(expect (+workspace-contains-buffer-p out1) :to-be nil))
|
(expect (+workspace-contains-buffer-p out1) :to-be nil))
|
||||||
(it "automatically adds interactively opened buffers"
|
|
||||||
(expect (+workspace-contains-buffer-p out1) :to-be nil)
|
|
||||||
(with-current-buffer out1 (+workspaces|auto-add-buffer))
|
|
||||||
(expect (+workspace-contains-buffer-p out1)))
|
|
||||||
(xit "returns a list of orphaned buffers"
|
(xit "returns a list of orphaned buffers"
|
||||||
(expect (+workspace-orphaned-buffer-list) :to-contain out2)))
|
(expect (+workspace-orphaned-buffer-list) :to-contain out2)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue