]> code.delx.au - gnu-emacs/commitdiff
emacs-lisp/package.el (package--list-loaded-files): New function
authorArtur Malabarba <bruce.connor.am@gmail.com>
Sat, 13 Dec 2014 11:48:08 +0000 (11:48 +0000)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Sat, 13 Dec 2014 12:31:20 +0000 (12:31 +0000)
List files in a given directory which correspond to already loaded
files.

lisp/ChangeLog
lisp/emacs-lisp/package.el

index f3d56c9924124b3e2f9950c0b91e131d078f129c..bc34066d001f0fe4d00cd77ae5446ca447d3f50e 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-13  Artur Malabarba  <bruce.connor.am@gmail.com>
+
+       * emacs-lisp/package.el (package--list-loaded-files): New function
+       to list files in a given directory which correspond to already
+       loaded files.
+
 2014-12-13  Eric S. Raymond  <esr@snark.thyrsus.com>
 
        * vc/vc-svn.el (vc-svn-diff): Fix bug #19312.
index 4e5c397e433e8f0ccc1b13ba23d997f5370bcb7b..654ad3aa3a58beb9f8549711257da638d37a9b7b 100644 (file)
@@ -543,6 +543,38 @@ Return the max version (as a string) if the package is held at a lower version."
     ;; Don't return nil.
     t))
 
+(defun package--list-loaded-files (dir)
+  "Recursively list all files in DIR which correspond to loaded features.
+Returns the `file-name-sans-extension' of each file, relative to
+DIR, sorted by most recently loaded last."
+  (let* ((history (mapcar (lambda (x) (file-name-sans-extension
+                                  (file-truename (car x))))
+                    load-history))
+         (dir (file-truename dir))
+         ;; List all files that have already been loaded.
+         (list-of-conflicts
+          (remove
+           nil
+           (mapcar
+               (lambda (x) (let* ((file (file-relative-name x dir))
+                             ;; Previously loaded file, if any.
+                             (previous
+                              (ignore-errors
+                                (file-name-sans-extension
+                                 (file-truename (find-library-name file)))))
+                             (pos (when previous (member previous history))))
+                        ;; Return (RELATIVE-FILENAME . HISTORY-POSITION)
+                        (when pos
+                          (cons (file-name-sans-extension file) (length pos)))))
+             (directory-files-recursively dir "\\`[^\\.].*\\.el\\'")))))
+    ;; Turn the list of (FILENAME . POS) back into a list of features.  Files in
+    ;; subdirectories are returned relative to DIR (so not actually features).
+    (let ((default-directory (file-name-as-directory dir)))
+      (mapcar (lambda (x) (file-truename (car x)))
+        (sort list-of-conflicts
+              ;; Sort the files by ascending HISTORY-POSITION.
+              (lambda (x y) (< (cdr x) (cdr y))))))))
+
 (defun package-built-in-p (package &optional min-version)
   "Return true if PACKAGE is built-in to Emacs.
 Optional arg MIN-VERSION, if non-nil, should be a version list