   (doom/popup-save (apply orig-fun args)))
 
 (put 'doom-popup-mode 'permanent-local t)
-(put 'doom-popup-mode-map '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
-  :global nil
-  (let ((rules (or doom-popup-rule
-                   (--any (let ((key (car it)))
-                            (when (cond ((symbolp key)
-                                         (or (eq major-mode key)
-                                             (derived-mode-p key)))
-                                        ((and (stringp key) buffer-file-name)
-                                         (string-match-p key buffer-file-name)))
-                              (cdr it)))
-                          doom-popup-rules))))
+  (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)
-    (unless (memq :noesc rules)
-      (make-local-variable 'doom-popup-mode-map)
-      (let ((map doom-popup-mode-map))
-        (define-key map [remap evil-force-normal-state] 'doom/popup-close)
-        (define-key map [escape] 'doom/popup-close)
-        (define-key map (kbd "ESC") 'doom/popup-close)))
+    (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)))))
 

     (prog1
         ,@body
       (when popup-p
         (if in-popup-p
             (doom/popup-last-buffer)
           (save-excursion (doom/popup-last-buffer)))))))

;;;###autoload
(defun doom/popup-buffer (buffer &optional plist)
  "Display BUFFER in a shackle popup."
  (let ((buffer-name (cond ((stringp buffer) buffer)
                           ((bufferp buffer) (buffer-name buffer))
                           (t (error "Not a valid buffer")))))
    (shackle-display-buffer
     (get-buffer-create buffer-name)
     nil (or plist (shackle-match buffer-name)))))

;;;###autoload

(defun doom*popup-init (orig-fn &rest args)
  "Enable `doom-popup-mode' in every popup window and returns the window."
  (let ((window (apply orig-fn args)))
    (with-selected-window window
      (doom-popup-mode +1))
    ;; NOTE orig-fn returns a window, so `doom*popup-init' must too
    window))
