         (t
          (remove-hook 'doom-unreal-buffer-functions #'+popup-p)
          (remove-hook 'doom-escape-hook #'+popup|close-on-escape)
+         (remove-hook 'doom-cleanup-hook #'+popup|cleanup-rules)
          (setq display-buffer-alist +popup--old-display-buffer-alist)
+         (+popup|cleanup-rules)
          (dolist (prop +popup-window-parameters)
            (map-delete prop window-persistent-parameters)))))
 

  (cond (+popup-mode
         (add-hook 'doom-unreal-buffer-functions #'+popup-p)
         (add-hook 'doom-escape-hook #'+popup|close-on-escape t)
         (setq +popup--old-display-buffer-alist display-buffer-alist
               display-buffer-alist +popup--display-buffer-alist)
         (dolist (prop +popup-window-parameters)

       #'+popup/close
     #'+popup/close-all)))

;;;###autoload
(defun +popup|cleanup-rules ()
  "Cleans up any duplicate popup rules."
  (interactive)
  (cl-delete-duplicates
   +popup--display-buffer-alist
   :key #'car :test #'equal :from-end t)
  (when +popup-mode
    (setq display-buffer-alist +popup--display-buffer-alist)))


;;
;; Commands
