diff options
| author | Stefan Kangas | 2024-07-06 16:41:33 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2024-07-06 18:57:37 +0200 |
| commit | c302c5fab0c8dee12e7b19925452871ddb09c0b2 (patch) | |
| tree | ef20e450e001ccafd1476d2d8e19c43046d36c05 | |
| parent | 38ce85c547cac4023260be37f1b60af2c1f22d20 (diff) | |
| download | emacs-c302c5fab0c8dee12e7b19925452871ddb09c0b2.tar.gz emacs-c302c5fab0c8dee12e7b19925452871ddb09c0b2.zip | |
Add new function `lm-package-needs-footer-line`
* lisp/emacs-lisp/lisp-mnt.el (lm-package-needs-footer-line):
Factor out new function...
* lisp/emacs-lisp/package.el (package-buffer-info): ...from here.
* lisp/emacs-lisp/lisp-mnt.el (lm-verify): Use above new function.
* test/lisp/emacs-lisp/lisp-mnt-tests.el
(lm-tests--lm-package-needs-footer-line/empty-dependencies)
(lm-tests--lm-package-needs-footer-line/old-version)
(lm-tests--lm-package-needs-footer-line/new-version):
New tests.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mnt.el | 43 | ||||
| -rw-r--r-- | lisp/emacs-lisp/package.el | 13 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/lisp-mnt-tests.el | 13 |
3 files changed, 51 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el index f111a77663c..841f1ce3b9c 100644 --- a/lisp/emacs-lisp/lisp-mnt.el +++ b/lisp/emacs-lisp/lisp-mnt.el | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | ;;; lisp-mnt.el --- utility functions for Emacs Lisp maintainers -*- lexical-binding:t -*- | 1 | ;;; lisp-mnt.el --- utility functions for Emacs Lisp maintainers -*- lexical-binding:t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1992, 1994, 1997, 2000-2024 Free Software Foundation, | 3 | ;; Copyright (C) 1992-2024 Free Software Foundation, Inc. |
| 4 | ;; Inc. | ||
| 5 | 4 | ||
| 6 | ;; Author: Eric S. Raymond <esr@thyrsus.com> | 5 | ;; Author: Eric S. Raymond <esr@thyrsus.com> |
| 7 | ;; Maintainer: emacs-devel@gnu.org | 6 | ;; Maintainer: emacs-devel@gnu.org |
| @@ -106,8 +105,10 @@ | |||
| 106 | ;; * Code line --- exists so Lisp can know where commentary and/or | 105 | ;; * Code line --- exists so Lisp can know where commentary and/or |
| 107 | ;; change-log sections end. | 106 | ;; change-log sections end. |
| 108 | ;; | 107 | ;; |
| 109 | ;; * Footer line --- marks end-of-file so it can be distinguished from | 108 | ;; * Footer line --- marks end-of-file so it can be distinguished |
| 110 | ;; an expanded formfeed or the results of truncation. | 109 | ;; from an expanded formfeed or the results of truncation. This is |
| 110 | ;; required for a package to be installable by package.el in Emacs 29.1 | ||
| 111 | ;; or earlier, but is optional in later versions. | ||
| 111 | 112 | ||
| 112 | ;;; Code: | 113 | ;;; Code: |
| 113 | 114 | ||
| @@ -467,6 +468,29 @@ package version (a string)." | |||
| 467 | (lm--prepare-package-dependencies | 468 | (lm--prepare-package-dependencies |
| 468 | (package-read-from-string (mapconcat #'identity require-lines " ")))))) | 469 | (package-read-from-string (mapconcat #'identity require-lines " ")))))) |
| 469 | 470 | ||
| 471 | (defun lm-package-needs-footer-line (&optional file) | ||
| 472 | "Return non-nil if package in current buffer needs a footer line. | ||
| 473 | |||
| 474 | Footer lines (sometimes referred to as \"terminating comments\") look | ||
| 475 | like this: | ||
| 476 | |||
| 477 | ;;; some-cool-package.el ends here | ||
| 478 | |||
| 479 | Such lines are required for a package to be installable by package.el in | ||
| 480 | Emacs 29.1 or earlier, but are optional in later versions. If the | ||
| 481 | package depends on a version of Emacs where package.el requires such | ||
| 482 | comments, or if no version requirement is specified, return non-nil. | ||
| 483 | |||
| 484 | If optional argument FILE is non-nil, use that file instead of the | ||
| 485 | current buffer." | ||
| 486 | (lm-with-file file | ||
| 487 | ;; Starting in Emacs 30.1, avoid warning if the minimum Emacs | ||
| 488 | ;; version is specified as 30.1 or later. | ||
| 489 | (let ((min-emacs (cadar (seq-filter (lambda (x) (eq (car x) 'emacs)) | ||
| 490 | (lm-package-requires))))) | ||
| 491 | (or (null min-emacs) | ||
| 492 | (version< min-emacs "30.1"))))) | ||
| 493 | |||
| 470 | (defun lm-keywords (&optional file) | 494 | (defun lm-keywords (&optional file) |
| 471 | "Return the keywords given in file FILE, or current buffer if FILE is nil. | 495 | "Return the keywords given in file FILE, or current buffer if FILE is nil. |
| 472 | The return is a `downcase'-ed string, or nil if no keywords | 496 | The return is a `downcase'-ed string, or nil if no keywords |
| @@ -593,11 +617,12 @@ copyright notice is allowed." | |||
| 593 | ((not (lm-code-start)) | 617 | ((not (lm-code-start)) |
| 594 | "Can't find a `Code' section marker") | 618 | "Can't find a `Code' section marker") |
| 595 | ((progn | 619 | ((progn |
| 596 | (goto-char (point-max)) | 620 | (when (lm-package-needs-footer-line) |
| 597 | (not | 621 | (goto-char (point-max)) |
| 598 | (re-search-backward | 622 | (not |
| 599 | (rx bol ";;; " (regexp name) " ends here") | 623 | (re-search-backward |
| 600 | nil t))) | 624 | (rx bol ";;; " (regexp name) " ends here") |
| 625 | nil t)))) | ||
| 601 | "Can't find the footer line") | 626 | "Can't find the footer line") |
| 602 | ((not (and (lm-copyright-mark) (lm-crack-copyright))) | 627 | ((not (and (lm-copyright-mark) (lm-crack-copyright))) |
| 603 | "Can't find a valid copyright notice") | 628 | "Can't find a valid copyright notice") |
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index fac824d44a4..b0ba886df74 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -1174,23 +1174,18 @@ boundaries." | |||
| 1174 | (let ((file-name (match-string-no-properties 1)) | 1174 | (let ((file-name (match-string-no-properties 1)) |
| 1175 | (desc (match-string-no-properties 2)) | 1175 | (desc (match-string-no-properties 2)) |
| 1176 | (start (line-beginning-position))) | 1176 | (start (line-beginning-position))) |
| 1177 | (require 'lisp-mnt) | ||
| 1177 | ;; This warning was added in Emacs 27.1, and should be removed at | 1178 | ;; This warning was added in Emacs 27.1, and should be removed at |
| 1178 | ;; the earliest in version 31.1. The idea is to phase out the | 1179 | ;; the earliest in version 31.1. The idea is to phase out the |
| 1179 | ;; requirement for a "footer line" without unduly impacting users | 1180 | ;; requirement for a "footer line" without unduly impacting users |
| 1180 | ;; on earlier Emacs versions. See Bug#26490 for more details. | 1181 | ;; on earlier Emacs versions. See Bug#26490 for more details. |
| 1181 | (unless (search-forward (concat ";;; " file-name ".el ends here") nil 'move) | 1182 | (unless (search-forward (concat ";;; " file-name ".el ends here") nil 'move) |
| 1182 | ;; Starting in Emacs 30.1, avoid warning if the minimum Emacs | 1183 | (when (lm-package-needs-footer-line) |
| 1183 | ;; version is specified as 30.1 or later. | 1184 | (lwarn '(package package-format) :warning |
| 1184 | (let ((min-emacs (cadar (seq-filter (lambda (x) (eq (car x) 'emacs)) | 1185 | "Package lacks a terminating comment"))) |
| 1185 | (lm-package-requires))))) | ||
| 1186 | (when (or (null min-emacs) | ||
| 1187 | (version< min-emacs "30.1")) | ||
| 1188 | (lwarn '(package package-format) :warning | ||
| 1189 | "Package lacks a terminating comment")))) | ||
| 1190 | ;; Try to include a trailing newline. | 1186 | ;; Try to include a trailing newline. |
| 1191 | (forward-line) | 1187 | (forward-line) |
| 1192 | (narrow-to-region start (point)) | 1188 | (narrow-to-region start (point)) |
| 1193 | (require 'lisp-mnt) | ||
| 1194 | ;; Use some headers we've invented to drive the process. | 1189 | ;; Use some headers we've invented to drive the process. |
| 1195 | (let* (;; Prefer Package-Version; if defined, the package author | 1190 | (let* (;; Prefer Package-Version; if defined, the package author |
| 1196 | ;; probably wants us to use it. Otherwise try Version. | 1191 | ;; probably wants us to use it. Otherwise try Version. |
diff --git a/test/lisp/emacs-lisp/lisp-mnt-tests.el b/test/lisp/emacs-lisp/lisp-mnt-tests.el index e32480ada46..147062cba29 100644 --- a/test/lisp/emacs-lisp/lisp-mnt-tests.el +++ b/test/lisp/emacs-lisp/lisp-mnt-tests.el | |||
| @@ -49,6 +49,19 @@ | |||
| 49 | (project "0.9.8") (xref "1.6.2") (eldoc "1.14.0") | 49 | (project "0.9.8") (xref "1.6.2") (eldoc "1.14.0") |
| 50 | (seq "2.23") (external-completion "0.1")))))) | 50 | (seq "2.23") (external-completion "0.1")))))) |
| 51 | 51 | ||
| 52 | (ert-deftest lm-tests--lm-package-needs-footer-line/empty-dependencies () | ||
| 53 | (with-temp-buffer | ||
| 54 | (should (lm-package-needs-footer-line)))) | ||
| 55 | |||
| 56 | (ert-deftest lm-tests--lm-package-needs-footer-line/old-version () | ||
| 57 | (with-temp-buffer | ||
| 58 | (insert ";; Package-Requires: ((emacs \"29.1\"))\n") | ||
| 59 | (should (lm-package-needs-footer-line)))) | ||
| 60 | |||
| 61 | (ert-deftest lm-tests--lm-package-needs-footer-line/new-version () | ||
| 62 | (with-temp-buffer | ||
| 63 | (insert ";; Package-Requires: ((emacs \"30.1\"))\n") | ||
| 64 | (should (not (lm-package-needs-footer-line))))) | ||
| 52 | 65 | ||
| 53 | (ert-deftest lm--tests-lm-website () | 66 | (ert-deftest lm--tests-lm-website () |
| 54 | (with-temp-buffer | 67 | (with-temp-buffer |