mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-11-25 07:28:20 +00:00
Add the public API of Compat to the core
* lisp/emacs-lisp/compat.el: Add stub file with minimal definitions, so that core packages, that haven't been installed from ELPA, can make use of the public API and use more recent function signatures. * lisp/progmodes/python.el (compat): Remove 'noerror flag, because Compat can now be required without the real package being available. * doc/lispref/package.texi (Forwards-Compatibility): Mention Compat and link to the manual. * etc/NEWS: Document change. (Bug#66554)
This commit is contained in:
parent
c0f656617d
commit
db195116a4
@ -28,6 +28,7 @@ these archives).
|
||||
* Multi-file Packages:: How to package multiple files.
|
||||
* Package Archives:: Maintaining package archives.
|
||||
* Archive Web Server:: Interfacing to an archive web server.
|
||||
* Forwards-Compatibility:: Supporting older versions of Emacs.
|
||||
@end menu
|
||||
|
||||
@node Packaging Basics
|
||||
@ -399,3 +400,50 @@ Return the file. This will be the tarball for a multi-file
|
||||
package, or the single file for a simple package.
|
||||
|
||||
@end table
|
||||
|
||||
@node Forwards-Compatibility
|
||||
@section Supporting older versions of Emacs
|
||||
@cindex compatibility compat
|
||||
|
||||
Packages that wish to support older releases of Emacs, without giving
|
||||
up on newer functionality from recent Emacs releases, one can make use
|
||||
of the Compat package on GNU ELPA. By depending on the package, Emacs
|
||||
can provide compatibility definitions for missing functionality.
|
||||
|
||||
The versioning of Compat follows that of Emacs, so next to the oldest
|
||||
version that a package relies on (via the @code{emacs}-package), one
|
||||
can also indicate what the newest version of Emacs is, that a package
|
||||
wishes to use definitions from:
|
||||
|
||||
@example
|
||||
;; Package-Requires: ((emacs "27.2") (compat "29.1"))
|
||||
@end example
|
||||
|
||||
Note that Compat provides replacement functions with extended
|
||||
functionality for functions that are already defined (@code{sort},
|
||||
@code{assoc}, @dots{}). These functions may have changed their
|
||||
calling convention (additional optional arguments) or may have changed
|
||||
their behavior. These functions must be looked up explicitly with
|
||||
@code{compat-function} or called explicitly with @code{compat-call}.
|
||||
We call them @dfn{Extended Definitions}. In contrast, newly @dfn{Added
|
||||
Definitions} can be called as usual.
|
||||
|
||||
@defmac compat-call fun &rest args
|
||||
This macro calls the compatibility function @var{fun} with @var{args}.
|
||||
Many functions provided by Compat can be called directly without this
|
||||
macro. However in the case where Compat provides an alternative
|
||||
version of an existing function, the function call has to go through
|
||||
@code{compat-call}.
|
||||
@end defmac
|
||||
|
||||
@defmac compat-function fun
|
||||
This macro returns the compatibility function symbol for @var{fun}.
|
||||
See @code{compat-call} for a more convenient macro to directly call
|
||||
compatibility functions.
|
||||
@end defmac
|
||||
|
||||
For further details on how to make use of the package, see
|
||||
@ref{Usage,, Usage, compat, "Compat" Manual}. In case you don't have
|
||||
the manual installed, you can also read the
|
||||
@url{https://elpa.gnu.org/packages/doc/compat.html#Usage, Online
|
||||
Compat manual}.
|
||||
|
7
etc/NEWS
7
etc/NEWS
@ -1396,6 +1396,13 @@ This minor mode generates the tags table automatically based on the
|
||||
current project configuration, and later updates it as you edit the
|
||||
files and save the changes.
|
||||
|
||||
+++
|
||||
** New package Compat
|
||||
Emacs now comes with a stub implementation of the
|
||||
forwards-compatibility Compat package from GNU ELPA. This allows
|
||||
built-in packages to use the library more effectively, and helps
|
||||
preventing the installation of Compat if unnecessary.
|
||||
|
||||
|
||||
* Incompatible Lisp Changes in Emacs 30.1
|
||||
|
||||
|
92
lisp/emacs-lisp/compat.el
Normal file
92
lisp/emacs-lisp/compat.el
Normal file
@ -0,0 +1,92 @@
|
||||
;;; compat.el --- Stub of the Compatibility Library -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: \
|
||||
;; Philip Kaludercic <philipk@posteo.net>, \
|
||||
;; Daniel Mendler <mail@daniel-mendler.de>
|
||||
;; Maintainer: \
|
||||
;; Daniel Mendler <mail@daniel-mendler.de>, \
|
||||
;; Compat Development <~pkal/compat-devel@lists.sr.ht>,
|
||||
;; emacs-devel@gnu.org
|
||||
;; URL: https://github.com/emacs-compat/compat
|
||||
;; Keywords: lisp, maint
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; The Compat package on ELPA provides forward-compatibility
|
||||
;; definitions for other packages. While mostly transparent, a
|
||||
;; minimal API is necessary whenever core definitions change calling
|
||||
;; conventions (e.g. `plist-get' can be invoked with a predicate from
|
||||
;; Emacs 29.1 onward). For core packages on ELPA to be able to take
|
||||
;; advantage of this functionality, the macros `compat-function' and
|
||||
;; `compat-call' have to be available in the core, usable even if
|
||||
;; users do not have the Compat package installed, which this file
|
||||
;; ensures.
|
||||
|
||||
;; A basic introduction to Compat is given in the Info node `(elisp)
|
||||
;; Forwards Compatibility'. Further details on Compat are documented
|
||||
;; in the Info node `(compat) Top' (installed along with the Compat
|
||||
;; package) or read the same manual online:
|
||||
;; https://elpa.gnu.org/packages/doc/compat.html.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defmacro compat-function (fun)
|
||||
"Return compatibility function symbol for FUN.
|
||||
This is a pseudo-compatibility stub for core packages on ELPA,
|
||||
that depend on the Compat package, whenever the user doesn't have
|
||||
the package installed on their current system."
|
||||
`#',fun)
|
||||
|
||||
(defmacro compat-call (fun &rest args)
|
||||
"Call compatibility function or macro FUN with ARGS.
|
||||
This is a pseudo-compatibility stub for core packages on ELPA,
|
||||
that depend on the Compat package, whenever the user doesn't have
|
||||
the package installed on their current system."
|
||||
(cons fun args))
|
||||
|
||||
;;;; Clever trick to avoid installing Compat if not necessary
|
||||
|
||||
;; The versioning scheme of the Compat package follows that of Emacs,
|
||||
;; to indicate the version of Emacs, that functionality is being
|
||||
;; provided for. For example, the Compat version number 29.2.3.9
|
||||
;; would attempt to provide compatibility definitions up to Emacs
|
||||
;; 29.2, while also designating that this is the third major release
|
||||
;; and ninth minor release of Compat, for the specific Emacs release.
|
||||
|
||||
;; The package version of this file is specified programmatically,
|
||||
;; instead of giving a fixed version in the header of this file. This
|
||||
;; is done to ensure that the version of compat.el provided by Emacs
|
||||
;; always corresponds to the current version of Emacs. In addition to
|
||||
;; the major-minor version, a large "major release" makes sure that
|
||||
;; the built-in version of Compat is always preferred over an external
|
||||
;; installation. This means that if a package specifies a dependency
|
||||
;; on Compat which matches the current or an older version of Emacs
|
||||
;; that is being used, no additional dependencies have to be
|
||||
;; downloaded.
|
||||
;;
|
||||
;; Further details and background on this file can be found in the
|
||||
;; bug#66554 discussion.
|
||||
|
||||
;;;###autoload (push (list 'compat
|
||||
;;;###autoload emacs-major-version
|
||||
;;;###autoload emacs-minor-version
|
||||
;;;###autoload 9999)
|
||||
;;;###autoload package--builtin-versions)
|
||||
|
||||
(provide 'compat)
|
||||
;;; compat.el ends here
|
@ -273,7 +273,7 @@
|
||||
(eval-when-compile (require 'subr-x)) ;For `string-empty-p' and `string-join'.
|
||||
(require 'treesit)
|
||||
(require 'pcase)
|
||||
(require 'compat nil 'noerror)
|
||||
(require 'compat)
|
||||
(require 'project nil 'noerror)
|
||||
(require 'seq)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user