diff options
author | Stefan Kangas <stefankangas@gmail.com> | 2023-12-22 23:41:36 +0100 |
---|---|---|
committer | Stefan Kangas <stefankangas@gmail.com> | 2023-12-23 01:31:26 +0100 |
commit | bb5399e3cd75450db6db9b3c5829f7bd87ca1308 (patch) | |
tree | 35f1539dc7087a74429a96de5999f49a64a2cdd1 /lisp/emacs-lisp/lisp-mnt.el | |
parent | 9cb85e950dac77b59d48d320c7d40689d019aad4 (diff) | |
download | emacs-bb5399e3cd75450db6db9b3c5829f7bd87ca1308.tar.gz emacs-bb5399e3cd75450db6db9b3c5829f7bd87ca1308.tar.bz2 emacs-bb5399e3cd75450db6db9b3c5829f7bd87ca1308.zip |
Introduce new function lm-package-requires
* lisp/emacs-lisp/package.el (package--prepare-dependencies): Move
from here...
* lisp/emacs-lisp/lisp-mnt.el (lm--prepare-package-dependencies):
...to here.
(lm-package-requires): New function.
(package-buffer-info): Use above new function.
* test/lisp/emacs-lisp/lisp-mnt-tests.el
(lm--tests-lm-package-requires): New test.
Diffstat (limited to 'lisp/emacs-lisp/lisp-mnt.el')
-rw-r--r-- | lisp/emacs-lisp/lisp-mnt.el | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el index cb7cff43555..2c7c6816e9c 100644 --- a/lisp/emacs-lisp/lisp-mnt.el +++ b/lisp/emacs-lisp/lisp-mnt.el @@ -434,6 +434,38 @@ This can be found in an RCS or SCCS header." header-max t) (match-string-no-properties 1))))))) +(defun lm--prepare-package-dependencies (deps) + "Turn DEPS into an acceptable list of dependencies. + +Any parts missing a version string get a default version string +of \"0\" (meaning any version) and an appropriate level of lists +is wrapped around any parts requiring it." + (cond + ((not (listp deps)) + (error "Invalid requirement specifier: %S" deps)) + (t (mapcar (lambda (dep) + (cond + ((symbolp dep) `(,dep "0")) + ((stringp dep) + (error "Invalid requirement specifier: %S" dep)) + ((and (listp dep) (null (cdr dep))) + (list (car dep) "0")) + (t dep))) + deps)))) + +(declare-function package-read-from-string "package" (str)) + +(defun lm-package-requires (&optional file) + "Return dependencies listed in file FILE, or current buffer if FILE is nil. +The return value is a list of elements of the form (PACKAGE VERSION) +where PACKAGE is the package name (a symbol) and VERSION is the +package version (a string)." + (require 'package) + (lm-with-file file + (and-let* ((require-lines (lm-header-multiline "package-requires"))) + (lm--prepare-package-dependencies + (package-read-from-string (mapconcat #'identity require-lines " ")))))) + (defun lm-keywords (&optional file) "Return the keywords given in file FILE, or current buffer if FILE is nil. The return is a `downcase'-ed string, or nil if no keywords |