Refactor switch {buffer,window} hooks
This commit is contained in:
parent
05303c0fdb
commit
f18e1c0ea1
2 changed files with 9 additions and 14 deletions
|
@ -93,33 +93,28 @@ Do not set this directly.")
|
|||
|
||||
(defun doom*switch-window-hooks (orig-fn window &optional norecord)
|
||||
(if (or doom-inhibit-switch-window-hooks
|
||||
(null window)
|
||||
norecord
|
||||
(eq window (selected-window))
|
||||
(window-minibuffer-p)
|
||||
(window-minibuffer-p window))
|
||||
(funcall orig-fn window norecord)
|
||||
(let ((doom-inhibit-switch-window-hooks t))
|
||||
(run-hooks 'doom-exit-window-hook)
|
||||
(prog1 (funcall orig-fn window norecord)
|
||||
(with-selected-window window
|
||||
(run-hooks 'doom-enter-window-hook))))))
|
||||
(run-hooks 'doom-enter-window-hook)))))
|
||||
|
||||
(defun doom*switch-buffer-hooks (orig-fn buffer-or-name &rest args)
|
||||
(if (or doom-inhibit-switch-buffer-hooks
|
||||
(null buffer-or-name)
|
||||
(if (eq orig-fn 'switch-to-buffer) (car args))
|
||||
(if (eq orig-fn 'pop-to-buffer) (nth 1 args))
|
||||
(eq (get-buffer buffer-or-name) (current-buffer)))
|
||||
(apply orig-fn buffer-or-name args)
|
||||
(let ((doom-inhibit-switch-buffer-hooks t))
|
||||
(run-hooks 'doom-exit-buffer-hook)
|
||||
(prog1 (apply orig-fn buffer-or-name args)
|
||||
(when (buffer-live-p (get-buffer buffer-or-name))
|
||||
(with-current-buffer buffer-or-name
|
||||
(run-hooks 'doom-enter-buffer-hook)))))))
|
||||
(run-hooks 'doom-enter-buffer-hook)))))
|
||||
|
||||
(defun doom|init-switch-hooks (&optional disable)
|
||||
"Set up enter/exit hooks for windows and buffers.
|
||||
|
||||
See `doom-enter-buffer-hook', `doom-enter-window-hook', `doom-exit-buffer-hook'
|
||||
and `doom-exit-window-hook'."
|
||||
(defun doom-init-switch-hooks (&optional disable)
|
||||
(dolist (spec '((select-window . doom*switch-window-hooks)
|
||||
(switch-to-buffer . doom*switch-buffer-hooks)
|
||||
(display-buffer . doom*switch-buffer-hooks)
|
||||
|
|
|
@ -63,9 +63,9 @@
|
|||
b (get-buffer-create "b"))
|
||||
(spy-on 'before-hook)
|
||||
(spy-on 'after-hook)
|
||||
(doom|init-switch-hooks))
|
||||
(doom-init-switch-hooks))
|
||||
(after-each
|
||||
(doom|init-switch-hooks 'disable)
|
||||
(doom-init-switch-hooks 'disable)
|
||||
(kill-buffer a)
|
||||
(kill-buffer b))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue