             (cl-assert (integerp ttl) t)
             (if (= ttl 0)
                 (+popup--kill-buffer buffer 0)
+              (add-hook 'kill-buffer-hook #'+popup|kill-buffer-hook nil t)
               (setq +popup--timer
                     (run-at-time ttl nil #'+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)
    (if (get-buffer-window buffer)
        (with-current-buffer buffer
          (setq +popup--timer
                (run-at-time ttl nil #'+popup--kill-buffer buffer ttl)))
      (with-demoted-errors "Error killing transient buffer: %s"
        (let ((inhibit-message (not doom-debug-mode)))
          (message "Cleaned up transient buffer: %s" buffer))
        (when-let* ((process (get-buffer-process (current-buffer))))
          (kill-process process))
        (kill-buffer buffer)))))

(defun +popup--init (window alist)
  "Initializes a popup window. Run any time a popup is opened. It sets the

  :init-value nil
  :keymap +popup-buffer-mode-map
  (when (and +popup-buffer-mode (timerp +popup--timer))
    (remove-hook 'kill-buffer-hook #'+popup|kill-buffer-hook t)
    (cancel-timer +popup--timer)
    (setq +popup--timer nil)))

