1

I'm reading through the definition of package-initialize to try and understand what goes on under the hood, and part of what it does is to read the package archive files. I see it comparing version numbers, but I don't fully understand what it's doing at a high level.

I'm looking at this method:

(defun package-read-archive-contents (archive)
  "Re-read archive contents for ARCHIVE.
If successful, set the variable `package-archive-contents'.
If the archive version is too new, signal an error."
  ;; Version 1 of 'archive-contents' is identical to our internal
  ;; representation.
  (let* ((contents-file (format "archives/%s/archive-contents" archive))
     (contents (package--read-archive-file contents-file)))
    (when contents
      (dolist (package contents)
    (package--add-to-archive-contents package archive)))))

I think it's being used to make sure that the packages we're loading also have their descriptors added to the package archives (e.g. .emacs.d/elpa/melpa-stable/archive-contents if they're not already in there. But I'm not clear on what these archive-contents files are used for, since running a command like package-list-packages communicates with the remote package archive.

I apologize if this question is a bit muddled, but I'm trying to push through the awkward early stage of learning emacs.

I should also probably mention that the reason I started investigating the internals of package-initialize was to figure out if there's some kind of lazy-loading that I could be doing, rather than loading everything as soon as emacs starts up.

2
  • Could you give the code of this function? The function may vary between versions. Jul 25, 2016 at 12:21
  • 2
    Please ask a specific question about some part that you do not understand. Otherwise the question is too broad: at what level are you asking for a complete explanation of what it does? The code is of course the most complete explanation...
    – Drew
    Jul 25, 2016 at 14:13

1 Answer 1

4

package-initialize is supposed to find all the installed packages and activate them (depending on the optional argument) by executing their <pkg>-autoloads.el files. Part of the complexity comes from the fact that it tries to make sure that it only activates a single version (the latest) of a given package (in case several versions of a package are installed).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.