From 6ac04e5a6d7c47e9c81c60feaa5ed6947838069e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 22 Dec 2019 16:02:56 -0500 Subject: [PATCH] ui/popup: prevent infinite loop when killing popup buffers --- modules/ui/popup/autoload/popup.el | 37 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/modules/ui/popup/autoload/popup.el b/modules/ui/popup/autoload/popup.el index e4391cae6..3d030b92b 100644 --- a/modules/ui/popup/autoload/popup.el +++ b/modules/ui/popup/autoload/popup.el @@ -13,26 +13,27 @@ (defun +popup--kill-buffer (buffer ttl) "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." - (when (buffer-live-p buffer) - (let ((inhibit-quit t) - (kill-buffer-hook (remq '+popup-kill-buffer-hook-h kill-buffer-hook))) - (cond ((get-buffer-window buffer t) + (let ((inhibit-quit t)) + (cond ((not (buffer-live-p buffer))) + ((not (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 (setq +popup--timer - (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))))))))))) + (run-at-time ttl nil #'+popup--kill-buffer buffer ttl)))))))) (defun +popup--delete-window (window) "Do housekeeping before destroying a popup window.