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
(run-hooks 'doom-after-switch-window-hook))))))
(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
(null dest)
(eq dest (current-buffer)))
(apply orig-fn dest args)
(let ((doom-inhibit-switch-buffer-hooks t))
(run-hooks 'doom-before-switch-buffer-hook)
(prog1 (apply orig-fn dest args)
(with-current-buffer dest
(run-hooks 'doom-after-switch-buffer-hook)))))))
(if (or doom-inhibit-switch-buffer-hooks
(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-before-switch-buffer-hook)
(prog1 (apply orig-fn buffer-or-name args)
(with-current-buffer buffer-or-name
(run-hooks 'doom-after-switch-buffer-hook))))))
(defun doom|init-custom-hooks (&optional disable)
(dolist (spec '((select-frame . doom*switch-frame-hooks)