From 0401b4f71bfa885e38c4f2ae0699f2da63b701b1 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Tue, 11 Feb 2025 06:10:39 +0100 Subject: [PATCH] Add new function lm-package-version * lisp/emacs-lisp/lisp-mnt.el (lm-package-version): New function. * lisp/emacs-lisp/package.el (package-buffer-info) (package-get-version): Use above new function. (lm-package-version): Declare. (cherry picked from commit e6a2256c8b7357f9654a566e31647316f44780c3) --- lisp/emacs-lisp/lisp-mnt.el | 7 +++++++ lisp/emacs-lisp/package.el | 12 +++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el index e45a762ccf8..826fac0b644 100644 --- a/lisp/emacs-lisp/lisp-mnt.el +++ b/lisp/emacs-lisp/lisp-mnt.el @@ -469,6 +469,13 @@ package version (a string)." (error "Can't read whole string")) (end-of-file expr)))))))) +(defun lm-package-version (&optional file) + "Return \"Package-Version\" or \"Version\" header. +Prefer Package-Version; if defined, the package author +probably wants us to use it. Otherwise try Version." + (lm-with-file file + (or (lm-header "package-version") (lm-header "version")))) + (defun lm-package-needs-footer-line (&optional file) "Return non-nil if package in current buffer needs a footer line. diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 788735347b8..31e9f6823e6 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1168,6 +1168,7 @@ Signal an error if the entire string was not used." (declare-function lm-header "lisp-mnt" (header)) (declare-function lm-package-requires "lisp-mnt" (&optional file)) +(declare-function lm-package-version "lisp-mnt" (&optional file)) (declare-function lm-website "lisp-mnt" (&optional file)) (declare-function lm-keywords-list "lisp-mnt" (&optional file)) (declare-function lm-maintainers "lisp-mnt" (&optional file)) @@ -1185,11 +1186,7 @@ boundaries." (let ((file-name (match-string-no-properties 1)) (desc (match-string-no-properties 2))) (require 'lisp-mnt) - ;; Use some headers we've invented to drive the process. - (let* (;; Prefer Package-Version; if defined, the package author - ;; probably wants us to use it. Otherwise try Version. - (version-info - (or (lm-header "package-version") (lm-header "version"))) + (let* ((version-info (lm-package-version)) (pkg-version (package-strip-rcs-id version-info)) (keywords (lm-keywords-list)) (website (lm-website))) @@ -4552,10 +4549,7 @@ the `Version:' header." (unless (file-readable-p mainfile) (setq mainfile file)) (when (file-readable-p mainfile) (require 'lisp-mnt) - (with-temp-buffer - (insert-file-contents mainfile) - (or (lm-header "package-version") - (lm-header "version"))))))))) + (lm-package-version mainfile))))))) ;;;; Quickstart: precompute activation actions for faster start up. -- 2.39.5