Fix infinite recursion in buffer switch hooks

Caused by advice functions trying to manipulate non-existent buffers
that were intended to be created after switching to them.
This commit is contained in:
Henrik Lissner 2018-06-11 00:39:55 +02:00
parent c8783f3291
commit dd9f8d47af
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -385,16 +385,14 @@ from the default."
(with-selected-window window (with-selected-window window
(run-hooks 'doom-after-switch-window-hook)))))) (run-hooks 'doom-after-switch-window-hook))))))
(defun doom*switch-buffer-hooks (orig-fn buffer-or-name &rest args) (defun doom*switch-buffer-hooks (orig-fn buffer-or-name &rest args)
(let ((dest (get-buffer buffer-or-name))) (if (or doom-inhibit-switch-buffer-hooks
(if (or doom-inhibit-switch-buffer-hooks (eq (get-buffer buffer-or-name) (current-buffer)))
(null dest) (apply orig-fn buffer-or-name args)
(eq dest (current-buffer))) (let ((doom-inhibit-switch-buffer-hooks t))
(apply orig-fn dest args) (run-hooks 'doom-before-switch-buffer-hook)
(let ((doom-inhibit-switch-buffer-hooks t)) (prog1 (apply orig-fn buffer-or-name args)
(run-hooks 'doom-before-switch-buffer-hook) (with-current-buffer buffer-or-name
(prog1 (apply orig-fn dest args) (run-hooks 'doom-after-switch-buffer-hook))))))
(with-current-buffer dest
(run-hooks 'doom-after-switch-buffer-hook)))))))
(defun doom|init-custom-hooks (&optional disable) (defun doom|init-custom-hooks (&optional disable)
(dolist (spec '((select-frame . doom*switch-frame-hooks) (dolist (spec '((select-frame . doom*switch-frame-hooks)