emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elpa packages and macro dependencies.


From: Artur Malabarba
Subject: Re: Elpa packages and macro dependencies.
Date: Mon, 20 Oct 2014 10:33:58 +0100

>> - Packages can include several files, so we have to figure out the set
>>   of files to load and (here's the rub) the order in which to load them.
>
> It could be approximated by doing it in the order found in load-history.
>

Thanks for the idea, Nicolas. I was struggling a bit with that part.

Here's what I had in mind. (I can turn this in to a patch, of course)

Inside the package-activate-1 function, immediately after loading the
“autoloads” file (which happens invariably), we call load on each file
in this package corresponding to features already loaded. Here's the
relevant snippet:

________________________________

(with-demoted-errors
  (load (expand-file-name autoload-name pkg-dir) nil t)
  ;; Call `load' on all files in `pkg-dir' which correspond to
  ;; provided features. Skip autoloads file since we already
  ;; evaluated it above.
  (mapcar (lambda (file) (load (expand-file-name file pkg-dir) nil t))
          ;; The autoloads file is usually not a feature, but better stay safe.
          (remove autoload-name (package-list-loaded-files pkg-dir))))

________________________________

The package-list-loaded-files function is then defined as follows. We
don't need to worry about inter-package dependency here, package.el
has already taken care of calling package-install in the right order.

We DO need to worry about intra-package dependencies (which
files require which), so we load them in the same order in which they
were originally added to features (thanks to Nicolas' idea). This should
be correct as long as the order in which files require each other doesn't
change between versions. And even when it does change, this can only
cause problems in situations where the current implementation already
causes problems anyway.

________________________________

(defun package-list-loaded-files (dir)
  "List all files in DIR which correspond to loaded features.
Returns the `file-name-base' of each file, sorted by most
recently loaded last."
  (mapcar
   ;; Turn the sorted list of cons back into a list of files.
   #'car
   (sort
    (remove nil (mapcar
                 (lambda (x) (let* ((name (file-name-base x))
                               (hist (memq (intern-soft name) features)))
                          ;; Return (FILENAME . HISTORY-POSITION)
                          (when hist
                            (cons name (length hist)))))
                 (directory-files "./" nil "^[^\\.].*\\.el\\'" 'nosort)))
    ;; The cdr is the position in history
    (lambda (x y) (< (cdr x) (cdr y))))))

________________________________

Haven't had time to test a full installation yet. But I've verified
package-list-loaded-files works.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]