[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master afd801f 1/2: emacs-lisp/package.el (package--list-l
From: |
Artur Malabarba |
Subject: |
[Emacs-diffs] master afd801f 1/2: emacs-lisp/package.el (package--list-loaded-files): New function |
Date: |
Sat, 13 Dec 2014 14:32:09 +0000 |
branch: master
commit afd801f9a7a5e025394d89dae798ac81bfc2d46d
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
emacs-lisp/package.el (package--list-loaded-files): New function
List files in a given directory which correspond to already loaded
files.
---
lisp/ChangeLog | 6 ++++++
lisp/emacs-lisp/package.el | 32 ++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f3d56c9..bc34066 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-13 Artur Malabarba <address@hidden>
+
+ * 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 <address@hidden>
* vc/vc-svn.el (vc-svn-diff): Fix bug #19312.
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 4e5c397..654ad3a 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -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