[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 10033e0 01/99: Initial import
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 10033e0 01/99: Initial import |
Date: |
Sun, 17 Oct 2021 05:57:46 -0400 (EDT) |
branch: externals/compat
commit 10033e07a89e3405ee27797e67cb1c4521e4f5a2
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Initial import
---
.build.yml | 10 +
.dir-locals.el | 4 +
.elpaignore | 3 +
.gitignore | 5 +
COPYING | 674 +++++++++++++++++++++++++++++++
Makefile | 28 ++
README | 62 +++
compat-24.2.el | 60 +++
compat-24.3.el | 44 ++
compat-24.4.el | 142 +++++++
compat-25.1.el | 239 +++++++++++
compat-26.1.el | 286 +++++++++++++
compat-27.1.el | 271 +++++++++++++
compat-28.1.el | 456 +++++++++++++++++++++
compat-macs.el | 245 ++++++++++++
compat-tests.el | 1195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
compat.el | 90 +++++
17 files changed, 3814 insertions(+)
diff --git a/.build.yml b/.build.yml
new file mode 100644
index 0000000..3d6d760
--- /dev/null
+++ b/.build.yml
@@ -0,0 +1,10 @@
+image: alpine/edge
+packages:
+- emacs
+tasks:
+- setup: |
+ apk add emacs
+- build: |
+ make -C compat compile
+- check: |
+ make -C compat test
\ No newline at end of file
diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000..1f7c4b7
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,4 @@
+;;; Directory Local Variables
+;;; For more information see (info "(emacs) Directory Variables")
+
+((emacs-lisp-mode . ((indent-tabs-mode . nil))))
diff --git a/.elpaignore b/.elpaignore
new file mode 100644
index 0000000..8969c4b
--- /dev/null
+++ b/.elpaignore
@@ -0,0 +1,3 @@
+compat-tests.el
+Makefile
+.build.yml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a3d210a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.elc
+*~
+\#*\#
+/compat-pkg.el
+/compat-autoloads.el
\ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..ba8389a
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e218aa6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,28 @@
+.POSIX:
+.PHONY: all compile test clean
+.SUFFIXES: .el .elc
+
+EMACS = emacs
+BYTEC = compat-24.2.elc \
+ compat-24.3.elc \
+ compat-24.4.elc \
+ compat-25.1.elc \
+ compat-26.1.elc \
+ compat-27.1.elc \
+ compat-28.1.elc \
+ compat-macs.elc \
+ compat.elc
+
+all: compile test
+
+compile: $(BYTEC)
+
+test:
+ $(EMACS) -Q --batch -L . -l compat-tests.el -f
ert-run-tests-batch-and-exit
+
+clean:
+ rm -f $(BYTEC)
+
+.el.elc:
+ $(EMACS) -Q --batch -L . -f batch-byte-compile $^
+
diff --git a/README b/README
new file mode 100644
index 0000000..0a40bae
--- /dev/null
+++ b/README
@@ -0,0 +1,62 @@
+* COMPATibility Library for Emacs -*- mode: outline; -*-
+
+Find here the source for compat.el, a forwards-compatibility library
+for (GNU) Emacs Lisp.
+
+The intended audience of this library aren't day-to-day users, but
+package developers that wish to make use of newer functionality, not
+provided in older versions of Emacs, without breaking compatibility
+for users bound to specific Emacs releases.
+
+** Installation
+
+compat.el shouldn't be installed directly, but downloaded from GNU
+ELPA. If necessary, this can be done using M-x package-install-file
+in the current working directory.
+
+** Usage
+
+The intended use-case for this library is for package developers to
+add as a dependency in the header:
+
+ ;; Package-Requires: ((emacs "24.3") (compat "28.1.0.0"))
+
+No further action should be required afterwards. The effect should be
+that all the functions and macros that compat.el provides are
+automatically accessible or made accessible as soon as the right
+libraries are loaded.
+
+** Contribute
+
+As compat.el is distribed as part of GNU ELPA, and therefore requires
+a copyright assignment to the FSF, for all non-trivial code
+contributions:
+
+
https://www.gnu.org/software/emacs/manual/html_node/emacs/Copyright-Assignment.html
+
+*** Source code
+
+The project is managed can be found on SourceHut
+
+ https://sr.ht/~pkal/compat
+
+but has a (disfavoured) GitHub mirror as well
+
+ https://github.com/phikal/compat.el
+
+*** Bug and patches
+
+Patches, bug reports and comments can be sent to the mailing list
+
+ ~pkal/public-inbox@lists.sr.ht
+
+When contributing, make sure to provide test and use the existing
+tests defined in compat-test.el. These can be easily executed using
+the bundled Makefile:
+
+ make test
+
+** Distribution
+
+compat.el and all other files in this directory are distributed under
+the GPL, Version 3 (like Emacs itself).
diff --git a/compat-24.2.el b/compat-24.2.el
new file mode 100644
index 0000000..bc1a15d
--- /dev/null
+++ b/compat-24.2.el
@@ -0,0 +1,60 @@
+;;; compat-24.2.el --- Compatibility Layer for Emacs 24.2 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 24.2, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in subr.el
+
+(compat-defun autoloadp (object)
+ "Non-nil if OBJECT is an autoload."
+ (eq 'autoload (car-safe object)))
+
+(compat-defun buffer-narrowed-p ()
+ "Return non-nil if the current buffer is narrowed."
+ (/= (- (point-max) (point-min)) (buffer-size)))
+
+(compat-defun posnp (obj)
+ "Return non-nil if OBJ appears to be a valid position.
+A `posn' object is returned from functions such as `event-start'.
+If OBJ is a valid `posn' object, but specifies a frame rather
+than a window, return nil."
+ (and (windowp (car-safe obj))
+ (atom (car-safe (setq obj (cdr obj)))) ;AREA-OR-POS.
+ (integerp (car-safe (car-safe (setq obj (cdr obj))))) ;XOFFSET.
+ (integerp (car-safe (cdr obj)))))
+
+;;;; Defined in files.el
+
+(compat-defun file-name-base (filename)
+ "Return the base name of the FILENAME: no directory, no extension."
+ (file-name-sans-extension
+ (file-name-nondirectory (or filename (buffer-file-name)))))
+
+(provide 'compat-24.2)
+;;; compat-24.2.el ends here
diff --git a/compat-24.3.el b/compat-24.3.el
new file mode 100644
index 0000000..93a7be3
--- /dev/null
+++ b/compat-24.3.el
@@ -0,0 +1,44 @@
+;;; compat-24.3.el --- Compatibility Layer for Emacs 24.3 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 24.3, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in subr.el
+
+(compat-defmacro defvar-local (var val &optional docstring)
+ "Define VAR as a buffer-local variable with default value VAL.
+Like `defvar' but additionally marks the variable as being automatically
+buffer-local wherever it is set."
+ (declare (debug defvar) (doc-string 3))
+ `(progn
+ (defvar ,var ,val ,docstring)
+ (make-variable-buffer-local ',var)))
+
+(provide 'compat-24.3)
+;;; compat-24.3.el ends here
diff --git a/compat-24.4.el b/compat-24.4.el
new file mode 100644
index 0000000..b744562
--- /dev/null
+++ b/compat-24.4.el
@@ -0,0 +1,142 @@
+;;; compat-24.4.el --- Compatibility Layer for Emacs 24.4 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 24.4, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in data.c
+
+(compat-advise = (number-or-marker &rest numbers-or-markers)
+ "Handle multiple arguments."
+ (catch 'fail
+ (while numbers-or-markers
+ (unless (funcall oldfun number-or-marker (car numbers-or-markers))
+ (throw 'fail nil))
+ (setq number-or-marker (pop numbers-or-markers)))
+ t))
+
+(compat-advise < (number-or-marker &rest numbers-or-markers)
+ "Handle multiple arguments."
+ (catch 'fail
+ (while numbers-or-markers
+ (unless (funcall oldfun number-or-marker (car numbers-or-markers))
+ (throw 'fail nil))
+ (setq number-or-marker (pop numbers-or-markers)))
+ t))
+
+(compat-advise > (number-or-marker &rest numbers-or-markers)
+ "Handle multiple arguments."
+ (catch 'fail
+ (while numbers-or-markers
+ (unless (funcall oldfun number-or-marker (car numbers-or-markers))
+ (throw 'fail nil))
+ (setq number-or-marker (pop numbers-or-markers)))
+ t))
+
+(compat-advise <= (number-or-marker &rest numbers-or-markers)
+ "Handle multiple arguments."
+ (catch 'fail
+ (while numbers-or-markers
+ (unless (funcall oldfun number-or-marker (car numbers-or-markers))
+ (throw 'fail nil))
+ (setq number-or-marker (pop numbers-or-markers)))
+ t))
+
+(compat-advise >= (number-or-marker &rest numbers-or-markers)
+ "Handle multiple arguments."
+ (catch 'fail
+ (while numbers-or-markers
+ (unless (funcall oldfun number-or-marker (pop numbers-or-markers))
+ (throw 'fail nil)))
+ t))
+
+;;;; Defined in subr.el
+
+(compat-defmacro with-eval-after-load (file &rest body)
+ "Execute BODY after FILE is loaded.
+FILE is normally a feature name, but it can also be a file name,
+in case that file does not provide any feature. See `eval-after-load'
+for more details about the different forms of FILE and their semantics."
+ (declare (indent 1) (debug (form def-body)))
+ `(eval-after-load ,file (lambda () ,@body)))
+
+(compat-defun special-form-p (object)
+ "Non-nil if and only if OBJECT is a special form."
+ (if (and (symbolp object) (fboundp object))
+ (setq object (indirect-function object)))
+ (and (subrp object) (eq (cdr (subr-arity object)) 'unevalled)))
+
+(compat-defun macrop (object)
+ "Non-nil if and only if OBJECT is a macro."
+ (let ((def (indirect-function object)))
+ (when (consp def)
+ (or (eq 'macro (car def))
+ (and (autoloadp def) (memq (nth 4 def) '(macro t)))))))
+
+(compat-defun string-suffix-p (suffix string &optional ignore-case)
+ "Return non-nil if SUFFIX is a suffix of STRING.
+If IGNORE-CASE is non-nil, the comparison is done without paying
+attention to case differences."
+ (let ((start-pos (- (length string) (length suffix))))
+ (and (>= start-pos 0)
+ (eq t (compare-strings suffix nil nil
+ string start-pos nil ignore-case)))))
+
+(compat-advise split-string (string &optional separators omit-nulls trim)
+ "Handle optional argument TRIM."
+ (let* ((token (funcall oldfun string separators omit-nulls))
+ (trimmed (if trim
+ (mapcar
+ (lambda (token)
+ (when (string-match (concat "\\`" trim) token)
+ (setq token (substring token (match-end 0))))
+ (when (string-match (concat trim "\\'") token)
+ (setq token (substring token 0 (match-beginning
0))))
+ token)
+ token)
+ token)))
+ (if omit-nulls (delete "" trimmed) trimmed)))
+
+(compat-defun delete-consecutive-dups (list &optional circular)
+ "Destructively remove `equal' consecutive duplicates from LIST.
+First and last elements are considered consecutive if CIRCULAR is
+non-nil."
+ (let ((tail list) last)
+ (while (cdr tail)
+ (if (equal (car tail) (cadr tail))
+ (setcdr tail (cddr tail))
+ (setq last tail
+ tail (cdr tail))))
+ (if (and circular
+ last
+ (equal (car tail) (car list)))
+ (setcdr last nil)))
+ list)
+
+(provide 'compat-24.4)
+;;; compat-24.4.el ends here
diff --git a/compat-25.1.el b/compat-25.1.el
new file mode 100644
index 0000000..a8010e0
--- /dev/null
+++ b/compat-25.1.el
@@ -0,0 +1,239 @@
+;;; compat-25.1.el --- Compatibility Layer for Emacs 25.1 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 25.1, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in fns.c
+
+(compat-advise sort (seq predicate)
+ "Handle SEQ of type vector."
+ (cond
+ ((listp seq)
+ (funcall oldfun seq predicate))
+ ((vectorp seq)
+ (let ((cseq (sort (append seq nil) predicate)))
+ (dotimes (i (length cseq))
+ (setf (aref seq i) (nth i cseq)))
+ (apply #'vector cseq)))
+ ((signal 'wrong-type-argument 'list-or-vector-p))))
+
+;;;; Defined in editfns.c
+
+(compat-defun format-message (string &rest objects)
+ "Format a string out of a format-string and arguments.
+The first argument is a format control string.
+The other arguments are substituted into it to make the result, a string.
+
+This implementation is equivalent to `format'."
+ (apply #'format string objects))
+
+;;;; Defined in minibuf.c
+
+;; TODO advise read-buffer to handle 4th argument
+
+;;;; Defined in subr.el
+
+(compat-defun string-greaterp (string1 string2)
+ "Return non-nil if STRING1 is greater than STRING2 in lexicographic order.
+Case is significant.
+Symbols are also allowed; their print names are used instead."
+ (string-lessp string2 string1))
+
+(compat-defmacro with-file-modes (modes &rest body)
+ "Execute BODY with default file permissions temporarily set to MODES.
+MODES is as for `set-default-file-modes'."
+ (declare (indent 1) (debug t))
+ (let ((umask (make-symbol "umask")))
+ `(let ((,umask (default-file-modes)))
+ (unwind-protect
+ (progn
+ (set-default-file-modes ,modes)
+ ,@body)
+ (set-default-file-modes ,umask)))))
+
+;;;; Defined in subr-x.el
+
+(compat-defmacro if-let* (varlist then &rest else)
+ "Bind variables according to VARLIST and evaluate THEN or ELSE.
+This is like `if-let' but doesn't handle a VARLIST of the form
+\(SYMBOL SOMETHING) specially."
+ :feature subr-x
+ (declare (indent 2)
+ (debug ((&rest [&or symbolp (symbolp form) (form)])
+ body)))
+ `(let* (,(let ((empty (make-symbol "s"))
+ (last t) list)
+ (dolist (var varlist)
+ (push `(,(if (cdr var) (car var) empty)
+ (and ,last ,(or (cdr var) (car var))))
+ list)
+ (when (or (cdr var) (consp (car var)))
+ (setq last (caar list))))
+ (nreverse list)))
+ ,then ,@else))
+
+(compat-defmacro when-let* (varlist &rest body)
+ "Bind variables according to VARLIST and conditionally evaluate BODY.
+This is like `when-let' but doesn't handle a VARLIST of the form
+\(SYMBOL SOMETHING) specially."
+ :feature subr-x
+ (declare (indent 1) (debug compat--if-let*))
+ `(compat--if-let* ,varlist ,(macroexp-progn body)))
+
+(compat-defmacro and-let* (varlist &rest body)
+ "Bind variables according to VARLIST and conditionally evaluate BODY.
+Like `when-let*', except if BODY is empty and all the bindings
+are non-nil, then the result is non-nil."
+ :feature subr-x
+ (declare (indent 1) (debug compat--if-let*))
+ (let ((empty (make-symbol "s"))
+ (last t) list)
+ (dolist (var varlist)
+ (push `(,(if (cdr var) (car var) empty)
+ (and ,last ,(or (cdr var) (car var))))
+ list)
+ (when (or (cdr var) (consp (car var)))
+ (setq last (caar list))))
+ `(let* (,(nreverse list))
+ (when ,(caar list)
+ ,@body))))
+
+(compat-defmacro if-let (spec then &rest else)
+ "Bind variables according to SPEC and evaluate THEN or ELSE.
+Evaluate each binding in turn, as in `let*', stopping if a
+binding value is nil. If all are non-nil return the value of
+THEN, otherwise the last form in ELSE.
+
+Each element of SPEC is a list (SYMBOL VALUEFORM) that binds
+SYMBOL to the value of VALUEFORM. An element can additionally be
+of the form (VALUEFORM), which is evaluated and checked for nil;
+i.e. SYMBOL can be omitted if only the test result is of
+interest. It can also be of the form SYMBOL, then the binding of
+SYMBOL is checked for nil.
+
+As a special case, interprets a SPEC of the form \(SYMBOL SOMETHING)
+like \((SYMBOL SOMETHING)). This exists for backward compatibility
+with an old syntax that accepted only one binding."
+ :feature subr-x
+ (declare (indent 2)
+ (debug ([&or (symbolp form)
+ (&rest [&or symbolp (symbolp form) (form)])]
+ body)))
+ (when (and (<= (length spec) 2)
+ (not (listp (car spec))))
+ ;; Adjust the single binding case
+ (setq spec (list spec)))
+ `(compat--if-let* ,spec ,then ,@(macroexp-unprogn else)))
+
+(compat-defmacro when-let (spec &rest body)
+ "Bind variables according to SPEC and conditionally evaluate BODY.
+Evaluate each binding in turn, stopping if a binding value is nil.
+If all are non-nil, return the value of the last form in BODY.
+
+The variable list SPEC is the same as in `if-let'."
+ :feature subr-x
+ (declare (indent 1) (debug compat--if-let))
+ (list 'compat--if-let spec (macroexp-progn body)))
+
+(compat-defmacro thread-first (&rest forms)
+ "Thread FORMS elements as the first argument of their successor.
+Example:
+ (thread-first
+ 5
+ (+ 20)
+ (/ 25)
+ -
+ (+ 40))
+Is equivalent to:
+ (+ (- (/ (+ 5 20) 25)) 40)
+Note how the single `-' got converted into a list before
+threading."
+ :feature subr-x
+ (declare (indent 1)
+ (debug (form &rest [&or symbolp (sexp &rest form)])))
+ (let ((body (car forms)))
+ (dolist (form (cdr forms))
+ (when (symbolp form)
+ (setq form (list form)))
+ (setq body (append (list (car form))
+ (list body)
+ (cdr form))))
+ body))
+
+(compat-defmacro thread-last (&rest forms)
+ "Thread FORMS elements as the last argument of their successor.
+Example:
+ (thread-last
+ 5
+ (+ 20)
+ (/ 25)
+ -
+ (+ 40))
+Is equivalent to:
+ (+ 40 (- (/ 25 (+ 20 5))))
+Note how the single `-' got converted into a list before
+threading."
+ :feature subr-x
+ (declare (indent 1) (debug thread-first))
+ (let ((body (car forms)))
+ (dolist (form (cdr forms))
+ (when (symbolp form)
+ (setq form (list form)))
+ (setq body (append form (list body))))
+ body))
+
+;;;; Defined in macroexp.el
+
+(compat-defun macroexpand-1 (form &optional environment)
+ "Perform (at most) one step of macro expansion."
+ :feature macroexp
+ (cond
+ ((consp form)
+ (let* ((head (car form))
+ (env-expander (assq head environment)))
+ (if env-expander
+ (if (cdr env-expander)
+ (apply (cdr env-expander) (cdr form))
+ form)
+ (if (not (and (symbolp head) (fboundp head)))
+ form
+ (let ((def (autoload-do-load (symbol-function head) head 'macro)))
+ (cond
+ ;; Follow alias, but only for macros, otherwise we may end up
+ ;; skipping an important compiler-macro (e.g. cl--block-wrapper).
+ ((and (symbolp def) (macrop def)) (cons def (cdr form)))
+ ((not (consp def)) form)
+ (t
+ (if (eq 'macro (car def))
+ (apply (cdr def) (cdr form))
+ form))))))))
+ (t form)))
+
+(provide 'compat-25.1)
+;;; compat-25.1.el ends here
diff --git a/compat-26.1.el b/compat-26.1.el
new file mode 100644
index 0000000..1808b14
--- /dev/null
+++ b/compat-26.1.el
@@ -0,0 +1,286 @@
+;;; compat-26.1.el --- Compatibility Layer for Emacs 26.1 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 26.1, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in fns.c
+
+(compat-advise assoc (key alist &optional testfn)
+ "Handle TESTFN manually."
+ (if testfn
+ (catch 'found
+ (dolist (ent alist)
+ (when (funcall testfn (car ent) key)
+ (throw 'found ent))))
+ (funcall oldfun key alist)))
+
+(compat-defun mapcan (func sequence)
+ "Apply FUNC to each element of SEQUENCE.
+Concatenate the results by altering them (using `nconc').
+SEQUENCE may be a list, a vector, a boolean vector, or a string."
+ (let (result)
+ (mapc
+ (lambda (elem)
+ (setq result (nconc result (funcall func elem))))
+ sequence)
+ result))
+
+(compat-advise line-number-at-pos (&optional position absolute)
+ "Handle optional argument ABSOLUTE:
+
+If the buffer is narrowed, the return value by default counts the lines
+from the beginning of the accessible portion of the buffer. But if the
+second optional argument ABSOLUTE is non-nil, the value counts the lines
+from the absolute start of the buffer, disregarding the narrowing."
+ (if absolute
+ (save-restriction
+ (widen)
+ (funcall oldfun position))
+ (funcall oldfun position)))
+
+;;;; Defined in subr.el
+
+(compat-advise alist-get (key alist &optional default remove testfn)
+ "Handle TESTFN manually."
+ :min-version "25.1" ;first defined in 25.1
+ :max-version "25.3" ;last version without testfn
+ :realname compat--alist-get-handle-testfn
+ (if testfn
+ (catch 'found
+ (dolist (ent alist)
+ (when (and (consp ent) (funcall testfn (car ent) key))
+ (throw 'found (cdr ent))))
+ default)
+ (funcall oldfun key alist default remove testfn)))
+
+(compat-defun alist-get (key alist &optional default remove testfn)
+ "Find the first element of ALIST whose `car' equals KEY and return its `cdr'.
+If KEY is not found in ALIST, return DEFAULT.
+Equality with KEY is tested by TESTFN, defaulting to `eq'."
+ :max-version "24.5"
+ :realname compat--alist-get-full-elisp
+ (ignore remove)
+ (unless testfn (setq testfn #'eq))
+ (catch 'found
+ (dolist (ent alist)
+ (when (and (consp ent) (funcall testfn (car ent) key))
+ (throw 'found (cdr ent))))
+ default))
+
+(compat-defun string-trim-left (string &optional regexp)
+ "Trim STRING of leading string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
+ (substring string (match-end 0))
+ string))
+
+(compat-defun string-trim-right (string &optional regexp)
+ "Trim STRING of trailing string matching REGEXP.
+
+REGEXP defaults to \"[ \\t\\n\\r]+\"."
+ (let ((i (string-match-p
+ (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
+ string)))
+ (if i (substring string 0 i) string)))
+
+(compat-defun string-trim (string &optional trim-left trim-right)
+ "Trim STRING of leading with and trailing matching TRIM-LEFT and TRIM-RIGHT.
+
+TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
+ (compat--string-trim-left
+ (compat--string-trim-right
+ string
+ trim-right)
+ trim-left))
+
+(compat-defun caaar (x)
+ "Return the `car' of the `car' of the `car' of X."
+ (declare (pure t))
+ (car (car (car x))))
+
+(compat-defun caadr (x)
+ "Return the `car' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (car (car (cdr x))))
+
+(compat-defun cadar (x)
+ "Return the `car' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (car (cdr (car x))))
+
+(compat-defun caddr (x)
+ "Return the `car' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (car (cdr (cdr x))))
+
+(compat-defun cdaar (x)
+ "Return the `cdr' of the `car' of the `car' of X."
+ (declare (pure t))
+ (cdr (car (car x))))
+
+(compat-defun cdadr (x)
+ "Return the `cdr' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (car (cdr x))))
+
+(compat-defun cddar (x)
+ "Return the `cdr' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (cdr (cdr (car x))))
+
+(compat-defun cdddr (x)
+ "Return the `cdr' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (cdr (cdr x))))
+
+(compat-defun caaaar (x)
+ "Return the `car' of the `car' of the `car' of the `car' of X."
+ (declare (pure t))
+ (car (car (car (car x)))))
+
+(compat-defun caaadr (x)
+ "Return the `car' of the `car' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (car (car (car (cdr x)))))
+
+(compat-defun caadar (x)
+ "Return the `car' of the `car' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (car (car (cdr (car x)))))
+
+(compat-defun caaddr (x)
+ "Return the `car' of the `car' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (car (car (cdr (cdr x)))))
+
+(compat-defun cadaar (x)
+ "Return the `car' of the `cdr' of the `car' of the `car' of X."
+ (declare (pure t))
+ (car (cdr (car (car x)))))
+
+(compat-defun cadadr (x)
+ "Return the `car' of the `cdr' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (car (cdr (car (cdr x)))))
+
+(compat-defun caddar (x)
+ "Return the `car' of the `cdr' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (car (cdr (cdr (car x)))))
+
+(compat-defun cadddr (x)
+ "Return the `car' of the `cdr' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (car (cdr (cdr (cdr x)))))
+
+(compat-defun cdaaar (x)
+ "Return the `cdr' of the `car' of the `car' of the `car' of X."
+ (declare (pure t))
+ (cdr (car (car (car x)))))
+
+(compat-defun cdaadr (x)
+ "Return the `cdr' of the `car' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (car (car (cdr x)))))
+
+(compat-defun cdadar (x)
+ "Return the `cdr' of the `car' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (cdr (car (cdr (car x)))))
+
+(compat-defun cdaddr (x)
+ "Return the `cdr' of the `car' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (car (cdr (cdr x)))))
+
+(compat-defun cddaar (x)
+ "Return the `cdr' of the `cdr' of the `car' of the `car' of X."
+ (declare (pure t))
+ (cdr (cdr (car (car x)))))
+
+(compat-defun cddadr (x)
+ "Return the `cdr' of the `cdr' of the `car' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (cdr (car (cdr x)))))
+
+(compat-defun cdddar (x)
+ "Return the `cdr' of the `cdr' of the `cdr' of the `car' of X."
+ (declare (pure t))
+ (cdr (cdr (cdr (car x)))))
+
+(compat-defun cddddr (x)
+ "Return the `cdr' of the `cdr' of the `cdr' of the `cdr' of X."
+ (declare (pure t))
+ (cdr (cdr (cdr (cdr x)))))
+
+(let ((counter 0))
+ (compat-defun gensym (&optional prefix)
+ "Return a new uninterned symbol.
+The name is made by appending `gensym-counter' to PREFIX.
+PREFIX is a string, and defaults to \"g\"."
+ (let ((num (prog1 counter (setq counter (1+ counter)))))
+ (make-symbol (format "%s%d" (or prefix "g") num)))))
+
+;;;; Defined in files.el
+
+(compat-defun make-nearby-temp-file (prefix &optional dir-flag suffix)
+ "Create a temporary file as close as possible to `default-directory'.
+If PREFIX is a relative file name, and `default-directory' is a
+remote file name or located on a mounted file systems, the
+temporary file is created in the directory returned by the
+function `temporary-file-directory'. Otherwise, the function
+`make-temp-file' is used. PREFIX, DIR-FLAG and SUFFIX have the
+same meaning as in `make-temp-file'."
+ (let ((handler (find-file-name-handler
+ default-directory 'make-nearby-temp-file)))
+ (if (and handler (not (file-name-absolute-p default-directory)))
+ (funcall handler 'make-nearby-temp-file prefix dir-flag suffix)
+ (let ((temporary-file-directory (temporary-file-directory)))
+ (make-temp-file prefix dir-flag suffix)))))
+
+(compat-defun temporary-file-directory ()
+ "The directory for writing temporary files.
+In case of a remote `default-directory', this is a directory for
+temporary files on that remote host. If such a directory does
+not exist, or `default-directory' ought to be located on a
+mounted file system (see `mounted-file-systems'), the function
+returns `default-directory'.
+For a non-remote and non-mounted `default-directory', the value of
+the variable `temporary-file-directory' is returned."
+ (let ((handler (find-file-name-handler
+ default-directory 'temporary-file-directory)))
+ (if handler
+ (funcall handler 'temporary-file-directory)
+ (if (string-match mounted-file-systems default-directory)
+ default-directory
+ temporary-file-directory))))
+
+(provide 'compat-26.1)
+;;; compat-26.1.el ends here
diff --git a/compat-27.1.el b/compat-27.1.el
new file mode 100644
index 0000000..dfd7802
--- /dev/null
+++ b/compat-27.1.el
@@ -0,0 +1,271 @@
+;;; compat-27.1.el --- Compatibility Layer for Emacs 27.1 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 27.1, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in fns.c
+
+(compat-defun proper-list-p (object)
+ "Return OBJECT's length if it is a proper list, nil otherwise.
+A proper list is neither circular nor dotted (i.e., its last cdr
+is nil)."
+ (catch 'improper
+ (let ((length 0) prev)
+ (while object
+ (unless (consp object)
+ ;; dotted
+ (throw 'improper nil))
+ (when (memq object prev)
+ ;; circular
+ (throw 'improper nil))
+ (setq prev (cons object prev)
+ object (cdr object)
+ length (1+ length)))
+ length)))
+
+(compat-defun string-distance (string1 string2 &optional bytecompare)
+ "Return Levenshtein distance between STRING1 and STRING2.
+The distance is the number of deletions, insertions, and substitutions
+required to transform STRING1 into STRING2.
+If BYTECOMPARE is nil or omitted, compute distance in terms of characters.
+If BYTECOMPARE is non-nil, compute distance in terms of bytes.
+Letter-case is significant, but text properties are ignored."
+ ;; https://en.wikipedia.org/wiki/Levenshtein_distance
+ (let ((s1 (if bytecompare
+ (encode-coding-string string1 'raw-text)
+ (concat string1 "")))
+ (s2 (if bytecompare
+ (encode-coding-string string2 'raw-text)
+ string2)))
+ (let* ((len1 (length s1))
+ (len2 (length s2))
+ (column (make-vector (1+ len1) 0)))
+ (dotimes (y len1)
+ (setf (aref column (1+ y)) y))
+ (dotimes (x len2)
+ (setf (aref column 0) (1+ x))
+ (let ((lastdiag x) olddiag)
+ (dotimes (y len1)
+ (setf olddiag (aref column (1+ y))
+ (aref column (1+ y))
+ (min (+ (if (= (aref s1 y) (aref s2 x)) 0 1)
+ lastdiag)
+ (1+ (aref column (1+ y)))
+ (1+ (aref column y)))
+ lastdiag olddiag))))
+ (aref column len1))))
+
+;;;; Defined in window.c
+
+(compat-advise recenter (&optional arg redisplay)
+ "Handle optional argument REDISPLAY."
+ (funcall oldfun arg)
+ (when (and redisplay recenter-redisplay)
+ (redisplay)))
+
+;;;; Defined in subr.el
+
+(compat-advise setq-local (&rest pairs)
+ "Handle multiple assignments."
+ (unless (zerop (mod (length pairs) 2))
+ (error "PAIRS must have an even number of variable/value members"))
+ (let (body)
+ (while pairs
+ (let* ((sym (pop pairs))
+ (val (pop pairs)))
+ (unless (symbolp sym)
+ (error "Attempting to set a non-symbol: %s" (car pairs)))
+ (push `(set (make-local-variable ,sym) ,val)
+ body)))
+ (cons 'progn (nreverse body))))
+
+(compat-defmacro ignore-error (condition &rest body)
+ "Execute BODY; if the error CONDITION occurs, return nil.
+Otherwise, return result of last form in BODY.
+
+CONDITION can also be a list of error conditions."
+ (declare (debug t) (indent 1))
+ `(condition-case nil (progn ,@body) (,condition nil)))
+
+(compat-defmacro dolist-with-progress-reporter (spec reporter-or-message &rest
body)
+ "Loop over a list and report progress in the echo area.
+Evaluate BODY with VAR bound to each car from LIST, in turn.
+Then evaluate RESULT to get return value, default nil.
+
+REPORTER-OR-MESSAGE is a progress reporter object or a string. In the latter
+case, use this string to create a progress reporter.
+
+At each iteration, print the reporter message followed by progress
+percentage in the echo area. After the loop is finished,
+print the reporter message followed by the word \"done\".
+
+\(fn (VAR LIST [RESULT]) REPORTER-OR-MESSAGE BODY...)"
+ (declare (indent 2) (debug ((symbolp form &optional form) form body)))
+ (let ((prep (make-symbol "--dolist-progress-reporter--"))
+ (count (make-symbol "--dolist-count--"))
+ (list (make-symbol "--dolist-list--")))
+ `(let ((,prep ,reporter-or-message)
+ (,count 0)
+ (,list ,(cadr spec)))
+ (when (stringp ,prep)
+ (setq ,prep (make-progress-reporter ,prep 0 (1- (length ,list)))))
+ (dolist (,(car spec) ,list)
+ ,@body
+ (progress-reporter-update ,prep (setq ,count (1+ ,count))))
+ (progress-reporter-done ,prep)
+ (or ,@(cdr (cdr spec)) nil))))
+
+(compat-defun flatten-tree (tree)
+ "Return a \"flattened\" copy of TREE.
+In other words, return a list of the non-nil terminal nodes, or
+leaves, of the tree of cons cells rooted at TREE. Leaves in the
+returned list are in the same order as in TREE.
+
+\(flatten-tree \\='(1 (2 . 3) nil (4 5 (6)) 7))
+=> (1 2 3 4 5 6 7)"
+ (let (elems)
+ (while (consp tree)
+ (let ((elem (pop tree)))
+ (while (consp elem)
+ (push (cdr elem) tree)
+ (setq elem (car elem)))
+ (if elem (push elem elems))))
+ (if tree (push tree elems))
+ (nreverse elems)))
+
+(compat-defun xor (cond1 cond2)
+ "Return the boolean exclusive-or of COND1 and COND2.
+If only one of the arguments is non-nil, return it; otherwise
+return nil."
+ (declare (pure t) (side-effect-free error-free))
+ (cond ((not cond1) cond2)
+ ((not cond2) cond1)))
+
+(compat-defvar regexp-unmatchable "\\`a\\`"
+ "Standard regexp guaranteed not to match any string at all."
+ :constant t)
+
+;;;; Defined in files.el
+
+(compat-advise file-size-human-readable (file-size &optional flavor space unit)
+ "Handle the optional third and forth argument:
+
+Optional third argument SPACE is a string put between the number and unit.
+It defaults to the empty string. We recommend a single space or
+non-breaking space, unless other constraints prohibit a space in that
+position.
+
+Optional fourth argument UNIT is the unit to use. It defaults to \"B\"
+when FLAVOR is `iec' and the empty string otherwise. We recommend \"B\"
+in all cases, since that is the standard symbol for byte."
+ (let ((power (if (or (null flavor) (eq flavor 'iec))
+ 1024.0
+ 1000.0))
+ (prefixes '("" "k" "M" "G" "T" "P" "E" "Z" "Y")))
+ (while (and (>= file-size power) (cdr prefixes))
+ (setq file-size (/ file-size power)
+ prefixes (cdr prefixes)))
+ (let* ((prefix (car prefixes))
+ (prefixed-unit (if (eq flavor 'iec)
+ (concat
+ (if (string= prefix "k") "K" prefix)
+ (if (string= prefix "") "" "i")
+ (or unit "B"))
+ (concat prefix unit))))
+ (format (if (and (>= (mod file-size 1.0) 0.05)
+ (< (mod file-size 1.0) 0.95))
+ "%.1f%s%s"
+ "%.0f%s%s")
+ file-size
+ (if (string= prefixed-unit "") "" (or space ""))
+ prefixed-unit))))
+
+;; TODO provide advice for directory-files-recursively
+
+;;;; Defined in format-spec.el
+
+;; TODO provide advice for format-spec
+
+;;;; Defined in regexp-opt.el
+
+(compat-advise regexp-opt (strings &optional paren)
+ "Handle an empty list of strings."
+ (if (null strings)
+ (let ((re "\\`a\\`"))
+ (cond ((null paren)
+ (concat "\\(?:" re "\\)"))
+ ((stringp paren)
+ (concat paren re "\\)"))
+ ((eq paren 'words)
+ (concat "\\<\\(" re "\\)\\>"))
+ ((eq paren 'symbols)
+ (concat "\\_\\(<" re "\\)\\_>"))
+ ((concat "\\(" re "\\)"))))
+ (funcall oldfun strings paren)))
+
+;;;; Defined in package.el
+
+(declare-function lm-header "lisp-mnt")
+
+(compat-defun package-get-version ()
+ "Return the version number of the package in which this is used.
+Assumes it is used from an Elisp file placed inside the top-level directory
+of an installed ELPA package.
+The return value is a string (or nil in case we can’t find it)."
+ ;; In a sense, this is a lie, but it does just what we want: precompute
+ ;; the version at compile time and hardcodes it into the .elc file!
+ (declare (pure t))
+ ;; Hack alert!
+ (let ((file
+ (or (and (boundp 'byte-compile-current-file)
byte-compile-current-file)
+ load-file-name
+ buffer-file-name)))
+ (cond
+ ((null file) nil)
+ ;; Packages are normally installed into directories named "<pkg>-<vers>",
+ ;; so get the version number from there.
+ ((string-match
+
"/[^/]+-\\([0-9]\\(?:[0-9.]\\|pre\\|beta\\|alpha\\|snapshot\\)+\\)/[^/]+\\'"
+ file)
+ (match-string 1 file))
+ ;; For packages run straight from the an elpa.git clone, there's no
+ ;; "-<vers>" in the directory name, so we have to fetch the version
+ ;; the hard way.
+ ((let* ((pkgdir (file-name-directory file))
+ (pkgname (file-name-nondirectory (directory-file-name pkgdir)))
+ (mainfile (expand-file-name (concat pkgname ".el") pkgdir)))
+ (when (file-readable-p mainfile)
+ (require 'lisp-mnt)
+ (with-temp-buffer
+ (insert-file-contents mainfile)
+ (or (lm-header "package-version")
+ (lm-header "version")))))))))
+
+(provide 'compat-27.1)
+;;; compat-27.1.el ends here
diff --git a/compat-28.1.el b/compat-28.1.el
new file mode 100644
index 0000000..d2ff192
--- /dev/null
+++ b/compat-28.1.el
@@ -0,0 +1,456 @@
+;;; compat-28.1.el --- Compatibility Layer for Emacs 28.1 -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; Find here the functionality added in Emacs 28.1, needed by older
+;; versions.
+;;
+;; Do NOT load this library manually. Instead require `compat'.
+
+;;; Code:
+
+(eval-and-compile (require 'compat-macs))
+
+;;;; Defined in fns.c
+
+(compat-defun string-search (needle haystack &optional start-pos)
+ "Search for the string NEEDLE in the strign HAYSTACK.
+
+The return value is the position of the first occurrence of
+NEEDLE in HAYSTACK, or nil if no match was found.
+
+The optional START-POS argument says where to start searching in
+HAYSTACK and defaults to zero (start at the beginning).
+It must be between zero and the length of HAYSTACK, inclusive.
+
+Case is always significant and text properties are ignored."
+ (when (and start-pos (< start-pos 0))
+ (signal 'args-out-of-range (list start-pos)))
+ (let ((inhibit-changing-match-data t)
+ (case-fold-search nil))
+ (string-match (regexp-quote needle) haystack start-pos)))
+
+(compat-defun length= (sequence length)
+ "Returns non-nil if SEQUENCE has a length equal to LENGTH."
+ (cond
+ ((null sequence) (zerop length))
+ ((consp sequence)
+ (and (null (nthcdr length sequence))
+ (nthcdr (1- length) sequence)
+ t))
+ ((arrayp sequence)
+ (= (length sequence) length))
+ ((signal 'wrong-type-argument sequence))))
+
+(compat-defun length< (sequence length)
+ "Returns non-nil if SEQUENCE is shorter than LENGTH."
+ (cond
+ ((null sequence) (not (zerop length)))
+ ((listp sequence)
+ (null (nthcdr (1- length) sequence)))
+ ((arrayp sequence)
+ (< (length sequence) length))
+ ((signal 'wrong-type-argument sequence))))
+
+(compat-defun length> (sequence length)
+ "Returns non-nil if SEQUENCE is longer than LENGTH."
+ (cond
+ ((listp sequence)
+ (and (nthcdr length sequence) t))
+ ((arrayp sequence)
+ (> (length sequence) length))
+ ((signal 'wrong-type-argument sequence))))
+
+;;;; Defined in fileio.c
+
+(compat-defun file-name-concat (directory &rest components)
+ "Append COMPONENTS to DIRECTORY and return the resulting string.
+Elements in COMPONENTS must be a string or nil.
+DIRECTORY or the non-final elements in COMPONENTS may or may not end
+with a slash -- if they don’t end with a slash, a slash will be
+inserted before contatenating."
+ (let ((seperator (eval-when-compile
+ (if (memq system-type '(ms-dos windows-nt cygwin))
+ "\\" "/")))
+ (last (if components (car (last components)) directory)))
+ (mapconcat (lambda (part)
+ (if (eq part last) ;the last component is not modified
+ last
+ (replace-regexp-in-string
+ (concat seperator "+\\'") "" part)))
+ (cons directory components)
+ seperator)))
+
+;;;; Defined in alloc.c
+
+(compat-defun garbage-collect-maybe (_factor)
+ "Call ‘garbage-collect’ if enough allocation happened.
+FACTOR determines what \"enough\" means here: If FACTOR is a
+positive number N, it means to run GC if more than 1/Nth of the
+allocations needed to trigger automatic allocation took place.
+Therefore, as N gets higher, this is more likely to perform a GC.
+Returns non-nil if GC happened, and nil otherwise."
+ ;; Do nothing
+ nil)
+
+;;;; Defined in filelock.c
+
+(compat-advise unlock-buffer ()
+ "Handle `file-error' conditions:
+
+Handles file system errors by calling ‘display-warning’ and
+continuing as if the error did not occur."
+ (condition-case error
+ (funcall oldfun)
+ (file-error
+ (display-warning
+ '(unlock-file)
+ (message "%s, ignored" (error-message-string error))
+ :warning))))
+
+;;;; Defined in characters.c
+
+(compat-advise string-width (string &optional from to)
+ "Handle optional arguments FROM and TO:
+
+Optional arguments FROM and TO specify the substring of STRING to
+consider, and are interpreted as in `substring'."
+ (funcall oldfun (substring string from to)))
+
+;;;; Defined in dired.c
+
+(compat-advise directory-files (directory &optional full match nosort count)
+ "Handle additional optional argument COUNT:
+
+If COUNT is non-nil and a natural number, the function will
+ return COUNT number of file names (if so many are present)."
+ (let ((files (funcall oldfun directory full match nosort)))
+ (when (natnump count)
+ (setf (nthcdr count files) nil))
+ files))
+
+;;;; Defined in subr.el
+
+(compat-defun string-replace (fromstring tostring instring)
+ "Replace FROMSTRING with TOSTRING in INSTRING each time it occurs."
+ (when (equal fromstring "")
+ (signal 'wrong-length-argument '(0)))
+ (let ((case-fold-search nil))
+ (replace-regexp-in-string
+ (regexp-quote fromstring)
+ tostring instring
+ t t)))
+
+(compat-defun always (&rest _arguments)
+ "Do nothing and return t.
+This function accepts any number of ARGUMENTS, but ignores them.
+Also see `ignore'."
+ t)
+
+(compat-defun insert-into-buffer (buffer &optional start end)
+ "Insert the contents of the current buffer into BUFFER.
+If START/END, only insert that region from the current buffer.
+Point in BUFFER will be placed after the inserted text."
+ (let ((current (current-buffer)))
+ (with-current-buffer buffer
+ (insert-buffer-substring current start end))))
+
+(compat-defun replace-regexp-in-region (regexp replacement &optional start end)
+ "Replace REGEXP with REPLACEMENT in the region from START to END.
+The number of replaced occurrences are returned, or nil if REGEXP
+doesn't exist in the region.
+
+If START is nil, use the current point. If END is nil, use `point-max'.
+
+Comparisons and replacements are done with fixed case.
+
+REPLACEMENT can use the following special elements:
+
+ `\\&' in NEWTEXT means substitute original matched text.
+ `\\N' means substitute what matched the Nth `\\(...\\)'.
+ If Nth parens didn't match, substitute nothing.
+ `\\\\' means insert one `\\'.
+ `\\?' is treated literally."
+ (if start
+ (when (< start (point-min))
+ (error "Start before start of buffer"))
+ (setq start (point)))
+ (if end
+ (when (> end (point-max))
+ (error "End after end of buffer"))
+ (setq end (point-max)))
+ (save-excursion
+ (let ((matches 0)
+ (case-fold-search nil))
+ (goto-char start)
+ (while (re-search-forward regexp end t)
+ (replace-match replacement t)
+ (setq matches (1+ matches)))
+ (and (not (zerop matches))
+ matches))))
+
+(compat-defun buffer-local-boundp (symbol buffer)
+ "Return non-nil if SYMBOL is bound in BUFFER.
+Also see `local-variable-p'."
+ (catch 'fail
+ (condition-case nil
+ (buffer-local-value symbol buffer)
+ (void-variable nil (throw 'fail nil)))
+ t))
+
+(compat-defmacro with-existing-directory (&rest body)
+ "Execute BODY with `default-directory' bound to an existing directory.
+If `default-directory' is already an existing directory, it's not changed."
+ (declare (indent 0) (debug t))
+ (let ((quit (gensym)))
+ `(catch ',quit
+ (dolist (dir (list default-directory
+ (expand-file-name "~/")
+ (getenv "TMPDIR")
+ "/tmp/"
+ ;; XXX: check if "/" works on non-POSIX
+ ;; system.
+ "/"))
+ (when (and dir (file-exists-p dir))
+ (throw ',quit (let ((default-directory dir))
+ ,@body)))))))
+
+(compat-defmacro dlet (binders &rest body)
+ "Like `let' but using dynamic scoping."
+ (declare (indent 1) (debug let))
+ `(let (_)
+ ,@(mapcar (lambda (binder)
+ `(defvar ,(if (consp binder) (car binder) binder)))
+ binders)
+ (let ,binders ,@body)))
+
+(compat-defun ensure-list (object)
+ "Return OBJECT as a list.
+If OBJECT is already a list, return OBJECT itself. If it's
+not a list, return a one-element list containing OBJECT."
+ (if (listp object)
+ object
+ (list object)))
+
+;;;; Defined in subr-x.el
+
+(compat-defun string-clean-whitespace (string)
+ "Clean up whitespace in STRING.
+All sequences of whitespaces in STRING are collapsed into a
+single space character, and leading/trailing whitespace is
+removed."
+ :feature subr-x
+ (let ((blank "[[:blank:]\r\n]+"))
+ (replace-regexp-in-string
+ "^[[:blank:]\r\n]+\\|[[:blank:]\r\n]+$"
+ ""
+ (replace-regexp-in-string
+ blank " " string))))
+
+(compat-defun string-fill (string length)
+ "Clean up whitespace in STRING.
+All sequences of whitespaces in STRING are collapsed into a
+single space character, and leading/trailing whitespace is
+removed."
+ :feature subr-x
+ (with-temp-buffer
+ (insert string)
+ (goto-char (point-min))
+ (let ((fill-column length)
+ (adaptive-fill-mode nil))
+ (fill-region (point-min) (point-max)))
+ (buffer-string)))
+
+(compat-defun string-lines (string &optional omit-nulls)
+ "Split STRING into a list of lines.
+If OMIT-NULLS, empty lines will be removed from the results."
+ :feature subr-x
+ (split-string string "\n" omit-nulls))
+
+(compat-defun string-pad (string length &optional padding start)
+ "Pad STRING to LENGTH using PADDING.
+If PADDING is nil, the space character is used. If not nil, it
+should be a character.
+
+If STRING is longer than the absolute value of LENGTH, no padding
+is done.
+
+If START is nil (or not present), the padding is done to the end
+of the string, and if non-nil, padding is done to the start of
+the string."
+ :feature subr-x
+ (unless (natnump length)
+ (signal 'wrong-type-argument (list 'natnump length)))
+ (let ((pad-length (- length (length string))))
+ (if (< pad-length 0)
+ string
+ (concat (and start
+ (make-string pad-length (or padding ?\s)))
+ string
+ (and (not start)
+ (make-string pad-length (or padding ?\s)))))))
+
+(compat-defun string-chop-newline (string)
+ "Remove the final newline (if any) from STRING."
+ :feature subr-x
+ (if (and (>= (length string) 1) (= (aref string (1- (length string))) ?\n))
+ (substring string 0 -1)
+ string))
+
+(compat-defmacro named-let (name bindings &rest body)
+ "Looping construct taken from Scheme.
+Like `let', bind variables in BINDINGS and then evaluate BODY,
+but with the twist that BODY can evaluate itself recursively by
+calling NAME, where the arguments passed to NAME are used
+as the new values of the bound variables in the recursive invocation."
+ ;; :feature subr-x
+ (declare (indent 2) (debug (symbolp (&rest (symbolp form)) body)))
+ (let* ((fargs (mapcar (lambda (b) (if (consp b) (car b) b)) bindings))
+ (aargs (mapcar (lambda (b) (if (consp b) (cadr b))) bindings))
+ (fn (make-symbol "self"))
+ (macro (lambda (&rest args) `(apply ',fn (list ,@args)))))
+ `(letrec ((,fn (lambda ,fargs . ,(macroexpand-all
+ (macroexp-progn body)
+ (list (cons name macro))))))
+ (apply ,fn (list ,@aargs)))))
+
+;;;; Defined in files.el
+
+(compat-defun file-name-with-extension (filename extension)
+ "Set the EXTENSION of a FILENAME.
+The extension (in a file name) is the part that begins with the last \".\".
+
+Trims a leading dot from the EXTENSION so that either \"foo\" or
+\".foo\" can be given.
+
+Errors if the FILENAME or EXTENSION are empty, or if the given
+FILENAME has the format of a directory.
+
+See also `file-name-sans-extension'."
+ (let ((extn (string-trim-left extension "[.]")))
+ (cond
+ ((string= filename "")
+ (error "Empty filename"))
+ ((string= extn "")
+ (error "Malformed extension: %s" extension))
+ ((directory-name-p filename)
+ (error "Filename is a directory: %s" filename))
+ (t
+ (concat (file-name-sans-extension filename) "." extn)))))
+
+(compat-defun directory-empty-p (dir)
+ "Return t if DIR names an existing directory containing no other files.
+Return nil if DIR does not name a directory, or if there was
+trouble determining whether DIR is a directory or empty.
+
+Symbolic links to directories count as directories.
+See `file-symlink-p' to distinguish symlinks."
+ (and (file-directory-p dir)
+ (null (directory-files dir nil directory-files-no-dot-files-regexp t))))
+
+;;;; Defined in minibuffer.el
+
+(compat-defun format-prompt (prompt default &rest format-args)
+ "Format PROMPT with DEFAULT.
+If FORMAT-ARGS is nil, PROMPT is used as a plain string. If
+FORMAT-ARGS is non-nil, PROMPT is used as a format control
+string, and FORMAT-ARGS are the arguments to be substituted into
+it. See `format' for details.
+
+If DEFAULT is a list, the first element is used as the default.
+If not, the element is used as is.
+
+If DEFAULT is nil or an empty string, no \"default value\" string
+is included in the return value."
+ (concat
+ (if (null format-args)
+ prompt
+ (apply #'format prompt format-args))
+ (and default
+ (or (not (stringp default))
+ (not (null default)))
+ (format " (default %s)"
+ (if (consp default)
+ (car default)
+ default)))
+ ": "))
+
+;;;; Defined in windows.el
+
+(compat-advise count-windows (&optional minibuf all-frames)
+ "Handle optional argument ALL-FRAMES:
+
+If ALL-FRAMES is non-nil, count the windows in all frames instead
+just the selected frame."
+ (if all-frames
+ (let ((sum 0))
+ (dolist (frame (frame-list))
+ (with-selected-frame frame
+ (setq sum (+ (funcall oldfun minibuf)
+ sum))))
+ sum)
+ (funcall oldfun minibuf)))
+
+;;;; Defined in thingatpt.el
+
+(compat-defun thing-at-mouse (event thing &optional no-properties)
+ "Return the THING at mouse click.
+Like `thing-at-point', but tries to use the event
+where the mouse button is clicked to find a thing nearby."
+ :feature thingatpt
+ (save-excursion
+ (mouse-set-point event)
+ (thing-at-point thing no-properties)))
+
+;;;; Defined in macroexp.el
+
+(compat-defun macroexp-file-name ()
+ "Return the name of the file from which the code comes.
+Returns nil when we do not know.
+A non-nil result is expected to be reliable when called from a macro in order
+to find the file in which the macro's call was found, and it should be
+reliable as well when used at the top-level of a file.
+Other uses risk returning non-nil value that point to the wrong file."
+ :feature macroexp
+ (let ((file (car (last current-load-list))))
+ (or (if (stringp file) file)
+ (bound-and-true-p byte-compile-current-file))))
+
+;;;; Defined in env.el
+
+(compat-defmacro with-environment-variables (variables &rest body)
+ "Set VARIABLES in the environent and execute BODY.
+VARIABLES is a list of variable settings of the form (VAR VALUE),
+where VAR is the name of the variable (a string) and VALUE
+is its value (also a string).
+
+The previous values will be be restored upon exit."
+ (declare (indent 1) (debug (sexp body)))
+ (unless (consp variables)
+ (error "Invalid VARIABLES: %s" variables))
+ `(let ((process-environment (copy-sequence process-environment)))
+ ,@(mapcar (lambda (elem)
+ `(setenv ,(car elem) ,(cadr elem)))
+ variables)
+ ,@body))
+
+(provide 'compat-28.1)
+;;; compat-28.1.el ends here
diff --git a/compat-macs.el b/compat-macs.el
new file mode 100644
index 0000000..c6a2aab
--- /dev/null
+++ b/compat-macs.el
@@ -0,0 +1,245 @@
+;;; compat-macs.el --- Compatibility Macros -*- lexical-binding: t;
-*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords: lisp
+
+;; 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:
+
+;; These macros are used to define compatibility functions, macros and
+;; advice.
+
+;;; Code:
+
+(defvar compat--disable-defer nil
+ "Prevent compatibility code from being deferred.
+This is used for testing, and should not be set to a non-nil
+value otherwise.")
+
+(defmacro compat--ignore (&rest _)
+ "Ignore all arguments."
+ nil)
+
+(defun compat-generate-common (name def-fn install-fn check-fn attr)
+ "Common code for generating compatibility definitions for NAME.
+The resulting body is constructed by invoking the functions
+DEF-FN (passed the \"realname\" and the version number, returning
+the compatibility definition), the INSTALL-FN (passed the
+\"realname\" and returning the installation code),
+CHECK-FN (passed the \"realname\" and returning a check to see if
+the compatibility definition should be installed). ATTR is a
+plist used to modify the generated code. The following
+attributes are handled, all others are ignored:
+
+- :min-version :: Prevent the compatibility definition from begin
+ installed in versions older than indicated (string).
+
+- :max-version :: Prevent the compatibility definition from begin
+ installed in versions newer than indicated (string).
+
+- :feature :: The library the code is supposed to be loaded
+ with (via `eval-after-load').
+
+- :force :: Non-nil means the compatibility code is installed no
+ matter what.
+
+- :version :: Manual specification of the version the compatee
+ code was defined in (string).
+
+- :realname :: Manual specification of a \"realname\" to use for
+ the compatibility definition (symbol)."
+ (let* ((min-version (plist-get attr :min-version))
+ (max-version (plist-get attr :max-version))
+ (feature (plist-get attr :feature))
+ (force (plist-get attr :force))
+ (version (or (plist-get attr :version)
+ (let ((file (or (and (boundp 'byte-compile-current-file)
+ byte-compile-current-file)
+ load-file-name
+ (buffer-file-name))))
+ ;; Guess the version from the file the macro is
+ ;; being defined in.
+ (and (string-match
+
"compat-\\([[:digit:]]+\\.[[:digit:]]+\\)\\.\\(?:elc?\\)\\'"
+ file)
+ (match-string 1 file)))))
+ (realname (or (plist-get attr :realname)
+ (intern (format "compat--%S" name))))
+ (body `(progn
+ ,(funcall def-fn realname version)
+ (,@(cond
+ ((or compat--disable-defer force)
+ '(progn))
+ ((or (or (not version)
+ (version< emacs-version version))
+ (or (not min-version)
+ (version<= min-version emacs-version))
+ (or (not max-version)
+ (version<= emacs-version max-version)))
+ '(compat--ignore))
+ (`(when ,(funcall check-fn realname))))
+ ,(funcall install-fn realname)))))
+ (if (and feature (not compat--disable-defer))
+ `(eval-after-load ',feature (lambda () ,body))
+ body)))
+
+(defun compat-common-fdefine (type name arglist docstring rest)
+ "Generate compatibility code for a function NAME.
+TYPE is one of `func', for functions and `macro' for macros, and
+`advice' ARGLIST is passed on directly to the definition, and
+DOCSTRING is prepended with a compatibility note. REST contains
+the remaining definition, that may begin with a property list of
+attributes (see `compat-generate-common')."
+ (let ((body rest))
+ (while (keywordp (car body))
+ (setq body (cddr body)))
+ (compat-generate-common
+ name
+ (lambda (realname version)
+ `(,(cond
+ ((memq type '(func advice)) 'defun)
+ ((eq type 'macro) 'defmacro)
+ ((error "Unknown type")))
+ ,realname ,arglist
+ ;; Prepend compatibility notice to the actual
+ ;; documentation string.
+ ,(let ((type (cond
+ ((eq type 'func) "function")
+ ((eq type 'macro) "macro")
+ ((eq type 'advice) "advice")
+ ((error "Unknown type")))))
+ (if version
+ (format
+ "[Compatibility %s for `%S', defined in Emacs %s]\n\n%s"
+ type name version docstring)
+ (format
+ "[Compatibility %s for `%S']\n\n%s"
+ type name docstring)))
+ ;; Advice may use the implicit variable `oldfun', but
+ ;; to avoid triggering the byte compiler, we make
+ ;; sure the argument is used at least once.
+ ,(and (eq type 'advice) '(ignore oldfun))
+ ;; Insert the actual body now.
+ ,@body))
+ (lambda (realname)
+ (cond
+ ((memq type '(func macro))
+ ;; Functions and macros are installed by
+ ;; aliasing the name of the compatible
+ ;; function to the name of the compatibility
+ ;; function.
+ `(defalias ',name #',realname))
+ ((eq type 'advice)
+ ;; Advice is installed the usual way.
+ `(advice-add ',name :around #',realname))))
+ (lambda (realname)
+ (cond
+ ((memq type '(func macro))
+ `(fboundp ',realname))
+ ((eq type 'advice)
+ ;; TODO: Improve the check if the advice already has been
+ ;; installed or still has to be added.
+ `(advice-member-p ',realname ',name))))
+ rest)))
+
+(defmacro compat-defun (name arglist docstring &rest rest)
+ "Define NAME with arguments ARGLIST as a compatibility function.
+The function must be documented in DOCSTRING. REST may begin
+with a plist, that is interpreted by the macro but not passed on
+to the actual function. See `compat-generate-common' for a
+listing of attributes.
+
+The definition will only be installed, if the version this
+function was defined in, as indicated by the `:version'
+attribute, is greater than the current Emacs version."
+ (declare (debug (&define name (&rest symbolp)
+ stringp
+ [&rest keywordp sexp]
+ def-body))
+ (doc-string 3) (indent 2))
+ (compat-common-fdefine 'func name arglist docstring rest))
+
+(defmacro compat-defmacro (name arglist docstring &rest rest)
+ "Define NAME with arguments ARGLIST as a compatibility macro.
+The macro must be documented in DOCSTRING. REST may begin
+with a plist, that is interpreted by this macro but not passed on
+to the actual macro. See `compat-generate-common' for a
+listing of attributes.
+
+The definition will only be installed, if the version this
+function was defined in, as indicated by the `:version'
+attribute, is greater than the current Emacs version."
+ (declare (debug compat-defun) (doc-string 3) (indent 2))
+ (compat-common-fdefine 'macro name arglist docstring rest))
+
+(defmacro compat-advise (name arglist docstring &rest rest)
+ "Define NAME with arguments ARGLIST as a compatibility advice.
+The advice function must be documented in DOCSTRING. REST may
+begin with a plist, that is interpreted by this macro but not
+passed on to the actual advice function. See
+`compat-generate-common' for a listing of attributes. The advice
+wraps the old definition, that is accessible via using the symbol
+`oldfun'.
+
+The advice will only be installed, if the version this function
+was defined in, as indicated by the `:version' attribute, is
+greater than the current Emacs version."
+ (declare (debug compat-defun) (doc-string 3) (indent 2))
+ (compat-common-fdefine 'advice name (cons 'oldfun arglist) docstring rest))
+
+(defmacro compat-defvar (name initval docstring &rest attr)
+ "Declare compatibility variable NAME with initial value INITVAL.
+The obligatory documentation string DOCSTRING must be given.
+
+The remaining arguments ATTR form a plist, modifying the
+behaviour of this macro. See `compat-generate-common' for a
+listing of attributes. Furthermore, `compat-defvar' also handles
+the attribute `:local' that either makes the variable permanent
+local with a value of `permanent' or just buffer local with any
+non-nil value."
+ (declare (debug (name form stringp [&rest keywordp sexp]))
+ (doc-string 3) (indent 2))
+ (compat-generate-common
+ name
+ (lambda (realname version)
+ (let ((localp (plist-get attr :local)))
+ `(progn
+ (,(if (plist-get attr :constant) 'defconst 'defvar)
+ ,realname ,initval
+ ;; Prepend compatibility notice to the actual
+ ;; documentation string.
+ ,(if version
+ (format
+ "[Compatibility variable for `%S', defined in Emacs %s]\n\n%s"
+ name version docstring)
+ (format
+ "[Compatibility variable for `%S']\n\n%s"
+ name docstring)))
+ ;; Make variable as local if necessary
+ ,(cond
+ ((eq localp 'permanent)
+ `(put ',realname 'permanent-local t))
+ (localp
+ `(make-variable-buffer-local ',realname))))))
+ (lambda (realname)
+ `(defvaralias ',name ',realname))
+ (lambda (realname)
+ `(boundp ',realname))
+ attr))
+
+(provide 'compat-macs)
+;;; compat-macs.el ends here
diff --git a/compat-tests.el b/compat-tests.el
new file mode 100644
index 0000000..703ed5b
--- /dev/null
+++ b/compat-tests.el
@@ -0,0 +1,1195 @@
+;;; compat-tests.el --- Tests for compat.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Package-Requires: ((emacs "28.1"))
+
+;; 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:
+
+;; Tests for compatibility functions from compat.el.
+;;
+;; Note that not all functions have tests (yet), for the most part
+;; because it is difficult to create a reproducible environment to
+;; test these in or their tests are trivial -- or a combination of
+;; both. The current list of untested functions, macros, etc. are:
+;;
+;; - and-let* (`compat--and-let*')
+;; - buffer-local-boundp (`buffer-local-boundp')
+;; - count-windows (`compat--count-windows')
+;; - defmacro (`compat--defmacro')
+;; - directory-empty-p (`compat--directory-empty-p')
+;; - directory-files (`compat--directory-files')
+;; - dlet (`compat--dlet')
+;; - garbage-collect-maybe (`compat--garbage-collect-maybe')
+;; - if-let (`compat--if-let')
+;; - if-let* (`compat--if-let*')
+;; - ignore-error (`compat--ignore-error')
+;; - insert-into-buffer (`compat--insert-into-buffer')
+;; - line-number-at-pos (`compat--line-number-at-pos')
+;; - macroexp-file-name (`compat--macroexp-file-name')
+;; - make-nearby-temp-file (`compat--make-nearby-temp-file')
+;; - named-let (`compat--named-let')
+;; - package-get-version (`compat--package-get-version')
+;; - recenter (`compat--recenter')
+;; - replace-regexp-in-region (`compat--replace-regexp-in-region')
+;; - setq-local (`compat--setq-local')
+;; - temporary-file-directory (`compat--temporary-file-directory')
+;; - thing-at-mouse (`compat--thing-at-mouse')
+;; - thread-first (`compat--thread-first')
+;; - thread-last (`compat--thread-last')
+;; - unlock-buffer (`compat--unlock-buffer')
+;; - when-let (`compat--when-let')
+;; - when-let* (`compat--when-let*')
+;; - with-environment-variables (`compat--with-environment-variables')
+;; - with-existing-directory (`compat--with-existing-directory')
+;; - with-file-modes (`compat--with-file-modes')
+;;
+;; Tests are welcome, but until then anyone working on these functions
+;; should take care to test these manually.
+
+;;; Code:
+
+(require 'ert)
+(eval-and-compile
+ (require 'compat-macs)
+
+ (let ((compat--disable-defer t))
+ (load "compat-24.2.el" nil nil nil t)
+ (load "compat-24.3.el" nil nil nil t)
+ (load "compat-24.4.el" nil nil nil t)
+ (load "compat-25.1.el" nil nil nil t)
+ (load "compat-26.1.el" nil nil nil t)
+ (load "compat-27.1.el" nil nil nil t)
+ (load "compat-28.1.el" nil nil nil t))
+
+ (defvar compat--current-fn nil)
+ (defvar compat--compat-fn nil)
+
+ (defmacro compat--should (result &rest input)
+ "Generate code for test with INPUT evaluating to RESULT."
+ (let ((cfn (or compat--compat-fn
+ (intern (format "compat--%s" compat--current-fn))))
+ (rfn compat--current-fn))
+ `(progn
+ (should (equal (,cfn ,@input) ,result))
+ (should (equal (,rfn ,@input) ,result)))))
+
+ (defmacro compat--should* (result &rest input)
+ "Generate code for test with INPUT evaluating to RESULT."
+ (let ((cfn (or compat--compat-fn
+ (intern (format "compat--%s" compat--current-fn))))
+ (rfn compat--current-fn))
+ `(progn
+ (should (equal (funcall (apply-partially #',cfn #',rfn) ,@input)
,result))
+ (should (equal (,rfn ,@input) ,result)))))
+
+ (defmacro compat--mshould (result &rest input)
+ "Generate code for test with INPUT evaluating to RESULT."
+ (let ((cfn (or compat--compat-fn
+ (intern (format "compat--%s" compat--current-fn))))
+ (rfn compat--current-fn))
+ `(progn
+ (should (equal (macroexpand-all `(,',cfn ,,@input)) ,result))
+ (should (equal (macroexpand-all `(,',rfn ,,@input)) ,result)))))
+
+ (defmacro compat--error (error &rest input)
+ "Generate code for test FN with INPUT to signal ERROR."
+ (let ((cfn (or compat--compat-fn
+ (intern (format "compat--%s" compat--current-fn))))
+ (rfn compat--current-fn))
+ `(progn
+ (should-error (,cfn ,@input) :type ',error)
+ (should-error (,rfn ,@input) :type ',error))))
+
+ (defmacro compat--error* (error &rest input)
+ "Generate code for test FN with INPUT to signal ERROR."
+ (let ((cfn (or compat--compat-fn
+ (intern (format "compat--%s" compat--current-fn))))
+ (rfn compat--current-fn))
+ `(progn
+ (should-error (funcall (apply-partially #',cfn #',rfn) ,@input) :type
',error)
+ (should-error (,rfn ,@input) :type ',error))))
+
+ ;; FIXME: extract the name of the test out of the ERT-test, instead
+ ;; of having to re-declare the name of the test redundantly.
+ (defmacro compat-test (fn &rest body)
+ "Set `compat--current-fn' to FN in BODY.
+If FN is a list, the car should be the actual function, and cadr
+the compatibility function."
+ (declare (indent 1))
+ (if (consp fn)
+ (setq compat--current-fn (car fn)
+ compat--compat-fn (cadr fn))
+ (setq compat--current-fn fn
+ compat--compat-fn nil))
+ (macroexp-progn body)))
+
+
+
+(ert-deftest compat-string-search ()
+ "Check if `string-search' was implemented correctly."
+ (compat-test string-search
+ ;; Find needle at the beginning of a haystack:
+ (c-should 0 "a" "abb")
+ ;; Find needle at the begining of a haystack, with more potential
+ ;; needles that could be found:
+ (c-should 0 "a" "abba")
+ ;; Find needle with more than one charachter at the beginning of
+ ;; a line:
+ (c-should 0 "aa" "aabbb")
+ ;; Find a needle midstring:
+ (c-should 1 "a" "bab")
+ ;; Find a needle at the end:
+ (c-should 2 "a" "bba")
+ ;; Find a longer needle midstring:
+ (c-should 1 "aa" "baab")
+ ;; Find a longer needle at the end:
+ (c-should 2 "aa" "bbaa")
+ ;; Find a case-sensitive needle:
+ (c-should 2 "a" "AAa")
+ ;; Find another case-sensitive needle:
+ (c-should 2 "aa" "AAaa")
+ ;; Test regular expression quoting (1):
+ (c-should 5 "." "abbbb.b")
+ ;; Test regular expression quoting (2):
+ (c-should 5 ".*" "abbbb.*b")
+ ;; Attempt to find non-existent needle:
+ (c-should nil "a" "bbb")
+ ;; Attempt to find non-existent needle that has the form of a
+ ;; regular expression:
+ (c-should nil "." "bbb")
+ ;; Handle empty string as needle:
+ (c-should 0 "" "abc")
+ ;; Handle empty string as haystack:
+ (c-should nil "a" "")
+ ;; Handle empty string as needle and haystack:
+ (c-should 0 "" "")
+ ;; Handle START argument:
+ (c-should 3 "a" "abba" 1)
+ ;; Additional test copied from:
+ (c-should 6 "zot" "foobarzot")
+ (c-should 0 "foo" "foobarzot")
+ (c-should nil "fooz" "foobarzot")
+ (c-should nil "zot" "foobarzo")
+ (c-should 0 "ab" "ab")
+ (c-should nil "ab\0" "ab")
+ (c-should 4 "ab" "abababab" 3)
+ (c-should nil "ab" "ababac" 3)
+ (c-should nil "aaa" "aa")
+ (c-should 5
+ (make-string 2 130)
+ (concat "helló" (make-string 5 130 t) "bár"))
+ (c-should 5
+ (make-string 2 127)
+ (concat "helló" (make-string 5 127 t) "bár"))
+ (c-should 1 "\377" "a\377ø")
+ (c-should 1 "\377" "a\377a")
+ (c-should nil (make-string 1 255) "a\377ø")
+ (c-should nil (make-string 1 255) "a\377a")
+ (c-should 3 "fóo" "zotfóo")
+ (c-should 2 (string-to-multibyte "\377") "ab\377c")
+ (c-should nil "\303" "aøb")
+ (c-should nil "\270" "aøb")
+ (c-should nil "ø" "\303\270")
+ (c-should nil "ø" (make-string 32 ?a))
+ (c-should nil "ø" (string-to-multibyte (make-string 32 ?a)))
+ (c-should 14 "o" (string-to-multibyte
+ (apply #'string (number-sequence ?a ?z))))
+ (c-should 2 "a\U00010f98z" "a\U00010f98a\U00010f98z")
+ (c-error (args-out-of-range -1) "a" "abc" -1)
+ (c-error (args-out-of-range 4) "a" "abc" 4)
+ (c-error (args-out-of-range 100000000000)
+ "a" "abc" 100000000000)
+ (c-should nil "a" "aaa" 3)
+ (c-should nil "aa" "aa" 1)
+ (c-should nil "\0" "")
+ (c-should 0 "" "")
+ (c-error (args-out-of-range 1) "" "" 1)
+ (c-should 0 "" "abc")
+ (c-should 2 "" "abc" 2)
+ (c-should 3 "" "abc" 3)
+ (c-error (args-out-of-range 4) "" "abc" 4)
+ (c-error (args-out-of-range -1) "" "abc" -1)
+ (c-should nil "ø" "foo\303\270")
+ (c-should nil "\303\270" "ø")
+ (c-should nil "\370" "ø")
+ (c-should nil (string-to-multibyte "\370") "ø")
+ (c-should nil "ø" "\370")
+ (c-should nil "ø" (string-to-multibyte "\370"))
+ (c-should nil "\303\270" "\370")
+ (c-should nil (string-to-multibyte "\303\270") "\370")
+ (c-should nil "\303\270" (string-to-multibyte "\370"))
+ (c-should nil
+ (string-to-multibyte "\303\270")
+ (string-to-multibyte "\370"))
+ (c-should nil "\370" "\303\270")
+ (c-should nil (string-to-multibyte "\370") "\303\270")
+ (c-should nil "\370" (string-to-multibyte "\303\270"))
+ (c-should nil
+ (string-to-multibyte "\370")
+ (string-to-multibyte "\303\270"))
+ (c-should 2
+ (string-to-multibyte "o\303\270")
+ "foo\303\270")
+ (c-should 3 "\303\270" "foo\303\270")))
+
+(ert-deftest compat-string-replace ()
+ "Check if `string-replace' was implemented correctly."
+ (compat-test string-replace
+ (c-should "bba" "aa" "bb" "aaa")
+ (c-should "AAA" "aa" "bb" "AAA")
+ ;; Additional test copied from subr-tests.el:
+ (c-should "zot" "foo" "bar" "zot")
+ (c-should "barzot" "foo" "bar" "foozot")
+ (c-should "barbarzot" "foo" "bar" "barfoozot")
+ (c-should "barfoobar" "zot" "bar" "barfoozot")
+ (c-should "barfoobarot" "z" "bar" "barfoozot")
+ (c-should "zat" "zot" "bar" "zat")
+ (c-should "zat" "azot" "bar" "zat")
+ (c-should "bar" "azot" "bar" "azot")
+ (c-should "foozotbar" "azot" "bar" "foozotbar")
+ (c-should "labarbarbarzot" "fo" "bar" "lafofofozot")
+ (c-should "axb" "\377" "x" "a\377b")
+ (c-should "axø" "\377" "x" "a\377ø")
+ (c-should "axb" (string-to-multibyte "\377") "x" "a\377b")
+ (c-should "axø" (string-to-multibyte "\377") "x" "a\377ø")
+ (c-should "ANAnas" "ana" "ANA" "ananas")
+ (c-should "" "a" "" "")
+ (c-should "" "a" "" "aaaaa")
+ (c-should "" "ab" "" "ababab")
+ (c-should "ccc" "ab" "" "abcabcabc")
+ (c-should "aaaaaa" "a" "aa" "aaa")
+ (c-should "defg" "abc" "defg" "abc")
+ (c-error wrong-length-argument "" "x" "abc")))
+
+(ert-deftest compat-length= ()
+ "Check if `string-length=' was implemented correctly."
+ (compat-test length=
+ (c-should t '() 0) ;empty list
+ (c-should t '(1) 1) ;single element
+ (c-should t '(1 2 3) 3) ;multiple elements
+ (c-should nil '(1 2 3) 2) ;less than
+ (c-should nil '(1) 0)
+ (c-should nil '(1 2 3) 4) ;more than
+ (c-should nil '(1) 2)
+ (c-should nil '() 1)
+ (c-should t [] 0) ;empty vector
+ (c-should t [1] 1) ;single element vector
+ (c-should t [1 2 3] 3) ;multiple element vector
+ (c-should nil [1 2 3] 2) ;less than
+ (c-should nil [1 2 3] 4) ;more than
+ (c-error wrong-type-argument 3 nil)))
+
+(ert-deftest compat-length< ()
+ "Check if `length<' was implemented correctly."
+ (compat-test length<
+ (c-should nil '(1) 0) ;single element
+ (c-should nil '(1 2 3) 2) ;multiple elements
+ (c-should nil '(1 2 3) 3) ;equal length
+ (c-should nil '(1) 1)
+ (c-should t '(1 2 3) 4) ;more than
+ (c-should t '(1) 2)
+ (c-should t '() 1)
+ (c-should nil [1] 0) ;single element vector
+ (c-should nil [1 2 3] 2) ;multiple element vector
+ (c-should nil [1 2 3] 3) ;equal length
+ (c-should t [1 2 3] 4) ;more than
+ (c-error wrong-type-argument 3 nil)))
+
+(ert-deftest compat-length> ()
+ "Check if `length>' was implemented correctly."
+ (compat-test length>
+ (c-should t '(1) 0) ;single element
+ (c-should t '(1 2 3) 2) ;multiple elements
+ (c-should nil '(1 2 3) 3) ;equal length
+ (c-should nil '(1) 1)
+ (c-should nil '(1 2 3) 4) ;more than
+ (c-should nil '(1) 2)
+ (c-should nil '() 1)
+ (c-should t [1] 0) ;single element vector
+ (c-should t [1 2 3] 2) ;multiple element vector
+ (c-should nil [1 2 3] 3) ;equal length
+ (c-should nil [1 2 3] 4) ;more than
+ (c-error wrong-type-argument 3 nil)))
+
+(ert-deftest compat-always ()
+ "Check if `always' was implemented correctly."
+ (compat-test always
+ (c-should t) ;no arguments
+ (c-should t 1) ;single argument
+ (c-should t 1 2 3 4))) ;multiple arguments
+
+(ert-deftest compat-insert-into-buffer ()
+ "Check if `insert-into-buffer' was implemented correctly."
+ ;; Without optional arguments
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (c-insert-into-buffer other))
+ (should (string= (buffer-string) "abcdef"))))
+ (when (fboundp 'insert-into-buffer)
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (insert-into-buffer other))
+ (should (string= (buffer-string) "abcdef")))))
+ ;; With one optional argument
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (c-insert-into-buffer other 2))
+ (should (string= (buffer-string) "abcef"))))
+ (when (fboundp 'insert-into-buffer)
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (insert-into-buffer other 2))
+ (should (string= (buffer-string) "abcef")))))
+ ;; With two optional arguments
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (c-insert-into-buffer other 2 3))
+ (should (string= (buffer-string) "abce"))))
+ (when (fboundp 'insert-into-buffer)
+ (with-temp-buffer
+ (let ((other (current-buffer)))
+ (insert "abc")
+ (with-temp-buffer
+ (insert "def")
+ (insert-into-buffer other 2 3))
+ (should (string= (buffer-string) "abce"))))))
+
+(ert-deftest compat-file-name-with-extension ()
+ "Check if `file-name-with-extension' was implemented correctly."
+ (compat-test file-name-with-extension
+ (c-should "file.ext" "file" "ext")
+ (c-should "file.ext" "file" ".ext")
+ (c-should "file.ext" "file." ".ext")
+ (c-should "file..ext" "file.." ".ext")
+ (c-should "file..ext" "file." "..ext")
+ (c-should "file...ext" "file.." "..ext")
+ (c-should "/abs/file.ext" "/abs/file" "ext")
+ (c-should "/abs/file.ext" "/abs/file" ".ext")
+ (c-should "/abs/file.ext" "/abs/file." ".ext")
+ (c-should "/abs/file..ext" "/abs/file.." ".ext")
+ (c-should "/abs/file..ext" "/abs/file." "..ext")
+ (c-should "/abs/file...ext" "/abs/file.." "..ext")
+ (c-error error "file" "")
+ (c-error error '"" "ext")
+ (c-error error "file" "")
+ (c-error error "rel/" "ext")
+ (c-error error "/abs/" "ext")))
+
+(ert-deftest compat-file-name-with-extension ()
+ "Check if `file-name-with-extension' was implemented correctly."
+ (compat-test file-name-with-extension
+ (c-should "file.ext" "file" "ext")
+ (c-should "file.ext" "file" ".ext")
+ (c-should "file.ext" "file." ".ext")
+ (c-should "file..ext" "file.." ".ext")
+ (c-should "file..ext" "file." "..ext")
+ (c-should "file...ext" "file.." "..ext")
+ (c-should "/abs/file.ext" "/abs/file" "ext")
+ (c-should "/abs/file.ext" "/abs/file" ".ext")
+ (c-should "/abs/file.ext" "/abs/file." ".ext")
+ (c-should "/abs/file..ext" "/abs/file.." ".ext")
+ (c-should "/abs/file..ext" "/abs/file." "..ext")
+ (c-should "/abs/file...ext" "/abs/file.." "..ext")
+ (c-error error "file" "")
+ (c-error error "" "ext")
+ (c-error error "file" "")
+ (c-error error "rel/" "ext")
+ (c-error error "/abs/" "ext")))
+
+(ert-deftest compat-string-width ()
+ "Check if `string-width' was implemented correctly."
+ (compat-test string-width
+ (c-should* 0 "")
+ (c-should* 3 "abc") ;no argument
+ (c-should* 5 "abcあ")
+ (c-should* (1+ tab-width) "a ")
+ (c-should* 2 "abc" 1) ;with from
+ (c-should* 4 "abcあ" 1)
+ (c-should* tab-width "a " 1)
+ (c-should* 2 "abc" 0 2) ;with to
+ (c-should* 3 "abcあ" 0 3)
+ (c-should* 1 "a " 0 1)
+ (c-should* 1 "abc" 1 2) ;with from and to
+ (c-should* 2 "abcあ" 3 4)
+ (c-should* 0 "a " 1 1)))
+
+(ert-deftest compat-ensure-list ()
+ "Check if `ensure-list' was implemented correctly."
+ (compat-test ensure-list
+ (c-should nil nil) ;empty list
+ (c-should '(1) '(1)) ;single element list
+ (c-should '(1 2 3) '(1 2 3)) ;multiple element list
+ (c-should '(1) 1))) ;atom
+
+(ert-deftest compat-proper-list-p ()
+ "Check if `proper-list-p' was implemented correctly."
+ (compat-test proper-list-p
+ (c-should 0 ()) ;empty list
+ (c-should 1 '(1)) ;single element
+ (c-should 3 '(1 2 3)) ;multiple elements
+ (c-should nil '(1 . 2)) ;cons
+ (c-should nil '(1 2 . 3)) ;dotted
+ (c-should nil (let ((l (list 1 2 3))) ;circular
+ (setf (nthcdr 3 l) l)
+ l))))
+
+(ert-deftest compat-flatten-tree ()
+ "Check if `flatten-tree' was implemented correctly."
+ (compat-test flatten-tree
+ ;; Example from docstring:
+ (c-should '(1 2 3 4 5 6 7) '(1 (2 . 3) nil (4 5 (6)) 7))
+ ;; Trivial example
+ (c-should nil ())
+ ;; Simple examples
+ (c-should '(1) '(1))
+ (c-should '(1 2) '(1 2))
+ (c-should '(1 2 3) '(1 2 3))
+ ;; Regular sublists
+ (c-should '(1) '((1)))
+ (c-should '(1 2) '((1) (2)))
+ (c-should '(1 2 3) '((1) (2) (3)))
+ ;; Complex examples
+ (c-should '(1) '(((((1))))))
+ (c-should '(1 2 3 4) '((1) nil 2 ((3 4))))
+ (c-should '(1 2 3 4) '(((1 nil)) 2 (((3 nil nil) 4))))))
+
+(ert-deftest compat-xor ()
+ "Check if `xor' was implemented correctly."
+ (compat-test xor
+ (c-should t t nil)
+ (c-should t nil t)
+ (c-should nil nil nil)
+ (c-should nil t t)))
+
+(ert-deftest compat- ()
+ "Check if `string-distance' was implemented correctly."
+ (compat-test string-distance
+ (c-should 3 "kitten" "sitting") ;from wikipedia
+ (c-should 0 "" "") ;trivial examples
+ (c-should 0 "a" "a")
+ (c-should 1 "" "a")
+ (c-should 1 "b" "a")
+ (c-should 2 "aa" "bb")
+ (c-should 2 "aa" "bba")
+ (c-should 2 "aaa" "bba")
+ (c-should 3 "a" "あ" t) ;byte example
+ (c-should 1 "a" "あ")))
+
+(ert-deftest compat-regexp-unmatchable ()
+ "Check if `string-distance' was implemented correctly."
+ (dolist (str '("" ;empty string
+ "a" ;simple string
+ "aaa" ;longer string
+ ))
+ (should-not (string-match-p (with-no-warnings c-regexp-unmatchable) str))
+ (should-not (string-match-p regexp-unmatchable str))))
+
+(ert-deftest compat-regexp-opt ()
+ "Check if `regexp-opt' advice was defined correctly."
+ (compat-test regexp-opt
+ ;; Ensure `compat--regexp-opt' doesn't change the existing
+ ;; behaviour:
+ (c-should* (regexp-opt '("a" "b" "c")) '("a" "b" "c"))
+ (c-should* (regexp-opt '("abc" "def" "ghe")) '("abc" "def" "ghe"))
+ (c-should* (regexp-opt '("a" "b" "c") 'words) '("a" "b" "c") 'words)
+ ;; Test empty list:
+ (c-should* "\\(?:\\`a\\`\\)" '())
+ (c-should* "\\<\\(\\`a\\`\\)\\>" '() 'words))
+ (let ((unmatchable (regexp-opt '())))
+ (dolist (str '("" ;empty string
+ "a" ;simple string
+ "aaa" ;longer string
+ ))
+ (should-not (string-match-p unmatchable str)))))
+
+(ert-deftest compat-assoc ()
+ "Check if `assoc' advice was advised correctly."
+ (compat-test assoc
+ ;; Fallback behaviour:
+ (c-should* nil 1 nil) ;empty list
+ (c-should* '(1) 1 '((1))) ;single element list
+ (c-should* nil 1 '(1))
+ (c-should* '(2) 2 '((1) (2) (3))) ;multiple element list
+ (c-should* nil 2 '(1 2 3))
+ (c-should* '(2) 2 '(1 (2) 3))
+ (c-should* nil 2 '((1) 2 (3)))
+ (c-should* '(1) 1 '((3) (2) (1)))
+ (c-should* '("a") "a" '(("a") ("b") ("c"))) ;non-primitive elements
+ (c-should* '("a" 0) "a" '(("c" . "a") "b" ("a" 0)))
+ ;; With testfn (advised behaviour):
+ (c-should* '(1) 3 '((10) (4) (1) (9)) #'<)
+ (c-should* '("a") "b" '(("c") ("a") ("b")) #'string-lessp)
+ (c-should* '("b") "a" '(("a") ("a") ("b"))
+ (lambda (s1 s2) (not (string= s1 s2))))
+ (c-should*
+ '("\\.el\\'" . emacs-lisp-mode)
+ "file.el"
+ '(("\\.c\\'" . c-mode)
+ ("\\.p\\'" . pascal-mode)
+ ("\\.el\\'" . emacs-lisp-mode)
+ ("\\.awk\\'" . awk-mode))
+ #'string-match-p)))
+
+(ert-deftest compat-alist-get-1 ()
+ "Check if `alist-get' was advised correctly."
+ (compat-test (alist-get compat--alist-get-handle-testfn)
+ ;; Fallback behaviour:
+ (c-should* nil 1 nil) ;empty list
+ (c-should* 'a 1 '((1 . a))) ;single element list
+ (c-should* nil 1 '(1))
+ (c-should* 'b 2 '((1 . a) (2 . b) (3 . c))) ;multiple element list
+ (c-should* nil 2 '(1 2 3))
+ (c-should* 'b 2 '(1 (2 . b) 3))
+ (c-should* nil 2 '((1 . a) 2 (3 . c)))
+ (c-should* 'a 1 '((3 . c) (2 . b) (1 . a)))
+ (c-should* nil "a" '(("a" . 1) ("b" . 2) ("c" . 3))) ;non-primitive
elements
+
+ ;; With testfn (advised behaviour):
+ (c-should* 1 "a" '(("a" . 1) ("b" . 2) ("c" . 3)) nil nil #'equal)
+ (c-should* 1 3 '((10 . 10) (4 . 4) (1 . 1) (9 . 9)) nil nil #'<)
+ (c-should* '(a) "b" '(("c" c) ("a" a) ("b" b)) nil nil #'string-lessp)
+ (c-should* 'c "a" '(("a" . a) ("a" . b) ("b" . c)) nil nil
+ (lambda (s1 s2) (not (string= s1 s2))))
+ (c-should* 'emacs-lisp-mode
+ "file.el"
+ '(("\\.c\\'" . c-mode)
+ ("\\.p\\'" . pascal-mode)
+ ("\\.el\\'" . emacs-lisp-mode)
+ ("\\.awk\\'" . awk-mode))
+ nil nil #'string-match-p)
+ (c-should* 'd 0 '((1 . a) (2 . b) (3 . c)) 'd) ;default value
+ (c-should* 'd 2 '((1 . a) (2 . b) (3 . c)) 'd nil #'ignore)))
+
+(ert-deftest compat-alist-get-2 ()
+ "Check if `alist-get' was implemented correctly."
+ (compat-test (alist-get compat--alist-get-full-elisp)
+ ;; Fallback behaviour:
+ (c-should nil 1 nil) ;empty list
+ (c-should 'a 1 '((1 . a))) ;single element list
+ (c-should nil 1 '(1))
+ (c-should 'b 2 '((1 . a) (2 . b) (3 . c))) ;multiple element list
+ (c-should nil 2 '(1 2 3))
+ (c-should 'b 2 '(1 (2 . b) 3))
+ (c-should nil 2 '((1 . a) 2 (3 . c)))
+ (c-should 'a 1 '((3 . c) (2 . b) (1 . a)))
+ (c-should nil "a" '(("a" . 1) ("b" . 2) ("c" . 3))) ;non-primitive
elements
+
+ ;; With testfn (advised behaviour):
+ (c-should 1 "a" '(("a" . 1) ("b" . 2) ("c" . 3)) nil nil #'equal)
+ (c-should 1 3 '((10 . 10) (4 . 4) (1 . 1) (9 . 9)) nil nil #'<)
+ (c-should '(a) "b" '(("c" c) ("a" a) ("b" b)) nil nil #'string-lessp)
+ (c-should 'c "a" '(("a" . a) ("a" . b) ("b" . c)) nil nil
+ (lambda (s1 s2) (not (string= s1 s2))))
+ (c-should 'emacs-lisp-mode
+ "file.el"
+ '(("\\.c\\'" . c-mode)
+ ("\\.p\\'" . pascal-mode)
+ ("\\.el\\'" . emacs-lisp-mode)
+ ("\\.awk\\'" . awk-mode))
+ nil nil #'string-match-p)
+ (c-should 'd 0 '((1 . a) (2 . b) (3 . c)) 'd) ;default value
+ (c-should 'd 2 '((1 . a) (2 . b) (3 . c)) 'd nil #'ignore)))
+
+(ert-deftest compat-string-trim-left ()
+ "Check if `string-trim-left' was implemented correctly."
+ (compat-test string-trim-left'
+ (c-should "" "") ;empty string
+ (c-should "a" "a") ;"full" string
+ (c-should "aaa" "aaa")
+ (c-should "へっろ" "へっろ")
+ (c-should "hello world" "hello world")
+ (c-should "a " "a ") ;right trailing
+ (c-should "aaa " "aaa ")
+ (c-should "a " "a ")
+ (c-should "a\t\t" "a\t\t")
+ (c-should "a\n \t" "a\n \t")
+ (c-should "a" " a") ;left trailing
+ (c-should "aaa" " aaa")
+ (c-should "a" "a")
+ (c-should "a" "\t\ta")
+ (c-should "a" "\n \ta")
+ (c-should "a " " a ") ;both trailing
+ (c-should "aaa " " aaa ")
+ (c-should "a\t\n" "\t\ta\t\n")
+ (c-should "a \n" "\n \ta \n")))
+
+(ert-deftest compat-string-trim-right ()
+ "Check if `string-trim-right' was implemented correctly."
+ (compat-test string-trim-right
+ (c-should "" "") ;empty string
+ (c-should "a" "a") ;"full" string
+ (c-should "aaa" "aaa")
+ (c-should "へっろ" "へっろ")
+ (c-should "hello world" "hello world")
+ (c-should "a" "a") ;right trailing
+ (c-should "aaa" "aaa")
+ (c-should "a" "a ")
+ (c-should "a" "a\t\t")
+ (c-should "a" "a\n \t")
+ (c-should " a" " a") ;left trailing
+ (c-should " aaa" " aaa")
+ (c-should "a" "a")
+ (c-should "\t\ta" "\t\ta")
+ (c-should "\n \ta" "\n \ta")
+ (c-should " a" " a ") ;both trailing
+ (c-should " aaa" " aaa")
+ (c-should "\t\ta" "\t\ta\t\n")
+ (c-should "\n \ta" "\n \ta \n")))
+
+(ert-deftest compat-string-trim ()
+ "Check if `string-trim' was implemented correctly."
+ (compat-test string-trim
+ (c-should "" "") ;empty string
+ (c-should "a" "a") ;"full" string
+ (c-should "aaa" "aaa")
+ (c-should "へっろ" "へっろ")
+ (c-should "hello world" "hello world")
+ (c-should "a" "a ") ;right trailing
+ (c-should "aaa" "aaa ")
+ (c-should "a" "a ")
+ (c-should "a" "a\t\t")
+ (c-should "a" "a\n \t")
+ (c-should "a" " a") ;left trailing
+ (c-should "aaa" " aaa")
+ (c-should "a" "a")
+ (c-should "a" "\t\ta")
+ (c-should "a" "\n \ta")
+ (c-should "a" " a ") ;both trailing
+ (c-should "aaa" " aaa ")
+ (c-should "t\ta" "t\ta\t\n")
+ (c-should "a" "\n \ta \n")))
+
+(ert-deftest compat-mapcan ()
+ "Check if `mapcan' was implemented correctly."
+ (compat-test mapcan
+ (c-should nil #'identity nil)
+ (c-should (list 1)
+ #'identity
+ (list (list 1)))
+ (c-should (list 1 2 3 4)
+ #'identity
+ (list (list 1) (list 2 3) (list 4)))
+ (c-should (list (list 1) (list 2 3) (list 4))
+ #'list
+ (list (list 1) (list 2 3) (list 4)))
+ (c-should (list 1 2 3 4)
+ #'identity
+ (list (list 1) (list) (list 2 3) (list 4)))
+ (c-should (list (list 1) (list) (list 2 3) (list 4))
+ #'list
+ (list (list 1) (list) (list 2 3) (list 4)))
+ (c-should (list)
+ #'identity
+ (list (list) (list) (list) (list)))))
+
+;; Note: as the cXXX+r implementations are relatively trivial, their
+;; tests are not as extensive.
+
+(defvar compat-cXXXr-test
+ '(((a . b) . (c . d)) . ((e . f) . (g . h)))
+ "Testcase for cXXXr functions.")
+
+(defvar compat-cXXXXr-test
+ '((((a . b) . (c . d)) . ((e . f) . (g . h))) .
+ (((i . j) . (k . l)) . ((m . j) . (o . p))))
+ "Testcase for cXXXXr functions.")
+
+(ert-deftest compat-caaar ()
+ "Check if `caaar' was implemented correctly."
+ (compat-test caaar
+ (c-should nil ())
+ (c-should 'a compat-cXXXr-test)))
+
+(ert-deftest compat-caadr ()
+ "Check if `caadr' was implemented correctly."
+ (compat-test caadr
+ (c-should nil ())
+ (c-should 'e compat-cXXXr-test)))
+
+(ert-deftest compat-cadar ()
+ "Check if `cadar' was implemented correctly."
+ (compat-test cadar
+ (c-should nil ())
+ (c-should 'c compat-cXXXr-test)))
+
+(ert-deftest compat-caddr ()
+ "Check if `caddr' was implemented correctly."
+ (compat-test caddr
+ (c-should nil ())
+ (c-should 'g compat-cXXXr-test)))
+
+(ert-deftest compat-cdaar ()
+ "Check if `cdaar' was implemented correctly."
+ (compat-test cdaar
+ (c-should nil ())
+ (c-should 'b compat-cXXXr-test)))
+
+(ert-deftest compat-cdadr ()
+ "Check if `cdadr' was implemented correctly."
+ (compat-test cdadr
+ (c-should nil ())
+ (c-should 'f compat-cXXXr-test)))
+
+(ert-deftest compat-cddar ()
+ "Check if `cddar' was implemented correctly."
+ (compat-test cddar
+ (c-should nil ())
+ (c-should 'd compat-cXXXr-test)))
+
+(ert-deftest compat-cdddr ()
+ "Check if `cdddr' was implemented correctly."
+ (compat-test cdddr
+ (c-should nil ())
+ (c-should 'h compat-cXXXr-test)
+ #'cdddr))
+
+(ert-deftest compat-caaaar ()
+ "Check if `caaaar' was implemented correctly."
+ (compat-test caaaar
+ (c-should nil ())
+ (c-should 'a compat-cXXXXr-test)))
+
+(ert-deftest compat-caaadr ()
+ "Check if `caaadr' was implemented correctly."
+ (compat-test caaadr
+ (c-should nil ())
+ (c-should 'i compat-cXXXXr-test)))
+
+(ert-deftest compat-caadar ()
+ "Check if `caadar' was implemented correctly."
+ (compat-test caadar
+ (c-should nil ())
+ (c-should 'e compat-cXXXXr-test)))
+
+(ert-deftest compat-caaddr ()
+ "Check if `caaddr' was implemented correctly."
+ (compat-test caaddr
+ (c-should nil ())
+ (c-should 'm compat-cXXXXr-test)))
+
+(ert-deftest compat-cadaar ()
+ "Check if `cadaar' was implemented correctly."
+ (compat-test cadaar
+ (c-should nil ())
+ (c-should 'c compat-cXXXXr-test)))
+
+(ert-deftest compat-cadadr ()
+ "Check if `cadadr' was implemented correctly."
+ (compat-test cadadr
+ (c-should nil ())
+ (c-should 'k compat-cXXXXr-test)))
+
+(ert-deftest compat-caddar ()
+ "Check if `caddar' was implemented correctly."
+ (compat-test caddar
+ (c-should nil ())
+ (c-should 'g compat-cXXXXr-test)))
+
+(ert-deftest compat-cadddr ()
+ "Check if `cadddr' was implemented correctly."
+ (compat-test cadddr
+ (c-should nil ())
+ (c-should 'o compat-cXXXXr-test)))
+
+(ert-deftest compat-cdaaar ()
+ "Check if `cdaaar' was implemented correctly."
+ (compat-test cdaaar
+ (c-should nil ())
+ (c-should 'b compat-cXXXXr-test)))
+
+(ert-deftest compat-cdaadr ()
+ "Check if `cdaadr' was implemented correctly."
+ (compat-test cdaadr
+ (c-should nil ())
+ (c-should 'j compat-cXXXXr-test)))
+
+(ert-deftest compat-cdadar ()
+ "Check if `cdadar' was implemented correctly."
+ (compat-test cdadar
+ (c-should nil ())
+ (c-should 'f compat-cXXXXr-test)))
+
+(ert-deftest compat-cdaddr ()
+ "Check if `cdaddr' was implemented correctly."
+ (compat-test cdaddr
+ (c-should nil ())
+ (c-should 'j compat-cXXXXr-test)))
+
+(ert-deftest compat-cddaar ()
+ "Check if `cddaar' was implemented correctly."
+ (compat-test cddaar
+ (c-should nil ())
+ (c-should 'd compat-cXXXXr-test)))
+
+(ert-deftest compat-cddadr ()
+ "Check if `cddadr' was implemented correctly."
+ (compat-test cddadr
+ (c-should nil ())
+ (c-should 'l compat-cXXXXr-test)))
+
+(ert-deftest compat-cdddar ()
+ "Check if `cdddar' was implemented correctly."
+ (compat-test cdddar
+ (c-should nil ())
+ (c-should 'h compat-cXXXXr-test)))
+
+(ert-deftest compat-string-greaterp ()
+ "Check if `string-greaterp' was implemented correctly."
+ (compat-test string-greaterp
+ (c-should t "b" "a")
+ (c-should nil "a" "b")
+ (c-should t "aaab" "aaaa")
+ (c-should nil "aaaa" "aaab")))
+
+(ert-deftest compat-sort ()
+ "Check if `sort' was advised correctly."
+ (compat-test sort
+ (c-should* (list 1 2 3) (list 1 2 3) #'<)
+ (c-should* (list 1 2 3) (list 3 2 1) #'<)
+ (c-should* '[1 2 3] '[1 2 3] #'<)
+ (c-should* '[1 2 3] '[3 2 1] #'<)))
+
+(ert-deftest compat-= ()
+ "Check if `=' was advised correctly."
+ (compat-test =
+ '(((0 0) t)
+ ((0 0 0) t)
+ ((0 0 0 0) t)
+ ((0 0 0 0 0) t)
+ ((0.0 0.0) t)
+ ((+0.0 -0.0) t)
+ ((0.0 0.0 0.0) t)
+ ((0.0 0.0 0.0 0.0) t)
+ ((0 1) nil)
+ ((0 0 1) nil)
+ ((0 0 0 0 1) nil)
+ ((0 0 a) nil wrong-type-argument)
+ ((0 1 a) nil)
+ ((0.0 0.0 0.0 0.1) nil)
+ )
+ (apply-partially #'c-= #'=)
+ #'=))
+
+(ert-deftest compat-< ()
+ "Check if `<' was advised correctly."
+ (compat-test <
+ (c-should* nil 0 0)
+ (c-should* nil 0 0 0)
+ (c-should* nil 0 0 0 0)
+ (c-should* nil 0 0 0 0 0)
+ (c-should* nil 0.0 0.0)
+ (c-should* nil +0.0 -0.0)
+ (c-should* nil 0.0 0.0 0.0)
+ (c-should* nil 0.0 0.0 0.0 0.0)
+ (c-should* t 0 1)
+ (c-should* nil 1 0)
+ (c-should* nil 0 0 1)
+ (c-should* t 0 1 2)
+ (c-should* nil 2 1 0)
+ (c-should* nil 0 0 0 0 1)
+ (c-should* t 0 1 2 3 4)
+ (c-error* wrong-type-argument 0 1 'a)
+ (c-should* nil 0 0 'a)
+ (c-should* nil 0.0 0.0 0.0 0.1)
+ (c-should* t -0.1 0.0 0.2 0.4)
+ (c-should* t -0.1 0 0.2 0.4)))
+
+(ert-deftest compat-> ()
+ "Check if `>' was advised correctly."
+ (compat-test >
+ (c-should* nil 0 0)
+ (c-should* nil 0 0 0)
+ (c-should* nil 0 0 0 0)
+ (c-should* nil 0 0 0 0 0)
+ (c-should* nil 0.0 0.0)
+ (c-should* nil +0.0 -0.0)
+ (c-should* nil 0.0 0.0 0.0)
+ (c-should* nil 0.0 0.0 0.0 0.0)
+ (c-should* t 1 0)
+ (c-should* nil 1 0 0)
+ (c-should* nil 0 1 2)
+ (c-should* t 2 1 0)
+ (c-should* nil 1 0 0 0 0)
+ (c-should* t 4 3 2 1 0)
+ (c-should* nil 4 3 2 1 1)
+ (c-error* wrong-type-argument 1 0 'a)
+ (c-should* nil 0 0 'a)
+ (c-should* nil 0.1 0.0 0.0 0.0)
+ (c-should* t 0.4 0.2 0.0 -0.1)
+ (c-should* t 0.4 0.2 0 -0.1)))
+
+(ert-deftest compat-<= ()
+ "Check if `<=' was advised correctly."
+ (compat-test <=
+ (c-should* t 0 0)
+ (c-should* t 0 0 0)
+ (c-should* t 0 0 0 0)
+ (c-should* t 0 0 0 0 0)
+ (c-should* t 0.0 0.0)
+ (c-should* t +0.0 -0.0)
+ (c-should* t 0.0 0.0 0.0)
+ (c-should* t 0.0 0.0 0.0 0.0)
+ (c-should* nil 1 0)
+ (c-should* nil 1 0 0)
+ (c-should* t 0 1 2)
+ (c-should* nil 2 1 0)
+ (c-should* nil 1 0 0 0 0)
+ (c-should* nil 4 3 2 1 0)
+ (c-should* nil 4 3 2 1 1)
+ (c-should* t 0 1 2 3 4)
+ (c-should* t 1 1 2 3 4)
+ (c-error* wrong-type-argument 0 0 'a)
+ (c-error* wrong-type-argument 0 1 'a)
+ (c-should* nil 1 0 'a)
+ (c-should* nil 0.1 0.0 0.0 0.0)
+ (c-should* t 0.0 0.0 0.0 0.1)
+ (c-should* t -0.1 0.0 0.2 0.4)
+ (c-should* t -0.1 0.0 0.0 0.2 0.4)
+ (c-should* t -0.1 0.0 0 0.2 0.4)
+ (c-should* t -0.1 0 0.2 0.4)
+ (c-should* nil 0.4 0.2 0.0 -0.1)
+ (c-should* nil 0.4 0.2 0.0 0.0 -0.1)
+ (c-should* nil 0.4 0.2 0 0.0 0.0 -0.1)
+ (c-should* nil 0.4 0.2 0 -0.1)))
+
+(ert-deftest compat->= ()
+ "Check if `>=' was implemented correctly."
+ (compat-test >=
+ (c-should* t 0 0)
+ (c-should* t 0 0 0)
+ (c-should* t 0 0 0 0)
+ (c-should* t 0 0 0 0 0)
+ (c-should* t 0.0 0.0)
+ (c-should* t +0.0 -0.0)
+ (c-should* t 0.0 0.0 0.0)
+ (c-should* t 0.0 0.0 0.0 0.0)
+ (c-should* t 1 0)
+ (c-should* t 1 0 0)
+ (c-should* nil 0 1 2)
+ (c-should* t 2 1 0)
+ (c-should* t 1 0 0 0 0)
+ (c-should* t 4 3 2 1 0)
+ (c-should* t 4 3 2 1 1)
+ (c-error* wrong-type-argument 0 0 'a)
+ (c-error* wrong-type-argument 1 0 'a)
+ (c-should* nil 0 1 'a)
+ (c-should* t 0.1 0.0 0.0 0.0)
+ (c-should* nil 0.0 0.0 0.0 0.1)
+ (c-should* nil -0.1 0.0 0.2 0.4)
+ (c-should* nil -0.1 0.0 0.0 0.2 0.4)
+ (c-should* nil -0.1 0.0 0 0.2 0.4)
+ (c-should* nil -0.1 0 0.2 0.4)
+ (c-should* t 0.4 0.2 0.0 -0.1)
+ (c-should* t 0.4 0.2 0.0 0.0 -0.1)
+ (c-should* t 0.4 0.2 0 0.0 0.0 -0.1)
+ (c-should* t 0.4 0.2 0 -0.1)))
+
+(ert-deftest compat-special-form-p ()
+ "Check if `special-form-p' was implemented correctly."
+ (compat-test special-form-p
+ (c-should t 'if)
+ (c-should t 'cond)
+ (c-should nil 'when)
+ (c-should nil 'defun)
+ (c-should nil '+)
+ (c-should nil nil)
+ (c-should nil "macro")
+ (c-should nil '(macro . +))))
+
+(ert-deftest compat-macrop ()
+ "Check if `macrop' was implemented correctly."
+ (compat-test macrop
+ (c-should t 'lambda)
+ (c-should t 'defun)
+ (c-should t 'defmacro)
+ (c-should nil 'defalias)
+ (c-should nil 'if)
+ (c-should nil '+)
+ (c-should nil 1)
+ (c-should nil nil)
+ (c-should nil "macro")
+ (c-should t '(macro . +))))
+
+(ert-deftest compat-string-suffix-p ()
+ "Check if `string-suffix-p' was implemented correctly."
+ (compat-test string-suffix-p
+ (c-should t "a" "abba")
+ (c-should t "ba" "abba")
+ (c-should t "abba" "abba")
+ (c-should nil "a" "ABBA")
+ (c-should nil "bA" "ABBA")
+ (c-should nil "aBBA" "ABBA")
+ (c-should nil "c" "ABBA")
+ (c-should nil "c" "abba")
+ (c-should nil "cddc" "abba")
+ (c-should nil "aabba" "abba")))
+
+(ert-deftest compat-split-string ()
+ "Check if `split-string' was advised correctly."
+ (compat-test split-string
+ (c-should* '("a" "b" "c") "a b c")
+ (c-should* '("..a.." "..b.." "..c..") "..a.. ..b.. ..c..")
+ (c-should* '("a" "b" "c") "..a.. ..b.. ..c.." nil nil "\\.+")))
+
+(ert-deftest compat-delete-consecutive-dups ()
+ "Check if `delete-consecutive-dups' was implemented correctly."
+ (compat-test delete-consecutive-dups
+ (c-should '(1 2 3 4) '(1 2 3 4))
+ (c-should '(1 2 3 4) '(1 2 2 3 4 4))
+ (c-should '(1 2 3 2 4) '(1 2 2 3 2 4 4))))
+
+(ert-deftest compat-autoloadp ()
+ "Check if `autoloadp' was implemented correctly."
+ (compat-test autoloadp
+ (c-should t '(autoload . anything))
+ (c-should nil 'anything)))
+
+(ert-deftest compat-file-name-base ()
+ "Check if `file-name-base' was implemented correctly."
+ (compat-test file-name-base
+ (c-should "file" "file.txt")
+ (c-should "file" "/path/to/some/file.txt")
+ (c-should "file" "/path/to/some/file")))
+
+(ert-deftest compat-posnp ()
+ "Check if `posnp' was implemented correctly."
+ (compat-test posnp
+ ;; FIXME: return an actual posn.
+ ;; (c-should t (posn-at-point))
+ (c-should nil (current-buffer))
+ (c-should nil (point-max))
+ (c-should nil (point-min))
+ (c-should nil nil)))
+
+(ert-deftest compat-string-clean-whitespace ()
+ "Check if `string-clean-whitespace' was implemented correctly."
+ (compat-test string-clean-whitespace
+ (c-should "a b c" "a b c")
+ (c-should "a b c" " a b c")
+ (c-should "a b c" "a b c ")
+ (c-should "a b c" "a b c")
+ (c-should "a b c" "a b c")
+ (c-should "a b c" "a b c")
+ (c-should "a b c" " a b c")
+ (c-should "a b c" "a b c ")
+ (c-should "a b c" " a b c ")
+ (c-should "aa bb cc" "aa bb cc")
+ (c-should "aa bb cc" " aa bb cc")
+ (c-should "aa bb cc" "aa bb cc ")
+ (c-should "aa bb cc" "aa bb cc")
+ (c-should "aa bb cc" "aa bb cc")
+ (c-should "aa bb cc" "aa bb cc")
+ (c-should "aa bb cc" " aa bb cc")
+ (c-should "aa bb cc" "aa bb cc ")
+ (c-should "aa bb cc" " aa bb cc ")))
+
+(ert-deftest compat-string-fill ()
+ "Check if `string-fill' was implemented correctly."
+ (compat-test string-fill
+ (c-should "a a a a a" "a a a a a" 9)
+ (c-should "a a a a a" "a a a a a" 10)
+ (c-should "a a a a\na" "a a a a a" 8)
+ (c-should "a a a a\na" "a a a a a" 8)
+ (c-should "a a\na a\na" "a a a a a" 4)
+ (c-should "a\na\na\na\na" "a a a a a" 2)
+ (c-should "a\na\na\na\na" "a a a a a" 1)))
+
+(ert-deftest compat-string-lines ()
+ "Check if `string-lines' was implemented correctly."
+ (compat-test string-lines
+ (c-should '("a" "b" "c") "a\nb\nc")
+ (c-should '("a" "b" "c" "") "a\nb\nc\n")
+ (c-should '("a" "b" "c") "a\nb\nc\n" t)
+ (c-should '("abc" "bcd" "cde") "abc\nbcd\ncde")
+ (c-should '(" abc" " bcd " "cde ") " abc\n bcd \ncde ")))
+
+(ert-deftest compat-string-pad ()
+ "Check if `string-pad' was implemented correctly."
+ (compat-test string-pad
+ (c-should "a " "a" 4)
+ (c-should "aaaa" "aaaa" 4)
+ (c-should "aaaaaa" "aaaaaa" 4)
+ (c-should "a..." "a" 4 ?.)
+ (c-should " a" "a" 4 nil t)
+ (c-should "...a" "a" 4 ?. t)))
+
+(ert-deftest compat-string-chop-newline ()
+ "Check if `string-chop-newline' was implemented correctly."
+ (compat-test string-chop-newline
+ (c-should "" "")
+ (c-should "" "\n")
+ (c-should "aaa" "aaa")
+ (c-should "aaa" "aaa\n")
+ (c-should "aaa\n" "aaa\n\n")))
+
+(ert-deftest compat-macroexpand-1 ()
+ "Check if `macroexpand-1' was implemented correctly."
+ (compat-test macroexpand-1
+ (c-should '(if a b c) '(if a b c))
+ (c-should '(if a (progn b)) '(when a b))
+ (c-should '(if a (progn (unless b c))) '(when a (unless b c)))))
+
+(ert-deftest compat-file-size-human-readable ()
+ "Check if `file-size-human-readable' was advised properly."
+ (compat-test file-size-human-readable
+ (c-should* "1000" 1000)
+ (c-should* "1k" 1024)
+ (c-should* "1M" (* 1024 1024))
+ (c-should* "1G" (expt 1024 3))
+ (c-should* "1T" (expt 1024 4))
+ (c-should* "1k" 1000 'si)
+ (c-should* "1KiB" 1024 'iec)
+ (c-should* "1KiB" 1024 'iec)
+ (c-should* "1 KiB" 1024 'iec " ")
+ (c-should* "1KiA" 1024 'iec nil "A")
+ (c-should* "1 KiA" 1024 'iec " " "A")
+ (c-should* "1kA" 1000 'si nil "A")
+ (c-should* "1 k" 1000 'si " ")
+ (c-should* "1 kA" 1000 'si " " "A")))
+
+(ert-deftest compat-format-prompt ()
+ "Check if `file-size-human-readable' was implemented properly."
+ (compat-test format-prompt
+ (c-should "Prompt: " "Prompt" nil)
+ (c-should "Prompt (default 3): " "Prompt" 3)
+ (c-should "Prompt (default abc): " "Prompt" "abc")
+ (c-should "Prompt (default abc def): " "Prompt" "abc def")
+ (c-should "Prompt 10: " "Prompt %d" nil 10)
+ (c-should "Prompt \"abc\" (default 3): " "Prompt %S" 3 "abc")))
+
+(provide 'compat-tests)
+;;; compat-tests.el ends here
+
+;; Local Variables:
+;; elisp-shorthands: (("c-" . "compat--"))
+;; End:
diff --git a/compat.el b/compat.el
new file mode 100644
index 0000000..c9b9103
--- /dev/null
+++ b/compat.el
@@ -0,0 +1,90 @@
+;;; compat.el --- Compatibility Library -*- lexical-binding: t;
-*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Maintainer: Philip Kaludercic <philipk@posteo.net>
+;; Version: 28.1.0.0-dev
+;; URL: https://git.sr.ht/~pkal/compat/
+;; Package-Requires: ((emacs "24.1"))
+;; Keywords: lisp
+
+;; 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:
+
+;; To allow for the usage of Emacs functions and macros that are
+;; defined in newer versions of Emacs, compat.el provides definitions
+;; that are installed ONLY if necessary. These reimplementations of
+;; functions and macros are at least subsets of the actual
+;; implementations. Be sure to read the documentation string to make
+;; sure.
+;;
+;; Not every function provided in newer versions of Emacs is provided
+;; here. Some depend on new features from the core, others cannot be
+;; implemented to a meaningful degree. The main audience for this
+;; library are not regular users, but package maintainers. Therefore
+;; commands and user options are usually not implemented here.
+
+;;; Code:
+
+(eval-when-compile (require 'compat-macs))
+
+;;;; Core functionality
+
+;; Suppress errors triggered by requiring non-existent libraries in
+;; older versions of Emacs (e.g. subr-x).
+(compat-advise require (feature &optional filename noerror)
+ "Avoid throwing an error if library has compatibility code."
+ :force t
+ (condition-case err
+ (funcall oldfun feature filename noerror)
+ (file-missing
+ ;; FIXME: avoid false negatives, check if compat defined a
+ ;; feature.
+ (unless (assq feature after-load-alist)
+ (signal (car err) (cdr err))))))
+
+;; Load the actual compatibility definitions:
+(when (version< emacs-version "24.2")
+ (require 'compat-24.2))
+(when (version< emacs-version "24.3")
+ (require 'compat-24.3))
+(when (version< emacs-version "24.4")
+ (require 'compat-24.4))
+(when (version< emacs-version "25")
+ (require 'compat-25.1))
+(when (version< emacs-version "26")
+ (require 'compat-26.1))
+(when (version< emacs-version "27")
+ (require 'compat-27.1))
+(when (version< emacs-version "28")
+ (require 'compat-28.1))
+
+;;;; Etcetera
+
+;; ;;;; Ensure NonGNU ELPA is in `package-archives'
+;; (with-eval-after-load 'package
+;; (unless (or (rassoc "https://elpa.nongnu.org/nongnu/"; package-archives)
+;; (rassoc "http://elpa.nongnu.org/nongnu/"; package-archives)
+;; (rassoc "https://elpa.nongnu.org/nongnu-devel/"; package-archives)
+;; (rassoc "http://elpa.nongnu.org/nongnu-devel/"; package-archives))
+;; (add-to-list 'package-archives '("nongnu" .
"https://elpa.nongnu.org/nongnu/";))))
+
+;; To ensure that compat.el is loaded as soon as possible, a require
+;; call is inserted directly into the autoload file:
+;;;###autoload (require 'compat)
+
+(provide 'compat)
+;;; compat.el ends here
- [elpa] branch externals/compat created (now 5506770), ELPA Syncer, 2021/10/17
- [elpa] externals/compat 51b832c 02/99: Remove compat--disable-defer check from installation check, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 10033e0 01/99: Initial import,
ELPA Syncer <=
- [elpa] externals/compat e00fc9c 03/99: Simplify mapcan implementation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 9688d79 05/99: Split proper-list-p into two implementations, ELPA Syncer, 2021/10/17
- [elpa] externals/compat c445418 04/99: Fix named-let implementation, ELPA Syncer, 2021/10/17
- [elpa] externals/compat b8e8cba 07/99: Use markdown instead of outline-mode for the README file, ELPA Syncer, 2021/10/17
- [elpa] externals/compat a403485 10/99: Require compat-macs in eval-when-compile instead of eval-and-compile, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 0d77194 14/99: Remove compat--disable-defer variable, ELPA Syncer, 2021/10/17
- [elpa] externals/compat eafe584 15/99: Remove unnecessary eval-and-compile block from compat-tests, ELPA Syncer, 2021/10/17
- [elpa] externals/compat c7d1615 06/99: Remove elisp-shorthands from compat-tests.el, ELPA Syncer, 2021/10/17
- [elpa] externals/compat 5936773 08/99: Fix installation check, ELPA Syncer, 2021/10/17
- [elpa] externals/compat d77b31f 11/99: Reorder files to byte compile in Makefile, ELPA Syncer, 2021/10/17