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:
Henrik Lissner 2018-06-30 00:57:41 +02:00
parent 537cc9e1ed
commit 83ba527afd
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 7 additions and 23 deletions

View file

@ -484,17 +484,6 @@ the next."
;; 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
(defun +workspaces|delete-associated-workspace (&optional frame)
"Delete workspace associated with current frame.

View file

@ -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-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
(defun +workspaces|init-persp-mode ()
(cond (persp-mode
@ -100,17 +106,10 @@ Uses `+workspaces-main' to determine the name of the main workspace."
;; kill-buffer-query-functions
(remove-hook 'kill-buffer-query-functions 'persp-kill-buffer-query-function)
(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
;; `doom-buffer-list'
(advice-add #'doom-buffer-list :override #'+workspace-buffer-list))
(t
(remove-hook 'doom-after-switch-buffer-hook #'+workspaces|auto-add-buffer)
(advice-remove #'doom-buffer-list #'+workspace-buffer-list))))
((advice-remove #'doom-buffer-list #'+workspace-buffer-list))))
(add-hook 'persp-mode-hook #'+workspaces|init-persp-mode)
(defun +workspaces|leave-nil-perspective (&rest _)

View file

@ -79,10 +79,6 @@
(expect (+workspace-contains-buffer-p in1)))
(it "returns nil for buffers outside of current workspace"
(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"
(expect (+workspace-orphaned-buffer-list) :to-contain out2)))