ui/popup: prevent infinite loop when killing popup buffers

This commit is contained in:
Henrik Lissner 2019-12-22 16:02:56 -05:00
parent d0188b827a
commit 6ac04e5a6d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -13,26 +13,27 @@
(defun +popup--kill-buffer (buffer ttl) (defun +popup--kill-buffer (buffer ttl)
"Tries to kill BUFFER, as was requested by a transient timer. If it fails, eg. "Tries to kill BUFFER, as was requested by a transient timer. If it fails, eg.
the buffer is visible, then set another timer and try again later." the buffer is visible, then set another timer and try again later."
(when (buffer-live-p buffer) (let ((inhibit-quit t))
(let ((inhibit-quit t) (cond ((not (buffer-live-p buffer)))
(kill-buffer-hook (remq '+popup-kill-buffer-hook-h kill-buffer-hook))) ((not (get-buffer-window buffer t))
(cond ((get-buffer-window buffer t) (with-demoted-errors "Error killing transient buffer: %s"
(with-current-buffer buffer
(let ((kill-buffer-hook (remq '+popup-kill-buffer-hook-h kill-buffer-hook))
confirm-kill-processes)
(when-let (process (get-buffer-process buffer))
(kill-process process))
(let (kill-buffer-query-functions)
;; HACK The debugger backtrace buffer, when killed, called
;; `top-level'. This causes jumpiness when the popup
;; manager tries to clean it up.
(cl-letf (((symbol-function #'top-level) #'ignore))
(kill-buffer buffer)))))))
((let ((ttl (if (= ttl 0)
(or (plist-get +popup-defaults :ttl) 3)
ttl)))
(with-current-buffer buffer (with-current-buffer buffer
(setq +popup--timer (setq +popup--timer
(run-at-time ttl nil #'+popup--kill-buffer buffer ttl)))) (run-at-time ttl nil #'+popup--kill-buffer buffer ttl))))))))
((eq ttl 0)
(kill-buffer buffer))
((with-demoted-errors "Error killing transient buffer: %s"
(with-current-buffer buffer
(let (confirm-kill-processes)
(when-let (process (get-buffer-process buffer))
(kill-process process))
(let (kill-buffer-query-functions)
;; HACK The debugger backtrace buffer, when killed, called
;; `top-level'. This causes jumpiness when the popup
;; manager tries to clean it up.
(cl-letf (((symbol-function #'top-level) #'ignore))
(kill-buffer buffer)))))))))))
(defun +popup--delete-window (window) (defun +popup--delete-window (window)
"Do housekeeping before destroying a popup window. "Do housekeeping before destroying a popup window.