       (insert ";;; -*- lexical-binding:t -*-\n"
               ";; This file was autogenerated by `doom|refresh-cache', DO NOT EDIT!\n")
       (prin1 `(setq load-path ',load-path
+                    auto-mode-alist ',auto-mode-alist
                     Info-directory-list ',Info-directory-list
                     doom-disabled-packages ',doom-disabled-packages
                     package-activated-list ',package-activated-list)

      ;; in case this function has side effects.
      (progn
        (doom-packages--async-run 'doom//reload-autoloads)
        (load doom-autoload-file t nil t))
    (let ((default-directory doom-emacs-dir)
          (targets
           (file-expand-wildcards

            (load-path (append (list doom-emacs-dir)
                               doom-psuedo-module-dirs
                               doom-modules-dirs
                               load-path))
            library-cache)
        (unwind-protect
            (condition-case-unless-debug ex
                (with-current-buffer buf
                  (goto-char (point-min))
                  (insert ";;; -*- lexical-binding:t -*-\n"
                          ";; This file is autogenerated by `doom//reload-autoloads', DO NOT EDIT !!\n\n")

                  (save-excursion
                    ;; Replace autoload paths with absolute paths for faster
                    ;; resolution during load and simpler `load-path'
                    (while (re-search-forward "^\\s-*(autoload\\s-+'[^ ]+\\s-+\"\\([^/][^\"]*\\)\"" nil t)
                      (let ((path (match-string 1)))
                        ;; (delete-region (match-beginning 1) (match-end 1))
                        (replace-match
                         (or (cdr (assoc path library-cache))
                             (when-let* ((libpath (locate-library path))
                                         (libpath (file-name-sans-extension libpath)))
                               (push (cons path libpath) library-cache)
                               libpath)
                             (progn
                               (warn "Couldn't find absolute path for: %s" path)
                               path))
                         t t nil 1)))
                    (message "✓ Autoload paths expanded"))

                  (save-excursion
                    ;; insert package autoloads
                    (dolist (file (doom-packages--files doom-packages-dir "-autoloads\\.el$"))
                      (insert
                       (with-temp-buffer
                         (insert "\n(let ((load-file-name " (prin1-to-string file) "))")
                         (insert-file-contents file)
                         (while (re-search-forward "^;;\\(.*\n\\)" nil 'move)
                           (replace-match "" t t))
                         (unless (bolp) (insert "\n"))
                         (insert ")\n")
                         (buffer-string))))
                    (message "✓ Package autoloads included"))

                  ;; Replace autoload paths with absolute paths for faster
                  ;; resolution during load and simpler `load-path'
                  (while (re-search-forward "^\\s-*(add-to-list\\s-+'\\(?:load-path\\|auto-mode-alist\\)" nil t)
                    (beginning-of-line-text)
                    (kill-sexp))
                  (message "✓ Autoload load-path entries removed")

                  (save-buffer)
                  (let (byte-compile-warnings)
                    ;; give the file a chance to reveal errors
                    (load doom-autoload-file nil 'nomessage 'nosuffix))
                  (message "Done!"))
              ('error
               (delete-file doom-autoload-file)
