                  (delq 'process-kill-buffer-query-function
                        kill-buffer-query-functions)))
             (kill-buffer (window-buffer window)))
-        (doom-popup-mode -1))
-      (delete-window window)
-      (when (< emacs-major-version 25)
-        (unless dont-redraw (redraw-frame))))))
+        (doom-popup-mode -1)))
+    (delete-window window)
+    (unless dont-redraw (redraw-frame))))
 
 ;;;###autoload
 (defun doom/popup-close-all (&optional dont-kill dont-redraw)
   "Closes all popups (kill them if DONT-KILL-BUFFERS is non-nil). Then redraw
 the display (unless DONT-REDRAW is non-nil)."
   (interactive)
-  (mapc (lambda (w) (doom/popup-close w dont-kill t))
-        (doom/get-visible-windows (buffer-list)))
+  (let ((orig-win (selected-window)))
+    (mapc (lambda (w) (doom/popup-close w dont-kill t))
+          (--filter (and (doom/popup-p it) (not (eq it orig-win))) (window-list))))
   (when (< emacs-major-version 25)
     (unless dont-redraw (redraw-frame))))
 

(defvar doom-popup-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map [remap doom/kill-real-buffer] 'doom/popup-close)
    (define-key map [remap evil-window-move-very-bottom] 'ignore)
    (define-key map [remap evil-window-move-very-top]    'ignore)
    (define-key map [remap evil-window-move-far-left]    'ignore)

  (doom/popup-save (apply orig-fun args)))

(put 'doom-popup-mode 'permanent-local t)
(put 'doom-popup-rule 'permanent-local t)

;;;###autoload
(define-minor-mode doom-popup-mode
  "Pop ups"
  :global nil
  :init-value nil
  :keymap doom-popup-mode-map
  (let ((rules (--any (let ((key (car it)))
                        (when (cond ((symbolp key)
                                     (or (eq major-mode key)
                                         (derived-mode-p key)))
                                    ((stringp key)
                                     (string-match-p key (buffer-name))))
                          (cdr it)))
                      doom-popup-rules)))
    (setq doom-last-popup (current-buffer))
    (setq-local doom-popup-rule rules)
    (let ((map doom-popup-mode-map))
      (unless (memq :noesc rules)
        (use-local-map doom-popup-mode-local-map)))
    (unless (memq :modeline rules)
      (doom-hide-mode-line-mode (if doom-popup-mode +1 -1)))))

