Function: package--reload-previously-loaded

package--reload-previously-loaded is a byte-compiled function defined in package.el.gz.

Signature

(package--reload-previously-loaded PKG-DESC &optional WARN)

Documentation

Force reimportation of files in PKG-DESC already present in load-history.

New editions of files contain macro definitions and redefinitions, the overlooking of which would cause byte-compilation of the new package to fail. If WARN is a string, display a warning (using WARN as a format string) before reloading the files. WARN must have two %-sequences corresponding to package name (a symbol) and a list of files loaded (as sexps).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/package.el.gz
(defun package--reload-previously-loaded (pkg-desc &optional warn)
  "Force reimportation of files in PKG-DESC already present in `load-history'.
New editions of files contain macro definitions and
redefinitions, the overlooking of which would cause
byte-compilation of the new package to fail.
If WARN is a string, display a warning (using WARN as a format string)
before reloading the files.  WARN must have two %-sequences
corresponding to package name (a symbol) and a list of files loaded (as
sexps)."
  (with-demoted-errors "Error in package--load-files-for-activation: %s"
    (let* (result
           (dir (package-desc-dir pkg-desc))
           ;; A previous implementation would skip `dir' itself.
           ;; However, in normal use reloading from the same directory
           ;; never happens anyway, while in certain cases external to
           ;; Emacs a package in the same directory not necessary
           ;; stays byte-identical, e.g.  during development.  Just
           ;; don't special-case `dir'.
           (effective-path (or (bound-and-true-p find-library-source-path)
                               load-path))
           (files (directory-files-recursively dir "\\`[^\\.].*\\.el\\'"))
           (history (mapcar #'file-truename
                            (cl-remove-if-not #'stringp
                                              (mapcar #'car load-history)))))
      (dolist (file files)
        (when-let* ((library (package--library-stem
                              (file-relative-name file dir)))
                    (canonical (locate-library library nil effective-path))
                    (truename (file-truename canonical))
                    ;; Normally, all files in a package are compiled by
                    ;; now, but don't assume that.  E.g. different
                    ;; versions can add or remove `no-byte-compile'.
                    (altname (if (string-suffix-p ".el" truename)
                                 (replace-regexp-in-string
                                  "\\.el\\'" ".elc" truename t)
                               (replace-regexp-in-string
                                "\\.elc\\'" ".el" truename t)))
                    (found (or (member truename history)
                               (and (not (string= altname truename))
                                    (member altname history))))
                    (recent-index (length found)))
          (unless (equal (file-name-base library)
                         (format "%s-autoloads" (package-desc-name pkg-desc)))
            (push (cons (expand-file-name library dir) recent-index) result))))
      (when (and result warn)
        (display-warning 'package
                         (format warn (package-desc-name pkg-desc)
                                 (mapcar #'car result))))
      (mapc (lambda (c) (load (car c) nil t))
            (sort result (lambda (x y) (< (cdr x) (cdr y))))))))