aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2018-10-18 12:17:52 -0400
committerStefan Monnier2018-10-18 12:17:52 -0400
commitf35916ce510968cf32a34cc32ebc21dd9be30443 (patch)
treea869d7494b02ffd129c761a93c3e64aab7fd5170
parent46106eec16ddb2294e06f9e482b9183777b90014 (diff)
downloademacs-f35916ce510968cf32a34cc32ebc21dd9be30443.tar.gz
emacs-f35916ce510968cf32a34cc32ebc21dd9be30443.zip
* lisp/emacs-lisp/package.el (package-get-version): New macro
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/emacs-lisp/package.el35
2 files changed, 36 insertions, 2 deletions
diff --git a/etc/NEWS b/etc/NEWS
index b46dcae9c23..2ebe5a16a22 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -414,6 +414,9 @@ This enables more efficient backends. See the docstring of
414 414
415** Package 415** Package
416 416
417*** New macro `package-get-version` lets packages query their own version
418Example use in auctex.el: (defconst auctex-version (package-get-version))
419
417*** New 'package-quickstart' feature. 420*** New 'package-quickstart' feature.
418When 'package-quickstart' is non-nil, package.el precomputes a big autoloads 421When 'package-quickstart' is non-nil, package.el precomputes a big autoloads
419file so that activation of packages can be done much faster, which can speed up 422file so that activation of packages can be done much faster, which can speed up
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 2ddab653630..06e9956da4a 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -689,8 +689,9 @@ PKG-DESC is a `package-desc' object."
689Load the autoloads file, and ensure `load-path' is setup. If 689Load the autoloads file, and ensure `load-path' is setup. If
690RELOAD is non-nil, also load all files in the package that 690RELOAD is non-nil, also load all files in the package that
691correspond to previously loaded files." 691correspond to previously loaded files."
692 (let* ((loaded-files-list (when reload 692 (let* ((loaded-files-list
693 (package--list-loaded-files (package-desc-dir pkg-desc))))) 693 (when reload
694 (package--list-loaded-files (package-desc-dir pkg-desc)))))
694 ;; Add to load path, add autoloads, and activate the package. 695 ;; Add to load path, add autoloads, and activate the package.
695 (package--activate-autoloads-and-load-path pkg-desc) 696 (package--activate-autoloads-and-load-path pkg-desc)
696 ;; Call `load' on all files in `package-desc-dir' already present in 697 ;; Call `load' on all files in `package-desc-dir' already present in
@@ -3450,6 +3451,36 @@ The list is displayed in a buffer named `*Packages*'."
3450 (interactive) 3451 (interactive)
3451 (list-packages t)) 3452 (list-packages t))
3452 3453
3454;;;###autoload
3455(defmacro package-get-version ()
3456 "Return the version number of the package in which this is used.
3457Assumes it is used from an Elisp file placed inside the top-level directory
3458of an installed ELPA package.
3459The return value is a string (or nil in case we can't find it)."
3460 ;; Hack alert!
3461 (let ((file
3462 (or (if (boundp 'byte-compile-current-file) byte-compile-current-file)
3463 load-file-name
3464 buffer-file-name)))
3465 (cond
3466 ((null file) nil)
3467 ;; Packages are normally installed into directories named "<pkg>-<vers>",
3468 ;; so get the version number from there.
3469 ((string-match "/[^/]+-\\([0-9]\\(?:[0-9.]\\|pre\\|beta\\|alpha\\|snapshot\\)+\\)/[^/]+\\'" file)
3470 (match-string 1 file))
3471 ;; For packages run straight from the an elpa.git clone, there's no
3472 ;; "-<vers>" in the directory name, so we have to fetch the version
3473 ;; the hard way.
3474 (t
3475 (let* ((pkgdir (file-name-directory file))
3476 (pkgname (file-name-nondirectory (directory-file-name pkgdir)))
3477 (mainfile (expand-file-name (concat pkgname ".el") pkgdir)))
3478 (when (file-readable-p mainfile)
3479 (with-temp-buffer
3480 (insert-file-contents mainfile)
3481 (or (lm-header "package-version")
3482 (lm-header "version")))))))))
3483
3453;;;; Quickstart: precompute activation actions for faster start up. 3484;;;; Quickstart: precompute activation actions for faster start up.
3454 3485
3455;; Activating packages via `package-initialize' is costly: for N installed 3486;; Activating packages via `package-initialize' is costly: for N installed