 
 (def-package! ranger
   :when (featurep! +ranger)
+  :after dired
   :init
-  (defun ranger/dired-setup ()
-    (setq dired-omit-verbose nil)
-    (make-local-variable 'dired-hide-details-hide-symlink-targets)
-    (setq dired-hide-details-hide-symlink-targets nil)
-    ;; hide details by default
-    (dired-hide-details-mode t))
-  (add-hook 'dired-mode-hook #'ranger/dired-setup)
-
-  (setq ranger-override-dired t)
   ;; set up image-dired to allow picture resize
   (setq image-dired-dir (concat doom-cache-dir "image-dir"))
+  :config
   (unless (file-directory-p image-dired-dir)
     (make-directory image-dired-dir))
-  :config
-  (setq ranger-omit-regexp "^\.DS_Store$"
+
+  (set-popup-rule! "^\\*ranger" :ignore t)
+
+  (setq ranger-override-dired t
+        ranger-cleanup-on-disable t
+        ranger-omit-regexp "^\.DS_Store$"
         ranger-excluded-extensions '("mkv" "iso" "mp4")
         ranger-deer-show-details nil
-        ranger-max-preview-size 10))
+        ranger-max-preview-size 10
+        dired-omit-verbose nil))
 
 
 (def-package! all-the-icons-dired
   :when (featurep! +icons)
-  :defer t
-  :init
-  (add-hook! 'dired-mode-hook #'all-the-icons-dired-mode))
+  :hook (dired-mode . all-the-icons-dired-mode))
 
 
 (def-package! dired-x
-  :defer t
-  :commands dired-omit-mode
   :hook (dired-mode . dired-omit-mode))
+
 
 ;;
 ;; Evil integration

      :n "<" #'dired-prev-dirline
      :n ">" #'dired-next-dirline
      :n "^" #'dired-up-directory
      :n [?\S-\ ] 'dired-previous-line
      :n [remap next-line] 'dired-next-line
      :n [remap previous-line] 'dired-previous-line
      ;; hiding
      :n "g$" #'dired-hide-subdir ;; FIXME: This can probably live on a better binding.
      :n "M-$" #'dired-hide-all
      :n "(" #'dired-hide-details-mode
      ;; isearch
      :n "M-s a C-s"   'dired-do-isearch
      :n "M-s a M-C-s" #'dired-do-isearch-regexp
      :n "M-s f C-s"   'dired-isearch-filenames
      :n "M-s f M-C-s" #'dired-isearch-filenames-regexp
      ;; misc
      :n [remap read-only-mode] 'dired-toggle-read-only
      ;; `toggle-read-only' is an obsolete alias for `read-only-mode'
      :n [remap toggle-read-only] 'dired-toggle-read-only
      :n "g?" #'dired-summary
      :n "<delete>" #'dired-unmark-backward
      :n [remap undo] 'dired-undo
      :n [remap advertised-undo] 'dired-undo
      ;; thumbnail manipulation (image-dired)
      :n "C-t d" #'image-dired-display-thumbs
      :n "C-t t" #'image-dired-tag-files

      :n "q" #'quit-window
      :m "j" #'dired-next-line
      :m "k" #'dired-previous-line
      :n [mouse-2] #'dired-mouse-find-file-other-window
      :n [follow-link] #'mouse-face
      ;; Commands to mark or flag certain categories of files
      :n "#" #'dired-flag-auto-save-files
      :n "." #'dired-clean-directory
