pax_global_header 0000666 0000000 0000000 00000000064 14730150706 0014515 g ustar 00root root 0000000 0000000 52 comment=a7e7842c615e149ad7d7e57f383936b49dcb129f
activities.el-0.7.2/ 0000775 0000000 0000000 00000000000 14730150706 0014266 5 ustar 00root root 0000000 0000000 activities.el-0.7.2/.elpaignore 0000664 0000000 0000000 00000000101 14730150706 0016404 0 ustar 00root root 0000000 0000000 .elpaignore
Makefile
makem.sh
NOTES.org
.github/
images/
tests/
activities.el-0.7.2/.gitignore 0000664 0000000 0000000 00000000031 14730150706 0016250 0 ustar 00root root 0000000 0000000 *.elc
/.sandbox/
/NOTES/
activities.el-0.7.2/LICENSE 0000664 0000000 0000000 00000104513 14730150706 0015277 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
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.
Copyright (C)
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 .
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:
Copyright (C)
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
.
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
.
activities.el-0.7.2/NOTES.org 0000777 0000000 0000000 00000000000 14730150706 0020153 2NOTES/NOTES.org ustar 00root root 0000000 0000000 activities.el-0.7.2/README.org 0000664 0000000 0000000 00000050165 14730150706 0015743 0 ustar 00root root 0000000 0000000 #+TITLE: activities.el
# NOTE: It would be preferable to put these at the bottom of the file under the export options heading, but it seems that "TEXINFO_DIR_CATEGORY" only works at the top of the file.
#+EXPORT_FILE_NAME: activities.texi
#+TEXINFO_DIR_CATEGORY: Emacs
#+TEXINFO_DIR_TITLE: Activities: (activities)
#+TEXINFO_DIR_DESC: Suspend/resume activities (sets of windows, frames, and buffers)
# ELPA badge image.
[[https://elpa.gnu.org/packages/activities.html][file:https://elpa.gnu.org/packages/activities.svg]]
Inspired by Genera's and KDE's concepts of "activities", this Emacs library allows the user to manage frames/tabs, windows, and buffers according to their purpose. An "activity" comprises a frame or tab, its window configuration, and the buffers displayed in them--its "state"; this state would be related to a certain task the user performs at various times, such as developing a certain software project, reading and writing email, working with one's Org mode system, etc.
"Suspending" an activity saves the activity's state and closes its frame/tab; the user would do this when finished with the activity's task for the time being. "Resuming" the activity restores its buffers and windows to its frame/tab; the user would do this when ready to resume the task at a later time. This saves the user from having to manually arrange the same windows and buffers each time the task is to be done.
Each activity saves two states: the default state, set when the activity is defined by the user, and the last-used state, which was how the user left it when the activity was suspended (or when Emacs exited, etc). This allows the user to resume the activity where the task was left off, while also allowing it to be reverted to the default state, providing a consistent entry point into the activity.
Internally, the Emacs ~bookmark~ library is used to save and restore buffers' states--that is, any major mode that supports the bookmark system is compatible. A buffer whose major mode does not support the bookmark system (or does not support it well enough to restore useful state) is not compatible and can't be fully restored, or perhaps not at all; but solving that is as simple as implementing bookmark support for the mode, which is often trivial.
Various hooks are (or will be--feedback is welcome) provided, both globally and per-activity, so that the user can define functions to be called when an activity is saved, restored, or switched from/to. For example, this could be used to limit the set of buffers offered for switching to within an activity, or to track the time spent in an activity.
* Contents :noexport:
:PROPERTIES:
:TOC: :include siblings :depth 0 :force (nothing) :ignore (this) :local (nothing)
:END:
:CONTENTS:
- [[#installation][Installation]]
- [[#configuration][Configuration]]
- [[#usage][Usage]]
- [[#faq][FAQ]]
- [[#changelog][Changelog]]
- [[#development][Development]]
:END:
* Installation
** GNU ELPA
~activities~ may be installed into Emacs versions 29.1 or later from [[https://elpa.gnu.org/packages/activities.html][GNU ELPA]] by using the command ~M-x package-install RET activities RET~. This will install the latest stable release, which is recommended.
** Quelpa
To install directly from git (e.g. to test a pre-release version), it's recommended to use [[https://framagit.org/steckerhalter/quelpa][Quelpa]]:
1. Install [[https://framagit.org/steckerhalter/quelpa-use-package#installation][quelpa-use-package]] (which can be installed directly from MELPA).
2. Add this form to your init file (see [[Configuration][Configuration]] for more details):
#+BEGIN_SRC elisp
(use-package activities
:quelpa (activities :fetcher github :repo "alphapapa/activities.el"))
#+END_SRC
If you choose to install it otherwise, please note that the author can't offer help with manual installation problems.
* Configuration
This is the recommended configuration, in terms of a ~use-package~ form to be placed in the user's init file:
#+BEGIN_SRC elisp
(use-package activities
:init
(activities-mode)
(activities-tabs-mode)
;; Prevent `edebug' default bindings from interfering.
(setq edebug-inhibit-emacs-lisp-mode-bindings t)
:bind
(("C-x C-a C-n" . activities-new)
("C-x C-a C-d" . activities-define)
("C-x C-a C-a" . activities-resume)
("C-x C-a C-s" . activities-suspend)
("C-x C-a C-k" . activities-kill)
("C-x C-a RET" . activities-switch)
("C-x C-a b" . activities-switch-buffer)
("C-x C-a g" . activities-revert)
("C-x C-a l" . activities-list)))
#+END_SRC
* Usage
** Activities
For the purposes of this library, an "activity" is a window configuration and its associated buffers. When an activity is "resumed," its buffers are recreated and loaded into the window configuration, which is loaded into a frame or tab.
From the user's perspective, an "activity" should be thought of as something like, "reading my email," "working on my Emacs library," "writing my book," "working for this client," etc. The user arranges a set of windows and buffers according to what's needed, then saves it as a new activity. Later, when the user wants to return to doing that activity, the activity is "resumed," which restores the activity's last-seen state, allowing the user to pick up where the activity was left off; but the user may also revert the activity to its default state, which may be used as a kind of entry point to doing the activity in general.
** Compatibility
This library is designed to not interfere with other workflows and tools; it is intended to coexist and allow integration with them. For example, when ~activities-tabs-mode~ is enabled, non-activity-related tabs are not affected by it; and the user may close any tab using existing tab commands, regardless of whether it is associated with an activity.
** Modes
+ ~activities-mode~ :: Automatically saves activities' states when Emacs is idle and when Emacs exits. Should be enabled while using this package (otherwise you would have to manually call ~activities-save-all~, which would defeat much of the purpose of this library).
+ ~activities-tabs-mode~ :: Causes activities to be managed as ~tab-bar~ tabs rather than frames (the default). (/This is what the author uses; bugs present when this mode is not enabled are less likely to be found, so please report them./)
** Workflow
An example of a workflow using activities:
1. Arrange windows in a tab according to an activity you're performing.
2. Call ~activities-define~ (~C-x C-a C-d~) to save the activity under a name.
3. Perform the activity for a while.
4. Change window configuration, change tab, close the tab, or even restart Emacs.
5. Call ~activities-resume~ (~C-x C-a C-a~) to resume the activity where you left off.
6. Return to the original activity state with ~activities-revert~ (~C-x C-a g~).
7. Rearrange windows and buffers.
8. Call ~activities-define~ with a universal prefix argument (~C-u C-x C-a C-d~) to redefine an activity's default state.
9. Suspend the activity with ~activities-suspend~ (~C-x C-a s~) (which saves its last state and closes its frame/tab).
** Bindings
Key bindings are, as always, ultimately up to the user. However, in [[Configuration][Configuration]], we suggest a set of bindings with a simple philosophy behind them:
+ A binding ending in a ~C~-prefixed key is expected to result in the set of active activities being changed (e.g. defining a new activity, switching to one, or suspending one).
+ A binding not ending in a ~C~-prefixed key is expected to modify an activity (e.g. reverting it) or do something else (like listing activities.)
** Commands
/With the recommended bindings:/
+ ~activities-list~ (~C-x C-a l~) :: List activities in a ~vtable~ buffer in which they can be managed with various commands.
+ ~activities-new~ (~C-x C-a C-n~) :: Switch to a new, empty activity (i.e. one showing a new frame/tab).
+ ~activities-define~ (~C-x C-a C-d~) :: Define a new activity whose default state is the current frame's or tab's window configuration. With prefix argument, redefine an existing activity (thereby updating its default state to the current state).
+ ~activities-suspend~ (~C-x C-a C-s~) :: Save an activity's state and close its frame or tab.
+ ~activities-kill~ (~C-x C-a C-k~) :: Discard an activity's last state (so when it is resumed, its default state will be used), and close its frame or tab.
+ ~activities-resume~ (~C-x C-a C-a~) :: Resume an activity, switching to a new frame or tab for its window configuration, and restoring its buffers. With prefix argument, restore its default state rather than its last.
+ ~activities-revert~ (~C-x C-a g~) :: Revert an activity to its default state.
+ ~activities-switch~ (~C-x C-a RET~) :: Switch to an already-active activity.
+ ~activities-switch-buffer~ (~C-x C-a b~) :: Switch to a buffer associated with the current activity (or, with prefix argument, another activity).
+ ~activities-rename~ :: Rename an activity.
+ ~activities-discard~ :: Discard an activity permanently.
+ ~activities-save-all~ :: Save all active activities' states. (~activities-mode~ does this automatically, so this command should rarely be needed.)
** Bookmarks
When option ~activities-bookmark-store~ is enabled, an Emacs bookmark is stored when a new activity is made. This allows the command ~bookmark-jump~ (~C-x r b~) to be used to resume an activity (helping to universalize the bookmark system).
* FAQ
+ How is this different from [[https://github.com/alphapapa/burly.el][Burly.el]] or [[https://github.com/alphapapa/bufler.el/][Bufler.el]]? :: Burly is a well-polished tool for restoring window and frame configurations, which could be considered an incubator for some of the ideas furthered here. Bufler's ~bufler-workspace~ library uses Burly to provide some similar functionality, which is at an exploratory stage. ~activities~ hopes to provide a longer-term solution more suitable for integration into Emacs.
+ How does this differ from "workspace" packages? :: Yes, there are many Emacs packages that provide "workspace"-like features in one way or another. To date, only Burly and Bufler seem to offer the ability to restore one across Emacs sessions, including non-file-backed buffers. As mentioned, ~activities~ is intended to be more refined and easier to use (e.g. automatically saving activities' states when ~activities-mode~ is enabled). Comparisons to other packages are left to the reader; suffice to say that ~activities~ is intended to provide what other tools haven't, in an idiomatic, intuitive way. (Feedback is welcome.)
+ How does this differ from the built-in ~desktop-mode~? :: As best this author can tell, ~desktop-mode~ saves and restores one set of buffers, with various options to control its behavior. It does not use ~bookmark~ internally, which prevents it from restoring non-file-backed buffers. As well, it is not intended to be used on-demand to switch between sets of buffers, windows, or frames (i.e. "activities").
+ "Activities" haven't seemed to pan out for KDE. Why would they in Emacs? :: KDE Plasma's Activities system requires applications that can save and restore their state through Plasma, which only (or mostly only?) KDE apps can do, limiting the usefulness of the system. However, Emacs offers a coherent environment, similar to Lisp machines of yore, and its ~bookmark~ library offers a way for any buffer's major mode to save and restore state, if implemented (which many already are).
+ Why did a buffer not restore correctly? :: Most likely because that buffer's major mode does not support Emacs bookmarks (which ~activities~ uses internally to save and restore buffer state). But many, if not most, major modes do; and for those that don't, implementing such support is usually trivial (and thereby benefits Emacs as a whole, not just ~activities~). So contact the major mode's maintainer and ask that ~bookmark~ support be implemented.
+ Why did I get an error? :: Because ~activities~ is at an early stage of development and some of these features are not simple to implement. But it's based on Burly, which has already been through much bug-fixing, so it should proceed smoothly. Please report any bugs you find.
* Changelog
** v0.7.2
*Fixes*
+ Handle errors from window parameter deserializers. ([[https://github.com/alphapapa/activities.el/issues/44][#44]]. Thanks to [[https://github.com/karthink][Karthik Chikmagalur]] and [[https://github.com/stardiviner][stardiviner]] for reporting.)
** v0.7.1
*Fixes*
+ Race condition when restoring multiple activities in rapid succession from user code. ([[https://github.com/alphapapa/activity.el/pull/98][#98]]. Thanks to [[https://github.com/jdtsmith][JD Smith]].)
+ Command ~activities-resume~ resets when called with a universal prefix argument. ([[https://github.com/alphapapa/activities.el/pull/75][#75]]. Thanks to [[https://breatheoutbreathe.in][Joseph Turner]].)
+ Refreshing activities list. ([[https://github.com/alphapapa/activities.el/pull/77][#77]]. Thanks to [[https://breatheoutbreathe.in][Joseph Turner]].)
+ Autoload bookmark handler. ([[https://github.com/alphapapa/activity.el/pull/114][#114]]. Thanks to [[https://breatheoutbreathe.in][Joseph Turner]].)
** v0.7
*Additions*
+ Command ~activities-new~ switches to a new, "empty" activity. (See [[https://github.com/alphapapa/activities.el/issues/46][#46]].)
*Changes*
+ Command ~activities-new~ renamed to ~activities-define~, with new binding ~C-x C-a C-d~. (See [[https://github.com/alphapapa/activities.el/issues/46][#46]].)
+ Improve error message when jumping to a buffer's bookmark signals an error.
*Fixes*
+ Suspending/killing an activity when only one frame/tab is open.
+ Generation of Info manual on GNU ELPA. (Thanks to Stefan Monnier.)
+ Ignore minimum window sizes and fixed size restrictions. ([[https://github.com/alphapapa/activity.el/issues/56][#56]]. Thanks to [[https://github.com/jellelicht][Jelle Licht]].)
** v0.6
*Additions*
+ Command ~activities-switch-buffer~ switches to a buffer associated with the current activity (or, with prefix argument, another activity). (A buffer is considered to be associated with an activity if it has been displayed in its tab. Note that this feature currently requires ~activities-tabs-mode~.)
+ Command ~activities-rename~ renames an activity.
+ Option ~activities-after-switch-functions~, a hook called after switching to an activity.
+ Option ~activities-set-frame-name~ sets the frame name after switching to an activity. ([[https://github.com/alphapapa/activities.el/issues/33][#33]]. Thanks to [[https://github.com/jdtsmith][JD Smith]].)
+ Option ~activities-kill-buffers~, when suspending an activity, kills buffers that were only shown in that activity.
*Changes*
+ Default time format in activities list.
+ When saving all activities, don't persist to disk for each activity. ([[https://github.com/alphapapa/activities.el/issues/34][#34]]. Thanks to [[https://github.com/yrns][Al M.]] for reporting.)
** v0.5.1
*Fixes*
+ Listing activities without last-saved states.
** v0.5
*Additions*
+ Suggest setting variable ~edebug-inhibit-emacs-lisp-mode-bindings~ to avoid conflicts with suggested keybindings.
+ Option ~activities-bookmark-warnings~ enables warning messages when a non-file-visiting buffer can't be bookmarked (for debugging purposes).
+ Option ~activities-resume-into-frame~ controls whether resuming an activity opens a new frame or uses the current one (when ~activities-tabs-mode~ is disabled). ([[https://github.com/alphapapa/activities.el/issues/22][#22]]. Thanks to [[https://github.com/Icy-Thought][Icy-Thought]] for suggesting.)
*Changes*
+ Command ~activities-kill~ now discards an activity's last state (while ~activities-suspend~ saves its last state), and closes its frame or tab.
+ Face ~activities-tabs-face~ is renamed to ~activities-tabs~, and now inherits from another face by default, which allows it to adjust with the loaded theme. ([[https://github.com/alphapapa/activities.el/issues/24][#24]]. Thanks to [[https://github.com/karthink][Karthik Chikmagalur]] for suggesting.)
*Fixes*
+ Show a helpful error if a bookmark's target file is missing. ([[https://github.com/alphapapa/activities.el/issues/17][#17]]. Thanks to [[https://github.com/jdtsmith][JD Smith]] for reporting.)
+ Sort order in ~activities-list~.
+ When discarding an inactive activity, don't switch to it first. ([[https://github.com/alphapapa/activity.el/issues/18][#18]]. Thanks to [[https://github.com/jdtsmith][JD Smith]] for reporting.)
+ Don't signal an error when ~debug-on-error~ is enabled and a buffer is not visiting a file. ([[https://github.com/alphapapa/activity.el/issues/25][#25]]. Thanks to [[https://github.com/karthink][Karthik Chikmagalur]] for reporting.)
** v0.4
*Additions*
+ Option ~activities-anti-save-predicates~ prevents saving activity states at inappropriate times.
*Fixes*
+ Don't save activity state if a minibuffer is active.
+ Offer only active activities for suspending.
+ Don't raise frame when saving activity states. (See [[https://github.com/alphapapa/activities.el/issues/4][#4]]. Thanks to [[https://github.com/jdtsmith][JD Smith]] for reporting.)
** v0.3.3
*Fixes*
+ Command ~activities-list~ shows a helpful message if no activities are defined. ([[https://github.com/alphapapa/activities.el/issues/11][#11]]. Thanks to [[https://github.com/fuzy112][fuzy112]] for reporting.)
+ Link in documentation (which works locally but not on GNU ELPA at the moment).
** v0.3.2
Updated documentation, etc.
** v0.3.1
*Fixes*
+ Handle case in which ~activities-tabs-mode~ is enabled again without having been disabled (which caused an error in ~tab-bar-mode~). ([[https://github.com/alphapapa/activities.el/issues/7][#7]])
** v0.3
*Additions*
+ Command ~activities-list~ lists activities in a ~vtable~ buffer in which they can be managed.
+ Offer current activity name by default when redefining an activity with ~activities-new~.
+ Record times at which activities' states were updated.
** v0.2
*Additions*
+ Offer current ~project~ name by default for new activities. (Thanks to [[https://breatheoutbreathe.in][Joseph Turner]].)
+ Use current activity as default for various completions. (Thanks to [[https://breatheoutbreathe.in][Joseph Turner]].)
*Fixes*
+ Raise frame after selecting it. (Thanks to [[https://github.com/jdtsmith][JD Smith]] for suggesting.)
** v0.1.3
*Fixes*
+ Autoloads.
+ Command aliases.
** v0.1.2
*Fixes*
+ Some single-window configurations were not restored properly.
** v0.1.1
*Fixes*
+ Silence message about non-file-visiting buffers.
** v0.1
Initial release.
* Development
~activities~ is developed on [[https://github.com/alphapapa/activities.el][GitHub]]. Suggestions, bug reports, and patches are welcome.
** Copyright assignment
This package is part of [[https://www.gnu.org/software/emacs/][GNU Emacs]], being distributed in [[https://elpa.gnu.org/][GNU ELPA]]. Contributions to this project must follow GNU guidelines, which means that, as with other parts of Emacs, patches of more than a few lines must be accompanied by having assigned copyright for the contribution to the FSF. Contributors who wish to do so may contact [[mailto:emacs-devel@gnu.org][emacs-devel@gnu.org]] to request the assignment form.
* COMMENT Export setup :noexport:
:PROPERTIES:
:TOC: :ignore this
:END:
# Copied from org-super-agenda's readme, in which much was borrowed from Org's =org-manual.org=.
#+OPTIONS: broken-links:t *:t num:1 toc:1
** Info export options
# NOTE: See note at top of file.
** File-local variables
# NOTE: Setting org-comment-string buffer-locally is a nasty hack to work around GitHub's org-ruby's HTML rendering, which does not respect noexport tags. The only way to hide this tree from its output is to use the COMMENT keyword, but that prevents Org from processing the export options declared in it. So since these file-local variables don't affect org-ruby, wet set org-comment-string to an unused keyword, which prevents Org from deleting this tree from the export buffer, which allows it to find the export options in it. And since org-export does respect the noexport tag, the tree is excluded from the info page.
# Local Variables:
# before-save-hook: org-make-toc
# org-export-initial-scope: buffer
# org-comment-string: "NOTCOMMENT"
# End:
activities.el-0.7.2/activities-list.el 0000664 0000000 0000000 00000007353 14730150706 0017735 0 ustar 00root root 0000000 0000000 ;;; activities-list.el --- List activities -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; Author: Adam Porter
;; 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 .
;;; Commentary:
;; This library implements a list view for activities.
;;; Code:
(require 'map)
(require 'vtable)
(require 'activities)
(defgroup activities-list nil
"Activities list buffer."
:group 'activities)
(defcustom activities-list-time-format "%Y-%m-%d %H:%M:%S"
"Time format for `activities-list' buffer."
:type 'string)
(defmacro activities-list-command (command)
"Expand to a lambda that applies its args to COMMAND and reverts the list buffer."
`(lambda (&rest args)
(let ((list-buffer (current-buffer)))
(apply #',command args)
(with-current-buffer list-buffer
(vtable-revert-command)))))
;;;###autoload
(defun activities-list ()
"List activities."
(interactive)
(unless activities-activities
(user-error (substitute-command-keys "No activities defined (to define one, type \"\\[activities-new]\")")))
(with-current-buffer (get-buffer-create "*Activities*")
(let ((inhibit-read-only t))
(read-only-mode)
(erase-buffer)
(make-vtable
:columns
`(( :name "Active" :primary descend
:getter (lambda (object _table)
(if (activities-activity-active-p object)
"*" " ")))
( :name "Name"
:getter (lambda (object _table)
(activities-activity-name object)))
( :name "Last saved"
:getter (lambda (activity _table)
(pcase-let (((cl-struct activities-activity last) activity))
(when last
(map-elt (activities-activity-state-etc last) 'time))))
:formatter activities-list--format-time)
( :name "Default saved"
:getter (lambda (activity _table)
(pcase-let (((cl-struct activities-activity default) activity))
(when default
(map-elt (activities-activity-state-etc default) 'time))))
:formatter activities-list--format-time))
:objects-function (lambda ()
(map-values activities-activities))
:sort-by '((2 . descend) (0 . descend))
:actions `("q" (lambda (&rest _) (bury-buffer))
"n" (lambda (&rest _) (forward-line 1))
"p" (lambda (&rest _) (forward-line -1))
"RET" ,(activities-list-command activities-resume)
"k" ,(activities-list-command activities-kill)
"s" ,(activities-list-command activities-suspend)
"D" ,(activities-list-command activities-discard)))
(pop-to-buffer (current-buffer)))))
;;;###autoload
(defalias 'list-activities #'activities-list)
(defun activities-list--format-time (time)
"Return TIME formatted according to `activities-list-time-format', which see.."
(if time
(format-time-string activities-list-time-format time)
"never"))
;;;; Footer
(provide 'activities-list)
;;; activities-list.el ends here
activities.el-0.7.2/activities-tabs.el 0000664 0000000 0000000 00000022244 14730150706 0017707 0 ustar 00root root 0000000 0000000 ;;; activities-tabs.el --- Integrate activities with tabs -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; Author: Adam Porter
;; 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 .
;;; Commentary:
;; This library integrates activities with `tab-bar-mode' tabs.
;;; Code:
;;;; Requirements
(require 'activities)
(require 'tab-bar)
;;;; Variables
(defvar activities-tabs-tab-bar-tab-face-function-original nil
"Records the original value of `tab-bar-tab-face-function'.
When `activities-tabs-mode' is enabled.")
(defvar activities-kill-buffers)
;;;; Customization
(defgroup activities-tabs nil
"Integrates activities and tabs."
:group 'activities)
(defcustom activities-tabs-before-resume-functions nil
"Functions called before resuming an activity.
Each is called with one argument, the activity."
:type 'hook)
(defface activities-tabs
`((t :inherit font-lock-function-name-face))
"Applied to tab-bar faces for tabs representing activities.")
;;;; Mode
;;;###autoload
(define-minor-mode activities-tabs-mode
"Integrate Activities with `tab-bar-mode'.
When active, activities are opened in new tabs and named
accordingly."
:global t
:group 'activities
(let ((override-map '((activities-activity-active-p . activities-tabs-activity-active-p)
(activities--set . activities-tabs-activity--set)
(activities--switch . activities-tabs--switch)
(activities-current . activities-tabs-current)
(activities-close . activities-tabs-close)
(activities-switch-buffer . activities-tabs--switch-buffer))))
(if activities-tabs-mode
(progn
(tab-bar-mode 1)
(add-hook 'window-configuration-change-hook #'activities-tabs--window-configuration-change)
(advice-add #'activities-resume :before #'activities-tabs-before-resume)
(pcase-dolist (`(,symbol . ,function) override-map)
(advice-add symbol :override function))
;; The mode command could be called to activate the mode
;; when it already is, in which case we must not swap the
;; tab-face-function again, which would discard the actual,
;; original value. (IOW, this must be idempotent.)
;; TODO: A way to prevent modes' body forms from being
;; reevaluated when they are already active.
(unless activities-tabs-tab-bar-tab-face-function-original
(setf activities-tabs-tab-bar-tab-face-function-original tab-bar-tab-face-function
tab-bar-tab-face-function #'activities-tabs--tab-bar-tab-face-function)))
(remove-hook 'window-configuration-change-hook #'activities-tabs--window-configuration-change)
(advice-remove #'activities-resume #'activities-tabs-before-resume)
(pcase-dolist (`(,symbol . ,function) override-map)
(advice-remove symbol function))
(when activities-tabs-tab-bar-tab-face-function-original
(setf tab-bar-tab-face-function activities-tabs-tab-bar-tab-face-function-original
activities-tabs-tab-bar-tab-face-function-original nil)))))
;;;; Commands
(defun activities-tabs--switch-buffer (activity)
"Switch to a buffer associated with ACTIVITY.
Interactively, select from buffers associated with ACTIVITY; or,
with prefix argument, choose another activity."
(interactive
(list (if current-prefix-arg
(activities-completing-read)
(or (activities-current) (activities-completing-read)))))
;; Much code borrowed from `read-buffer-to-switch', which see.
(let* ((tab (activities-tabs--tab activity))
(activity-buffers (activities-tabs--tab-parameter 'activities-buffer-list tab))
(current-buffer-name (buffer-name (current-buffer)))
(rbts-completion-table
(apply-partially
#'completion-table-with-predicate
#'internal-complete-buffer
(lambda (buffer-name)
(let ((buffer-name (if (consp buffer-name) (car buffer-name) buffer-name)))
(and (not (equal buffer-name current-buffer-name))
(cl-member buffer-name activity-buffers :key #'buffer-name))))
nil))
(selected-buffer
(minibuffer-with-setup-hook
(lambda ()
(setq-local minibuffer-completion-table rbts-completion-table)
(if (and (boundp 'icomplete-with-completion-tables)
(listp icomplete-with-completion-tables))
(setq-local icomplete-with-completion-tables
(cons rbts-completion-table
icomplete-with-completion-tables))))
(read-buffer "Switch to activity buffer:" (other-buffer (current-buffer))
(confirm-nonexistent-file-or-buffer)))))
(switch-to-buffer selected-buffer)))
;;;; Functions
(cl-defun activities-tabs-close (activity)
"Close ACTIVITY.
Its state is not saved, and its frames, windows, and tabs are
closed."
(activities--switch activity)
(activities-tabs--kill-buffers)
(if (= 1 (length (tab-bar-tabs)))
(progn
(tab-bar-new-tab)
(tab-bar-close-other-tabs))
(tab-bar-close-tab)))
(defun activities-tabs--window-configuration-change ()
"Add frame's windows' buffers to the current tab's `buffer-list' parameter."
(cl-assert tab-bar-mode)
(let ((tab (tab-bar--current-tab-find)))
(walk-windows (lambda (window)
(cl-pushnew (window-buffer window)
(alist-get 'activities-buffer-list (cdr tab)))))))
(defun activities-tabs--kill-buffers ()
;; TODO: Frame parameter name should be prefixed with `activities'.
"Kill buffers that are only in the current tab's buffer list.
Only does so when `activities-kill-buffers' is non-nil."
(when activities-kill-buffers
(let* ((all-tabs (funcall tab-bar-tabs-function))
(current-tab (tab-bar--current-tab-find))
(tab-buffers
(cl-reduce
(lambda (acc tab)
(seq-difference acc (activities-tabs--tab-parameter 'activities-buffer-list tab)))
(remove current-tab all-tabs)
:initial-value (activities-tabs--tab-parameter 'activities-buffer-list current-tab)))
(target-buffers (cl-remove-if (lambda (buffer)
(run-hook-with-args-until-success
'activities-anti-kill-predicates buffer))
tab-buffers)))
(mapc #'kill-buffer target-buffers))))
(defun activities-tabs--switch (activity)
"Switch to ACTIVITY.
Selects its tab, making one if needed. Its state is not changed."
(if-let ((tab (activities-tabs--tab activity)))
(tab-bar-switch-to-tab (alist-get 'name tab))
(tab-bar-new-tab))
(tab-bar-rename-tab (activities-name-for activity)))
(defun activities-tabs--tab (activity)
"Return ACTIVITY's tab."
(pcase-let (((cl-struct activities-activity name) activity))
(cl-find-if (lambda (tab)
(when-let ((tab-activity (alist-get 'activity (cdr tab))))
(equal name (activities-activity-name tab-activity))))
(funcall tab-bar-tabs-function))))
(defun activities-tabs-current ()
"Return current activity."
(activities-tabs--tab-parameter 'activity (tab-bar--current-tab-find)))
(defun activities-tabs--tab-parameter (parameter tab)
"Return TAB's PARAMETER."
;; TODO: Make this a gv.
(alist-get parameter (cdr tab)))
(defun activities-tabs--tab-bar-tab-face-function (tab)
"Return a face for TAB.
If TAB represents an activity, face `activities-tabs' is added as
inherited."
;; TODO: Propose a tab-bar equivalent of `tab-line-tab-face-functions'.
(let ((face (funcall activities-tabs-tab-bar-tab-face-function-original tab)))
(if (activities-tabs--tab-parameter 'activity tab)
`(:inherit (activities-tabs ,face))
face)))
(defun activities-tabs-activity--set (activity)
"Set the current activity.
Sets the current tab's `activity' parameter to ACTIVITY."
(let ((tab (tab-bar--current-tab-find)))
(setf (alist-get 'activity (cdr tab)) activity)))
(defun activities-tabs-activity-active-p (activity)
"Return non-nil if ACTIVITY is active.
That is, if any tabs have an `activity' parameter whose
activity's name is NAME."
(activities-tabs--tab activity))
(defun activities-tabs-before-resume (activity &rest _)
"Called before resuming ACTIVITY."
(run-hook-with-args 'activities-tabs-before-resume-functions activity))
;;;; Footer
(provide 'activities-tabs)
;;; activities-tabs.el ends here
activities.el-0.7.2/activities.el 0000664 0000000 0000000 00000117321 14730150706 0016761 0 ustar 00root root 0000000 0000000 ;;; activities.el --- Save/restore sets of windows, tabs/frames, and their buffers -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Free Software Foundation, Inc.
;; Author: Adam Porter
;; Maintainer: Adam Porter
;; URL: https://github.com/alphapapa/activities.el
;; Keywords: convenience
;; Version: 0.7.2
;; Package-Requires: ((emacs "29.1") (persist "0.6"))
;; 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 .
;;; Commentary:
;; Inspired by Genera's and KDE's concepts of "activities", this
;; library allows the user to select an "activity", the loading of
;; which restores a window configuration into a `tab-bar' tab or
;; frame, along with the buffers shown in each window. Saving an
;; activity saves the state for later restoration. Switching away
;; from an activity saves the last-used state for later switching back
;; to, while still allowing the activity's initial or default state to
;; be restored on demand. Resuming an activity loads the last-used
;; state, or the initial/default state when a universal argument is
;; provided.
;; The implementation uses the bookmark system to save buffers'
;; states--that is, any major mode that supports the bookmark system
;; is compatible. A buffer whose major mode does not support the
;; bookmark system (or does not support it well enough to restore
;; useful state) is not compatible and can't be fully restored, or
;; perhaps not at all; but solving that is as simple as implementing
;; bookmark support for the mode, which is usually trivial.
;; Integration with Emacs's `tab-bar-mode' is provided: a window
;; configuration or can be restored to a `tab-bar' tab or to a frame.
;; Various hooks are provided, both globally and per-activity, so that
;; the user can define functions to be called when an activity is
;; saved, restored, or switched from/to. For example, this could be
;; used to limit the set of buffers offered for switching to within an
;; activity, or to track the time spent in an activity.
;;; Acknowledgments:
;; Thanks to Pat Metheny, whose music aided the initial
;; implementation.
;;; Code:
;;;; Requirements
(require 'cl-lib)
(require 'bookmark)
(require 'map)
(require 'persist)
(require 'subr-x)
;;;; Types
(cl-defstruct activities-activity
"FIXME: Docstring."
name default last etc)
(cl-defstruct activities-activity-state
"FIXME: Docstring."
(window-state nil :documentation "Window state (see `window-state-get').")
(etc nil :documentation "Map for miscellaneous data."))
;;;; Debugging
(require 'warnings)
;; NOTE: Uncomment this form and `emacs-lisp-byte-compile-and-load'
;; the file to enable `activities-debug' messages. This is commented
;; out by default because, even though the messages are only displayed
;; when `warning-minimum-log-level' is `:debug' at runtime, if that is
;; so at expansion time, the expanded macro calls format the message
;; and check the log level at runtime, which is not zero-cost.
;; (eval-and-compile (setq-local warning-minimum-log-level nil) (setq-local warning-minimum-log-level :debug))
(cl-defmacro activities-debug (&rest args)
"Display a debug warning showing the runtime value of ARGS.
The warning automatically includes the name of the containing
function, and it is only displayed if `warning-minimum-log-level'
is `:debug' at expansion time (otherwise the macro expands to a
call to `ignore' with ARGS and is eliminated by the
byte-compiler). When debugging, the form also returns nil so,
e.g. it may be used in a conditional in place of nil.
Each of ARGS may be a string, which is displayed as-is, or a
symbol, the value of which is displayed prefixed by its name, or
a Lisp form, which is displayed prefixed by its first symbol.
Before the actual ARGS arguments, you can write keyword
arguments, i.e. alternating keywords and values. The following
keywords are supported:
:buffer BUFFER Name of buffer to pass to `display-warning'.
:level LEVEL Level passed to `display-warning', which see.
Default is :debug."
;; TODO: Can we use a compiler macro to handle this more elegantly?
(pcase-let* ((fn-name (when byte-compile-current-buffer
(with-current-buffer byte-compile-current-buffer
;; This is a hack, but a nifty one.
(save-excursion
(beginning-of-defun)
(cl-second (read (current-buffer)))))))
(plist-args (cl-loop while (keywordp (car args))
collect (pop args)
collect (pop args)))
((map (:buffer buffer) (:level level)) plist-args)
(level (or level :debug))
(string (cl-loop for arg in args
concat (pcase arg
((pred stringp) "%S ")
((pred symbolp)
(concat (upcase (symbol-name arg)) ":%S "))
((pred listp)
(concat "(" (upcase (symbol-name (car arg)))
(pcase (length arg)
(1 ")")
(_ "...)"))
":%S "))))))
(if (eq :debug warning-minimum-log-level)
`(let ((fn-name ,(if fn-name
`',fn-name
;; In an interpreted function: use `backtrace-frame' to get the
;; function name (we have to use a little hackery to figure out
;; how far up the frame to look, but this seems to work).
`(cl-loop for frame in (backtrace-frames)
for fn = (cl-second frame)
when (not (or (subrp fn)
(special-form-p fn)
(eq 'backtrace-frames fn)))
return (make-symbol (format "%s [interpreted]" fn))))))
(display-warning fn-name (format ,string ,@args) ,level ,buffer)
nil)
`(ignore ,@args))))
;;;; Macros
(defmacro activities-with (activity &rest body)
"Evaluate BODY with ACTIVITY active.
Selects ACTIVITY's frame/tab and then switches back."
(declare (indent defun) (debug (sexp body)))
(let ((original-state-var (gensym)))
`(let ((,original-state-var `( :frame ,(selected-frame)
:window ,(selected-window)
:tab-index ,(when (bound-and-true-p tab-bar-mode)
(tab-bar--current-tab-index)))))
(unless (activities-activity-active-p ,activity)
(error "Activity %S not active" (activities-activity-name ,activity)))
(unwind-protect
(progn
(activities--switch ,activity)
,@body)
(pcase-let (((map :frame :window :tab-index) ,original-state-var))
(when frame
(select-frame frame))
(when tab-index
(tab-bar-select-tab (1+ tab-index)))
(when window
(select-window window)))))))
;;;; Variables
(with-demoted-errors "activities: Variable `activities-activities' failed to load persisted data: %S"
(persist-defvar activities-activities nil "FIXME: Docstring."))
(defvar activities-buffer-local-variables nil
"Variables whose value are saved and restored by activities.
Intended to be bound around code calling `activities-' commands.")
(defvar activities-completing-read-history nil
"History for `activities-completing-read'.")
(defvar activities-window-parameters-translators
`((window-preserved-size
(serialize . ,(pcase-lambda (`(,buffer ,direction ,size))
`(,(buffer-name buffer) ,direction ,size)))
(deserialize . ,(pcase-lambda (`(,buffer-name ,direction ,size))
`(,(get-buffer buffer-name) ,direction ,size)))))
"Functions used to serialize and deserialize certain window parameters.
For example, the value of `window-preserved-size' includes a
buffer, which must be serialized to a buffer name, and then
deserialized back to the buffer after it is reincarnated.")
(defvar activities-saving-p nil
"Non-nil when saving activities' states.")
;;;; Customization
(defgroup activities nil
"Activities."
:link '(emacs-commentary-link "activities")
:link '(url-link "https://github.com/alphapapa/activities.el")
:link '(custom-manual "(activities)")
:group 'convenience)
(defcustom activities-always-persist t
"Always persist activity states to disk when saving.
When disabled, only persist them when exiting Emacs.
Generally, leaving this enabled should be fine. However, in case
of unusual bugs, it could be helpful to only save upon exiting
Emacs, so that any unusual state that caused a crash would not be
persisted."
:type 'boolean)
(defcustom activities-name-prefix "α: "
"Prefix applied to activity names in frames/tabs."
:type 'string)
(defcustom activities-bookmark-store t
"Store a bookmark when making a new activity.
This is merely for convenience, offering a way to help unify the
`bookmark' and `activities' interfaces (i.e. allowing
`bookmark-jump' to open an activity rather than requiring the use
of `activities-resume').
Such bookmarks merely point to an activity name; they do not
contain the actual activity metadata, so if an activity is
discarded, such a bookmark could become stale."
:type 'boolean)
(defcustom activities-bookmark-name-prefix "Activity: "
"Prefix for activity bookmark names."
:type 'string)
(defcustom activities-window-persistent-parameters
(list (cons 'header-line-format 'writable)
(cons 'mode-line-format 'writable)
(cons 'tab-line-format 'writable)
(cons 'no-other-window 'writable)
(cons 'no-delete-other-windows 'writable)
(cons 'window-preserved-size 'writable)
(cons 'window-side 'writable)
(cons 'window-slot 'writable))
"Additional window parameters to persist.
See Info node `(elisp)Window Parameters'."
:type '(alist :key-type (symbol :tag "Window parameter")
:value-type (choice (const :tag "Not saved" nil)
(const :tag "Saved" writable))))
(defcustom activities-after-resume-functions nil
"Functions called after resuming an activity.
Called with one argument, the activity."
:type 'hook)
(defcustom activities-before-resume-functions nil
"Functions called before resuming an activity.
Called with one argument, the activity."
:type 'hook)
(defcustom activities-after-switch-functions nil
"Functions called after switching to an activity.
Called with one argument, the activity."
:type 'hook)
(defcustom activities-default-name-fn 'activities--project-name
"Function that returns the default name for a new activity.
The string should not be prefixed by, e.g. \"Activity\" because
prefixes will be added automatically."
:type '(choice (const :tag "No default name" (lambda (&rest _) nil))
(const :tag "Current project's name" activities--project-name)
(function-item :tag "Other function")))
(defcustom activities-set-frame-name t
"Set frame name after switching activity.
Only applies when `activities-tabs-mode' is disabled."
:type 'boolean)
(defcustom activities-anti-kill-predicates
;; TODO(v0.7): Consider removing `activities-buffer-special-p'. from the
;; default value. Not sure if it's really a good idea (e.g. it
;; would prevent Magit buffers from being killed, and for no good
;; reason I can think of).
'(activities-buffer-hidden-p activities-buffer-special-p)
"Predicates which prevent a buffer from being killed.
Used when suspending an activity and `activities-kill-buffers' is
enabled. Each predicate is called with the buffer as its
argument. If any predicate returns non-nil, the buffer is not
killed."
:type '(set (function-item activities-buffer-special-p)
(function-item activities-buffer-hidden-p)
(function :tag "Other predicate")))
(defcustom activities-anti-save-predicates
'(active-minibuffer-window activities--backtrace-visible-p)
"Predicates which prevent an activity's state from being saved.
Each predicate is called without arguments, with the activity to
be saved having been activated. If any predicate returns
non-nil, the activity's state is not saved."
:type '(set (function-item active-minibuffer-window)
(function-item activities--backtrace-visible-p)
(function :tag "Other predicate")))
(defcustom activities-resume-into-frame 'current
"Which frame to resume an activity into.
Only applies when `activities-tabs-mode' is disabled."
:type '(choice (const :tag "Current frame"
:doc "Replace current frame's window configuration"
current)
(const :tag "New frame" :doc "Make a new frame" new)))
(defcustom activities-bookmark-warnings nil
"Warn when a buffer can't be bookmarked.
This is expected to be the case for non-file-visiting buffers
whose major mode does not provide bookmark support, for which no
warning is necessary. This option may be enabled for debugging,
which will cause a message to be printed for such buffers when an
activity's state is saved."
:type 'boolean)
(defcustom activities-kill-buffers nil
"Kill buffers when suspending an activity.
Kills buffers that have only been shown in that activity's
frame/tab."
:type 'boolean)
;;;; Commands
;;;###autoload
(cl-defun activities-define (name &key forcep)
"Define current state as a new activity with NAME.
If FORCEP (interactively, with prefix), redefine existing
activity."
(interactive
(let* ((current-activity-name
(when-let ((current-activity (activities-current)))
(activities-activity-name current-activity)))
(default (or current-activity-name (funcall activities-default-name-fn))))
(list (read-string (format-prompt "New activity name" default) nil nil default)
:forcep current-prefix-arg)))
(when (and (not forcep) (member name (activities-names)))
(user-error "Activity named %S already exists" name))
(let ((activity (make-activities-activity :name name)))
(activities--set activity)
(activities-save activity :defaultp t :lastp t)
(when activities-bookmark-store
(activities-bookmark-store activity))
(activities--switch activity)
activity))
;;;###autoload
(defun activities-new (name)
"Switch to a newly defined activity named NAME."
(interactive
(list (read-string "New activity name: ")))
(when (member name (activities-names))
(user-error "Activity named %S already exists" name))
(let ((activity (make-activities-activity :name name)))
(activities-switch activity)
(activities-set activity :state nil)
(activities-save activity :defaultp t)))
(defun activities-rename (activity name)
"Rename ACTIVITY to NAME."
(interactive
(let* ((activity (activities-completing-read :prompt "Rename activity" :default nil))
(name (read-string (format "Rename activity %S to: "
(activities-activity-name activity)))))
(list activity name)))
(setf activities-activities (map-delete activities-activities
(activities-activity-name activity))
(activities-activity-name activity) name
(map-elt activities-activities name) activity)
(activities--persist))
;;;###autoload
(cl-defun activities-resume (activity &key resetp)
"Resume ACTIVITY.
If RESETP (interactively, with universal prefix), reset to
ACTIVITY's default state; otherwise, resume its last state, if
available."
(interactive
(list (activities-completing-read :prompt "Resume activity" :default nil)
:resetp current-prefix-arg))
(let ((already-active-p (activities-activity-active-p activity)))
(activities--switch activity)
(when (or resetp (not already-active-p))
(activities-set activity :state (if resetp 'default 'last)))))
(defun activities-switch (activity)
"Switch to ACTIVITY.
Interactively, offers active activities."
(interactive
(list (activities-completing-read
:activities (cl-remove-if-not #'activities-activity-active-p activities-activities :key #'cdr)
:prompt "Switch to activity")))
(activities--switch activity)
(run-hook-with-args 'activities-after-switch-functions activity))
(defun activities-suspend (activity)
"Suspend ACTIVITY.
Its last state is saved, and its frames, windows, and tabs are closed."
(interactive
(list (activities-completing-read
:activities (cl-remove-if-not #'activities-activity-active-p
activities-activities :key #'cdr)
:prompt "Suspend activity")))
(activities-save activity :lastp t)
(activities-close activity))
(defun activities-kill (activity)
"Kill ACTIVITY.
Its last state is discarded (so when it is resumed, its default
state will be used), and close its frame or tab."
(interactive
(list (activities-completing-read
:activities (cl-remove-if-not #'activities-activity-active-p
activities-activities :key #'cdr)
:prompt "Kill activity")))
(setf (activities-activity-last activity) nil)
(activities-save activity)
(activities-close activity))
(cl-defun activities-save-all (&key persistp)
"Save all active activities' last states.
With PERSISTP, persist to disk (otherwise see
`activities-always-persist'). To be safe for `kill-emacs-hook',
this demotes errors."
(interactive)
(with-demoted-errors "activities-save-all: ERROR: %S"
(dolist (activity (cl-remove-if-not #'activities-activity-active-p (map-values activities-activities)))
(let ((activities-saving-p t)
;; Don't write to disk for each activity.
(activities-always-persist nil))
(activities-save activity :lastp t)))
(activities--persist persistp)))
(defun activities-revert (activity)
"Reset ACTIVITY to its default state."
(interactive (list (activities-current)))
(unless activity
(user-error "No active activity"))
;; TODO: Consider resetting the activity's buffers list.
(activities-set activity :state 'default))
(defun activities-discard (activity)
"Discard ACTIVITY and its state.
It will not be recoverable."
;; TODO: Discard relevant bookmarks when `activities-bookmark-store' is enabled.
(interactive
(list (activities-completing-read :prompt "Discard activity")))
(when (yes-or-no-p (format "Discard activity %S permanently?" (activities-activity-name activity)))
(ignore-errors
;; FIXME: After fixing all the bugs, remove ignore-errors.
(when (activities-activity-active-p activity)
(activities-close activity)))
(setf activities-activities (map-delete activities-activities (activities-activity-name activity)))))
;;;; Activity mode
;; This mode automatically saves active activities.
(defvar activities-mode-timer nil
"Automatically saves activities according to `activities-mode-idle-frequency'.")
(defgroup activities-mode nil
"Automatically save activities."
:group 'activities)
(defcustom activities-mode-idle-frequency 5
"Automatically save activities when Emacs has been idle this many seconds."
:type 'natnum)
;;;###autoload
(define-minor-mode activities-mode
"Automatically remember activities' state.
accordingly."
:global t
:group 'activities
(if activities-mode
(progn
(setf activities-mode-timer
(run-with-idle-timer activities-mode-idle-frequency t #'activities-save-all))
(add-hook 'kill-emacs-hook #'activities-mode--killing-emacs))
(when (timerp activities-mode-timer)
(cancel-timer activities-mode-timer)
(setf activities-mode-timer nil))
(remove-hook 'kill-emacs-hook #'activities-mode--killing-emacs)))
(defun activities-mode--killing-emacs ()
"Persist all activities' states.
To be called from `kill-emacs-hook'."
(let ((activities-always-persist t))
(activities-save-all)))
;;;; Functions
(cl-defun activities-save (activity &key defaultp lastp persistp)
"Save states of ACTIVITY.
If DEFAULTP, save its default state; if LASTP, its last. If
PERSISTP, force persisting of data (otherwise, data is persisted
according to option `activities-always-persist', which see)."
(activities-with activity
(when (or defaultp lastp)
(unless (run-hook-with-args-until-success 'activities-anti-save-predicates)
(pcase-let* (((cl-struct activities-activity default last) activity)
(new-state (activities-state)))
(setf (activities-activity-default activity) (if (or defaultp (not default)) new-state default)
(activities-activity-last activity) (if (or lastp (not last)) new-state last)))))
;; Always set the value so, e.g. the activity can be modified
;; externally and saved here.
(setf (map-elt activities-activities (activities-activity-name activity)) activity))
(activities--persist persistp))
(cl-defun activities-set (activity &key (state 'last))
"Set ACTIVITY as the current one.
Its STATE (\\+`last' or \\+`default') is loaded into the current frame."
(activities--set activity)
(activities-with activity
(pcase-let (((cl-struct activities-activity name default last) activity))
(pcase state
('default (activities--windows-set (activities-activity-state-window-state default)))
('last (if last
(activities--windows-set (activities-activity-state-window-state last))
(activities--windows-set (activities-activity-state-window-state default))
(message "Activity %S has no last state. Resuming default." name)))))))
(defun activities--set (activity)
"Set current frame's activity parameter to ACTIVITY."
(set-frame-parameter nil 'activity activity))
(defun activities--persist (&optional forcep)
"Persist `activities-activities' to disk if enabled or FORCEP.
See option `activities-always-persist'."
(when (or forcep activities-always-persist)
(persist-save 'activities-activities)))
(defun activities-current ()
"Return the current activity."
(frame-parameter nil 'activity))
(cl-defun activities-close (activity)
"Close ACTIVITY.
Its state is not saved, and its frames, windows, and tabs are
closed."
(activities--switch activity)
(activities--kill-buffers)
;; TODO: Set frame parameter when resuming.
(let ((deleting-frame (selected-frame)))
(when (= 1 (length (frame-list)))
(select-frame (make-frame)))
(delete-frame deleting-frame)))
(defun activities-named (name)
"Return activity having NAME."
(map-elt activities-activities name))
(defun activities--switch (activity)
"Switch to ACTIVITY.
Select's ACTIVITY's frame, making a new one if needed. Its state
is not changed."
(if (activities-activity-active-p activity)
(select-frame (activities--frame activity))
(pcase activities-resume-into-frame
('current nil)
('new (select-frame (make-frame `((activity . ,activity)))))))
(unless activities-saving-p
;; HACK: Don't raise the frame when saving the activity's state.
;; (I don't love this solution, largely because it only applies
;; when not using `activities-tabs-mode', but it will do for now.)
(raise-frame))
(when activities-set-frame-name
(set-frame-name (activities-name-for activity))))
(defun activities--frame (activity)
"Return ACTIVITY's frame."
(pcase-let (((cl-struct activities-activity name) activity))
(cl-find-if (lambda (frame)
(when-let ((frame-activity (frame-parameter frame 'activity)))
(equal name (activities-activity-name frame-activity))))
(frame-list))))
(defun activities-state ()
"Return an activity state for the current frame."
(make-activities-activity-state
:window-state (activities--window-state (selected-frame))
:etc (map-insert nil 'time (current-time))))
(defun activities-activity-active-p (activity)
"Return non-nil if ACTIVITY is active.
That is, if any frames have an `activity' parameter whose
activity's name is NAME."
(activities--frame activity))
(defun activities--window-state (frame)
"Return FRAME's window state."
(with-selected-frame frame
(let* ((window-persistent-parameters (append activities-window-persistent-parameters
window-persistent-parameters))
(window-state (window-state-get nil 'writable)))
(activities--window-serialized window-state))))
(defun activities--window-serialized (state)
"Return window STATE having serialized its parameters."
(cl-labels ((translate-state (state)
"Set windows' buffers in STATE."
(pcase state
(`(leaf . ,_attrs) (translate-leaf state))
((pred atom) state)
(`(,_key . ,(pred atom)) state)
((pred list) (mapcar #'translate-state state))))
(translate-leaf (leaf)
"Translate window parameters in LEAF."
(pcase-let* ((`(leaf . ,attrs) leaf)
((map parameters ('buffer `(,buffer-or-buffer-name . ,_buffer-attrs))) attrs))
(setf (map-elt parameters 'activities-buffer)
(activity--serialize (get-buffer buffer-or-buffer-name)))
(pcase-dolist (`(,parameter . ,(map serialize))
activities-window-parameters-translators)
(when (map-elt parameters parameter)
(setf (map-elt parameters parameter)
(funcall serialize (map-elt parameters parameter)))))
(setf (map-elt attrs 'parameters) parameters)
(cons 'leaf attrs))))
(if-let ((leaf-pos (cl-position 'leaf state)))
;; A one-window frame: the elements following `leaf' are that window's params.
(append (cl-subseq state 0 leaf-pos)
(translate-leaf (cl-subseq state leaf-pos)))
;; Multi-window frame.
(translate-state state))))
(defun activities--windows-set (state)
"Set window configuration according to STATE."
;; HACK: Since `bookmark--jump-via' insists on calling a buffer-display
;; function after handling the bookmark, we use an immediate timer to
;; set the window configuration.
(run-at-time nil nil
(lambda (frame state)
(let ((window-persistent-parameters
(append activities-window-persistent-parameters
window-persistent-parameters)))
(window-state-put state (frame-root-window frame) 'safe)))
(selected-frame)
;; NOTE: We copy the state so as not to mutate the one in storage.
(activities--bufferize-window-state (copy-tree state))))
(defun activities--bufferize-window-state (state)
"Return window state STATE with its buffers reincarnated."
(cl-labels ((bufferize-state (state)
"Set windows' buffers in STATE."
(pcase state
(`(leaf . ,_attrs) (translate-leaf (bufferize-leaf state)))
((pred atom) state)
(`(,_key . ,(pred atom)) state)
((pred list) (mapcar #'bufferize-state state))))
(bufferize-leaf (leaf)
"Recreate buffers in LEAF."
(pcase-let* ((`(leaf . ,attrs) leaf)
((map parameters buffer) attrs)
((map activities-buffer) parameters)
(`(,_buffer-name . ,buffer-attrs) buffer)
(new-buffer (activities--deserialize activities-buffer)))
(setf (map-elt attrs 'buffer) (cons new-buffer buffer-attrs))
(cons 'leaf attrs)))
(translate-leaf (leaf)
"Translate window parameters in LEAF."
(pcase-let* ((`(leaf . ,attrs) leaf)
((map parameters) attrs))
(pcase-dolist (`(,parameter . ,(map deserialize))
activities-window-parameters-translators)
(condition-case-unless-debug nil
(when (map-elt parameters parameter)
(setf (map-elt parameters parameter)
(funcall deserialize (map-elt parameters parameter))))
(error (setf parameters (map-delete parameters parameter)))))
(setf (map-elt attrs 'parameters) parameters)
(cons 'leaf attrs))))
(if-let ((leaf-pos (cl-position 'leaf state)))
;; A one-window frame: the elements following `leaf' are that window's params.
(append (cl-subseq state 0 leaf-pos)
(translate-leaf (bufferize-leaf (cl-subseq state leaf-pos))))
;; Multi-window frame.
(bufferize-state state))))
(cl-defstruct activities-buffer
"FIXME: Docstring."
(bookmark nil :documentation "Bookmark props")
(filename nil :documentation "Filename, if file-backed")
(name nil :documentation "Buffer name")
(local-variables nil)
(etc nil :documentation "Alist for other data."))
(cl-defmethod activity--serialize ((buffer buffer))
"Return `activities-buffer' struct for BUFFER."
(with-current-buffer buffer
(make-activities-buffer
:bookmark (condition-case err
(bookmark-make-record)
(error
(pcase (error-message-string err)
("Buffer not visiting a file or directory")
(_ (when activities-bookmark-warnings
(message (format "Activities: Error while making bookmark for buffer %S: %%S" buffer) err))))
nil))
:filename (buffer-file-name buffer)
:name (buffer-name buffer)
;; TODO: Handle indirect buffers, narrowing.
:etc `((indirectp . ,(not (not (buffer-base-buffer buffer))))
(narrowedp . ,(buffer-narrowed-p)))
:local-variables
(when activities-buffer-local-variables
(cl-loop
for variable in activities-buffer-local-variables
when (buffer-local-boundp variable (current-buffer))
collect (cons variable
(buffer-local-value variable (current-buffer))))))))
(cl-defmethod activities--deserialize ((struct activities-buffer))
"Return buffer for `activities-buffer' STRUCT."
(pcase-let* (((cl-struct activities-buffer bookmark filename name) struct)
(buffer (cond (bookmark (activities--bookmark-buffer struct))
(filename (activities--filename-buffer struct))
(name (activities--name-buffer struct))
(t (error "Activity struct is invalid: %S" struct)))))
(cl-assert (buffer-live-p buffer))
(activities-debug struct buffer)
buffer))
(defun activities--bookmark-buffer (struct)
"Return buffer for `activities-buffer' STRUCT."
;; NOTE: Be aware of the following note from burly.el:
;; NOTE: Due to changes in help-mode.el which serialize natively
;; compiled subrs in the bookmark props, which cannot be read
;; back (which actually break the entire bookmark system when
;; such a props is saved in the bookmarks file), we have to
;; workaround a failure to read here. See bug#56643.
;; Unfortunately, when a bookmarked file no longer exists,
;; `bookmark-handle-bookmark' handles the error itself and returns
;; nil, preventing us from handling the error. Since
;; `bookmark-jump' works by side effect, we have to test whether the
;; buffer was changed in order to know whether it worked. We call
;; it from a temp buffer in case the jumped-to buffer would be the
;; same as the current buffer.
;; FIXME: Use `bookmark-jump`'s DISPLAY-FUNC argument!
(with-temp-buffer
(pcase-let* (((cl-struct activities-buffer bookmark) struct)
(temp-buffer (current-buffer))
(error)
(jumped-to-buffer
(save-window-excursion
(condition-case err
(progn
(bookmark-jump bookmark)
(when-let ((local-variable-map
(bookmark-prop-get bookmark 'activities-buffer-local-variables)))
(cl-loop for (variable . value) in local-variable-map
do (setf (buffer-local-value variable (current-buffer)) value))))
(error (setf error (format "Error while opening bookmark: ERROR:%S RECORD:%S" err struct))))
(current-buffer))))
(if (not (eq temp-buffer jumped-to-buffer))
;; Bookmark appears to have been jumped to: return that buffer.
jumped-to-buffer
;; Bookmark appears to have not changed the buffer: return a new one showing an error.
(activities--error-buffer
(format "%s:%s" (car bookmark) (bookmark-prop-get bookmark 'filename))
(list "Activities was unable to get a buffer for bookmark:\n\n"
(prin1-to-string bookmark) "\n\n"
"Error: " (prin1-to-string error) "\n\n"
"It's likely that the bookmark's file no longer exists, in which case you may need to relocate it and redefine this activity.\n\n"
"If this is not the case, please report this error to the `activities' maintainer.\n\n"
"In the meantime, you may ignore this error and use the other buffers in the activity.\n\n"))))))
(defun activities--error-buffer (name strings)
"Return a new error buffer having NAME and content STRINGS."
;; TODO: Use this elsewhere too.
(with-current-buffer (get-buffer-create (format "*Activities (error): %s*" name))
(visual-line-mode)
(goto-char (point-max))
(apply #'insert strings)
(current-buffer)))
(defun activities--filename-buffer (activities-buffer)
"Return buffer for ACTIVITIES-BUFFER having `filename' set."
(pcase-let (((cl-struct activities-buffer filename) activities-buffer))
(find-file-noselect filename)))
(defun activities--name-buffer (activities-buffer)
"Return buffer for ACTIVITIES-BUFFER having `name' set."
(pcase-let (((cl-struct activities-buffer name) activities-buffer))
(or (get-buffer name)
(with-current-buffer (get-buffer-create (concat "*Activities (error): " name "*"))
(insert "Activities was unable to get a buffer named: " name "\n\n"
"It is likely that this buffer's major mode does not support the `bookmark' system, so it can't be restored properly. Please ask the major mode's maintainer to add bookmark support.\n\n"
"If this is not the case, please report this error to the `activities' maintainer.\n\n"
"In the meantime, it's recommended to not use buffers of this major mode in an activity's layout; or you may simply ignore this error and use the other buffers in the activity.")
(current-buffer)))))
(cl-defun activities-completing-read
(&key (activities activities-activities)
(default (when (activities-current)
(activities-activity-name (activities-current))))
(prompt "Activity"))
"Return an activity read with completion from ACTIVITIES.
PROMPT is passed to `completing-read' by way of `format-prompt',
which see, with DEFAULT."
(let* ((prompt (format-prompt prompt default))
(names (activities-names activities))
(name (completing-read prompt names nil t nil 'activities-completing-read-history default)))
(or (map-elt activities-activities name)
(make-activities-activity :name name))))
(cl-defun activities-names (&optional (activities activities-activities))
"Return list of names of ACTIVITIES."
(map-keys activities))
(defun activities-name-for (activity)
"Return frame/tab name for ACTIVITY.
Adds `activities-name-prefix'."
(concat activities-name-prefix (activities-activity-name activity)))
(defun activities--backtrace-visible-p ()
"Return non-nil if a visible window is in `backtrace-mode'."
(catch :found
(walk-windows (lambda (window)
(with-selected-window window
(when (derived-mode-p 'backtrace-mode)
(throw :found t)))))))
(defun activities--kill-buffers ()
;; TODO: Frame parameter name should be prefixed with `activities'.
"Kill buffers that are only in the current frame's/tab's buffer list.
Only does so when `activities-kill-buffers' is non-nil."
(when activities-kill-buffers
(let* ((frame-buffers (cl-reduce (lambda (acc frame)
(seq-difference acc (frame-parameter frame 'buffer-list)))
(remove (selected-frame) (frame-list))
:initial-value (frame-parameter nil 'buffer-list)))
(target-buffers (cl-remove-if (lambda (buffer)
(run-hook-with-args-until-success
'activities-anti-kill-predicates buffer))
frame-buffers)))
(mapc #'kill-buffer target-buffers))))
(defun activities-buffer-special-p (buffer)
"Return non-nil if BUFFER is special.
That is, if its name starts with an asterisk."
(string-prefix-p "*" (buffer-name buffer)))
(defun activities-buffer-hidden-p (buffer)
"Return non-nil if BUFFER is hidden.
That is, if its name starts with a space."
(string-prefix-p " " (buffer-name buffer)))
(defun activities-switch-buffer (_activity)
"Switch to a buffer associated with ACTIVITY.
Interactively, select from buffers associated with ACTIVITY; or,
with prefix argument, choose another activity."
(interactive
(list (if current-prefix-arg
(activities-completing-read)
(or (activities-current) (activities-completing-read)))))
(unless (defvar activities-tabs-mode)
(error "`activities-switch-buffer' currently requires `activities-tabs-mode'")))
;;;; Project support
(declare-function project-name "project")
(defun activities--project-name ()
"Return the name of the current project, if any."
(require 'project)
(when-let ((project (project-current)))
(project-name project)))
;;;; Bookmark support
(defun activities-bookmark-store (activity)
"Store a `bookmark' record for ACTIVITY."
(bookmark-maybe-load-default-file)
(let* ((activities-name (activities-activity-name activity))
(bookmark-name (concat activities-bookmark-name-prefix activities-name))
(props `((activities-name . ,activities-name)
(handler . activities-bookmark-handler))))
(bookmark-store bookmark-name props nil)))
;;;###autoload
(defun activities-bookmark-handler (bookmark)
"Switch to BOOKMARK's activity."
(activities-resume (map-elt activities-activities (bookmark-prop-get bookmark 'activities-name))))
(defun activities--buffer-local-variables (variables)
"Return alist of buffer-local VARIABLES for current buffer.
Variables without buffer-local bindings in the current buffer are
ignored."
(cl-loop for variable in variables
when (buffer-local-boundp variable (current-buffer))
collect (cons variable (buffer-local-value variable (current-buffer)))))
;;;; Footer
(provide 'activities)
;;; activities.el ends here
activities.el-0.7.2/makem.sh 0000775 0000000 0000000 00000117110 14730150706 0015720 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
# * makem.sh --- Script to aid building and testing Emacs Lisp packages
# URL: https://github.com/alphapapa/makem.sh
# Version: 0.7.1
# * Commentary:
# makem.sh is a script that helps to build, lint, and test Emacs Lisp
# packages. It aims to make linting and testing as simple as possible
# without requiring per-package configuration.
# It works similarly to a Makefile in that "rules" are called to
# perform actions such as byte-compiling, linting, testing, etc.
# Source and test files are discovered automatically from the
# project's Git repo, and package dependencies within them are parsed
# automatically.
# Output is simple: by default, there is no output unless errors
# occur. With increasing verbosity levels, more detail gives positive
# feedback. Output is colored by default to make reading easy.
# The script can run Emacs with the developer's local Emacs
# configuration, or with a clean, "sandbox" configuration that can be
# optionally removed afterward. This is especially helpful when
# upstream dependencies may have released new versions that differ
# from those installed in the developer's personal configuration.
# * License:
# 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 .
# * Functions
function usage {
cat <$file <$file <$file <"$file" <$file <"$file" <$file <&1)
# Set output file.
output_file=$(mktemp) || die "Unable to make output file."
paths_temp+=("$output_file")
# Run Emacs.
debug "run_emacs: ${emacs_command[@]} $@ &>\"$output_file\""
"${emacs_command[@]}" "$@" &>"$output_file"
# Check exit code and output.
exit=$?
[[ $exit != 0 ]] \
&& debug "Emacs exited non-zero: $exit"
[[ $verbose -gt 1 || $exit != 0 ]] \
&& cat $output_file
return $exit
}
# ** Compilation
function batch-byte-compile {
debug "batch-byte-compile: ERROR-ON-WARN:$compile_error_on_warn"
[[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq byte-compile-error-on-warn t)")
run_emacs \
--load "$(elisp-byte-compile-file)" \
"${error_on_warn[@]}" \
--eval "(unless (makem-batch-byte-compile) (kill-emacs 1))" \
"$@"
}
function byte-compile-file {
debug "byte-compile: ERROR-ON-WARN:$compile_error_on_warn"
local file="$1"
[[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq byte-compile-error-on-warn t)")
# FIXME: Why is the line starting with "&& verbose 3" not indented properly? Emacs insists on indenting it back a level.
run_emacs \
--load "$(elisp-byte-compile-file)" \
"${error_on_warn[@]}" \
--eval "(pcase-let ((\`(,num-errors ,num-warnings) (makem-byte-compile-file \"$file\"))) (when (or (and byte-compile-error-on-warn (not (zerop num-warnings))) (not (zerop num-errors))) (kill-emacs 1)))" \
&& verbose 3 "Compiling $file finished without errors." \
|| { verbose 3 "Compiling file failed: $file"; return 1; }
}
# ** Files
function submodules {
# Echo a list of submodules's paths relative to the repo root.
# TODO: Parse with bash regexp instead of cut.
git submodule status | awk '{print $2}'
}
function project-root {
# Echo the root of the project (or superproject, if running from
# within a submodule).
root_dir=$(git rev-parse --show-superproject-working-tree)
[[ $root_dir ]] || root_dir=$(git rev-parse --show-toplevel)
[[ $root_dir ]] || error "Can't find repo root."
echo "$root_dir"
}
function files-project {
# Echo a list of files in project; or with $1, files in it
# matching that pattern with "git ls-files". Excludes submodules.
[[ $1 ]] && pattern="/$1" || pattern="."
local excludes
for submodule in $(submodules)
do
excludes+=(":!:$submodule")
done
git ls-files -- "$pattern" "${excludes[@]}"
}
function dirs-project {
# Echo list of directories to be used in load path.
files-project-feature | dirnames
files-project-test | dirnames
}
function files-project-elisp {
# Echo list of Elisp files in project.
files-project 2>/dev/null \
| egrep "\.el$" \
| filter-files-exclude-default \
| filter-files-exclude-args
}
function files-project-feature {
# Echo list of Elisp files that are not tests and provide a feature.
files-project-elisp \
| grep -E -v "$test_files_regexp" \
| filter-files-feature
}
function files-project-test {
# Echo list of Elisp test files.
files-project-elisp | grep -E "$test_files_regexp"
}
function dirnames {
# Echo directory names for files on STDIN.
while read file
do
dirname "$file"
done
}
function filter-files-exclude-default {
# Filter out paths (STDIN) which should be excluded by default.
grep -E -v "(/\.cask/|-autoloads\.el|\.dir-locals)"
}
function filter-files-exclude-args {
# Filter out paths (STDIN) which are excluded with --exclude.
if [[ ${files_exclude[@]} ]]
then
(
# We use a subshell to set IFS temporarily so we can send
# the list of files to grep -F. This is ugly but more
# correct than replacing spaces with line breaks. Note
# that, for some reason, using IFS="\n" or IFS='\n' doesn't
# work, and a literal line break seems to be required.
IFS="
"
grep -Fv "${files_exclude[*]}"
)
else
cat
fi
}
function filter-files-feature {
# Read paths on STDIN and echo ones that (provide 'a-feature).
while read path
do
grep -E "^\\(provide '" "$path" &>/dev/null \
&& echo "$path"
done
}
function args-load-files {
# For file in $@, echo "--load $file".
for file in "$@"
do
sans_extension=${file%%.el}
printf -- '--load %q ' "$sans_extension"
done
}
function args-load-path {
# Echo load-path arguments.
for path in $(dirs-project | sort -u)
do
printf -- '-L %q ' "$path"
done
}
function test-files-p {
# Return 0 if $files_project_test is non-empty.
[[ "${files_project_test[@]}" ]]
}
function buttercup-tests-p {
# Return 0 if Buttercup tests are found.
test-files-p || die "No tests found."
debug "Checking for Buttercup tests..."
grep "(require 'buttercup)" "${files_project_test[@]}" &>/dev/null
}
function ert-tests-p {
# Return 0 if ERT tests are found.
test-files-p || die "No tests found."
debug "Checking for ERT tests..."
# We check for this rather than "(require 'ert)", because ERT may
# already be loaded in Emacs and might not be loaded with
# "require" in a test file.
grep "(ert-deftest" "${files_project_test[@]}" &>/dev/null
}
function package-main-file {
# Echo the package's main file.
file_pkg=$(files-project "*-pkg.el" 2>/dev/null)
if [[ $file_pkg ]]
then
# Use *-pkg.el file if it exists.
echo "$file_pkg"
else
# Use shortest filename (a sloppy heuristic that will do for now).
for file in "${files_project_feature[@]}"
do
echo ${#file} "$file"
done \
| sort -h \
| head -n1 \
| sed -r 's/^[[:digit:]]+ //'
fi
}
function dependencies {
# Echo list of package dependencies.
# Search package headers. Use -a so grep won't think that an Elisp file containing
# control characters (rare, but sometimes necessary) is binary and refuse to search it.
grep -E -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \
| grep -E -o '\([^([:space:]][^)]*\)' \
| grep -E -o '^[^[:space:])]+' \
| sed -r 's/\(//g' \
| grep -E -v '^emacs$' # Ignore Emacs version requirement.
# Search Cask file.
if [[ -r Cask ]]
then
grep -E '\(depends-on "[^"]+"' Cask \
| sed -r -e 's/\(depends-on "([^"]+)".*/\1/g'
fi
# Search -pkg.el file.
if [[ $(files-project "*-pkg.el" 2>/dev/null) ]]
then
sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(files-project- -- -pkg.el 2>/dev/null)
fi
}
# ** Sandbox
function sandbox {
verbose 2 "Initializing sandbox..."
# *** Sandbox arguments
# MAYBE: Optionally use branch-specific sandbox?
# Check or make user-emacs-directory.
if [[ $sandbox_dir ]]
then
# Directory given as argument: ensure it exists.
if ! [[ -d $sandbox_dir ]]
then
debug "Making sandbox directory: $sandbox_dir"
mkdir -p "$sandbox_dir" || die "Unable to make sandbox dir."
fi
# Add Emacs version-specific subdirectory, creating if necessary.
sandbox_dir="$sandbox_dir/$(emacs-version)"
if ! [[ -d $sandbox_dir ]]
then
mkdir "$sandbox_dir" || die "Unable to make sandbox subdir: $sandbox_dir"
fi
else
# Not given: make temp directory, and delete it on exit.
local sandbox_dir=$(mktemp -d) || die "Unable to make sandbox dir."
paths_temp+=("$sandbox_dir")
fi
# Make argument to load init file if it exists.
init_file="$sandbox_dir/init.el"
# Set sandbox args. This is a global variable used by the run_emacs function.
args_sandbox=(
--title "makem.sh: $(basename $(pwd)) (sandbox: $sandbox_dir)"
--eval "(setq user-emacs-directory (file-truename \"$sandbox_dir\"))"
--load package
--eval "(setq package-user-dir (expand-file-name \"elpa\" user-emacs-directory))"
--eval "(setq user-init-file (file-truename \"$init_file\"))"
)
# Add package-install arguments for dependencies.
if [[ $install_deps ]]
then
local deps=($(dependencies))
debug "Installing dependencies: ${deps[@]}"
# Ensure built-in packages get upgraded to newer versions from ELPA.
args_sandbox_package_install+=(--eval "(setq package-install-upgrade-built-in t)")
for package in "${deps[@]}"
do
args_sandbox_package_install+=(--eval "(package-install '$package)")
done
fi
# Add package-install arguments for linters.
if [[ $install_linters ]]
then
debug "Installing linters: package-lint relint"
args_sandbox_package_install+=(
--eval "(package-install 'elsa)"
--eval "(package-install 'package-lint)"
--eval "(package-install 'relint)")
fi
# *** Install packages into sandbox
if [[ ${args_sandbox_package_install[@]} ]]
then
# Initialize the sandbox (installs packages once rather than for every rule).
verbose 1 "Installing packages into sandbox..."
run_emacs \
--eval "(package-refresh-contents)" \
"${args_sandbox_package_install[@]}" \
&& success "Packages installed." \
|| die "Unable to initialize sandbox."
fi
verbose 2 "Sandbox initialized."
}
# ** Utility
function cleanup {
# Remove temporary paths (${paths_temp[@]}).
for path in "${paths_temp[@]}"
do
if [[ $debug ]]
then
debug "Debugging enabled: not deleting temporary path: $path"
elif [[ -r $path ]]
then
rm -rf "$path"
else
debug "Temporary path doesn't exist, not deleting: $path"
fi
done
}
function echo-unset-p {
# Echo 0 if $1 is set, otherwise 1. IOW, this returns the exit
# code of [[ $1 ]] as STDOUT.
[[ $1 ]]
echo $?
}
function ensure-package-available {
# If package $1 is available, return 0. Otherwise, return 1, and
# if $2 is set, give error otherwise verbose. Outputting messages
# here avoids repetition in callers.
local package=$1
local direct_p=$2
if ! run_emacs --load $package &>/dev/null
then
if [[ $direct_p ]]
then
error "$package not available."
else
verbose 2 "$package not available."
fi
return 1
fi
}
function ensure-tests-available {
# If tests of type $1 (like "ERT") are available, return 0. Otherwise, if
# $2 is set, give an error and return 1; otherwise give verbose message. $1
# should have a corresponding predicate command, like ert-tests-p for ERT.
local test_name=$1
local test_command="${test_name,,}-tests-p" # Converts name to lowercase.
local direct_p=$2
if ! $test_command
then
if [[ $direct_p ]]
then
error "$test_name tests not found."
else
verbose 2 "$test_name tests not found."
fi
return 1
fi
}
function echo_color {
# This allows bold, italic, etc. without needing a function for
# each variation.
local color_code="COLOR_$1"
shift
if [[ $color ]]
then
echo -e "${!color_code}${@}${COLOR_off}"
else
echo "$@"
fi
}
function debug {
if [[ $debug ]]
then
function debug {
echo_color yellow "DEBUG ($(ts)): $@" >&2
}
debug "$@"
else
function debug {
true
}
fi
}
function error {
echo_color red "ERROR ($(ts)): $@" >&2
((errors++))
return 1
}
function die {
[[ $@ ]] && error "$@"
exit $errors
}
function log {
echo "LOG ($(ts)): $@" >&2
}
function log_color {
local color_name=$1
shift
echo_color $color_name "LOG ($(ts)): $@" >&2
}
function success {
if [[ $verbose -ge 2 ]]
then
log_color green "$@" >&2
fi
}
function verbose {
# $1 is the verbosity level, rest are echoed when appropriate.
if [[ $verbose -ge $1 ]]
then
[[ $1 -eq 1 ]] && local color_name=blue
[[ $1 -eq 2 ]] && local color_name=cyan
[[ $1 -ge 3 ]] && local color_name=white
shift
log_color $color_name "$@" >&2
fi
}
function ts {
date "+%Y-%m-%d %H:%M:%S"
}
function emacs-version {
# Echo Emacs version number.
# Don't use run_emacs function, which does more than we need.
"${emacs_command[@]}" -Q --batch --eval "(princ emacs-version)" \
|| die "Unable to get Emacs version."
}
function rule-p {
# Return 0 if $1 is a rule.
[[ $1 =~ ^(lint-?|tests?)$ ]] \
|| [[ $1 =~ ^(batch|interactive)$ ]] \
|| [[ $(type -t "$2" 2>/dev/null) =~ function ]]
}
# * Rules
# These functions are intended to be called as rules, like a Makefile.
# Some rules test $1 to determine whether the rule is being called
# directly or from a meta-rule; if directly, an error is given if the
# rule can't be run, otherwise it's skipped.
function all {
verbose 1 "Running all rules..."
lint
tests
}
function compile-batch {
[[ $compile ]] || return 0
unset compile # Only compile once.
verbose 1 "Compiling..."
verbose 2 "Batch-compiling files..."
debug "Byte-compile files: ${files_project_byte_compile[@]}"
batch-byte-compile "${files_project_byte_compile[@]}"
}
function compile-each {
[[ $compile ]] || return 0
unset compile # Only compile once.
verbose 1 "Compiling..."
debug "Byte-compile files: ${files_project_byte_compile[@]}"
local compile_errors
for file in "${files_project_byte_compile[@]}"
do
verbose 2 "Compiling file: $file..."
byte-compile-file "$file" \
|| compile_errors=t
done
[[ ! $compile_errors ]]
}
function compile {
if [[ $compile = batch ]]
then
compile-batch "$@"
else
compile-each "$@"
fi
local status=$?
if [[ $compile_error_on_warn ]]
then
# Linting: just return status code, because lint rule will print messages.
[[ $status = 0 ]]
else
# Not linting: print messages here.
[[ $status = 0 ]] \
&& success "Compiling finished without errors." \
|| error "Compiling failed."
fi
}
function batch {
# Run Emacs in batch mode with ${args_batch_interactive[@]} and
# with project source and test files loaded.
verbose 1 "Executing Emacs with arguments: ${args_batch_interactive[@]}"
run_emacs \
$(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}") \
"${args_batch_interactive[@]}"
}
function interactive {
# Run Emacs interactively. Most useful with --sandbox and --install-deps.
local load_file_args=$(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}")
verbose 1 "Running Emacs interactively..."
verbose 2 "Loading files: ${load_file_args//--load /}"
[[ $compile ]] && compile
unset arg_batch
run_emacs \
$load_file_args \
--eval "(load user-init-file)" \
"${args_batch_interactive[@]}"
arg_batch="--batch"
}
function lint {
verbose 1 "Linting..."
lint-checkdoc
lint-compile
lint-declare
# NOTE: Elint doesn't seem very useful at the moment. See comment
# in lint-elint function.
# lint-elint
lint-indent
lint-package
lint-regexps
}
function lint-checkdoc {
verbose 1 "Linting checkdoc..."
local checkdoc_file="$(elisp-checkdoc-file)"
paths_temp+=("$checkdoc_file")
run_emacs \
--load="$checkdoc_file" \
"${files_project_feature[@]}" \
&& success "Linting checkdoc finished without errors." \
|| error "Linting checkdoc failed."
}
function lint-compile {
verbose 1 "Linting compilation..."
compile_error_on_warn=true
compile "${files_project_byte_compile[@]}" \
&& success "Linting compilation finished without errors." \
|| error "Linting compilation failed."
unset compile_error_on_warn
}
function lint-declare {
verbose 1 "Linting declarations..."
local check_declare_file="$(elisp-check-declare-file)"
paths_temp+=("$check_declare_file")
run_emacs \
--load "$check_declare_file" \
-f makem-check-declare-files-and-exit \
"${files_project_feature[@]}" \
&& success "Linting declarations finished without errors." \
|| error "Linting declarations failed."
}
function lint-elsa {
verbose 1 "Linting with Elsa..."
# MAYBE: Install Elsa here rather than in sandbox init, to avoid installing
# it when not needed. However, we should be careful to be clear about when
# packages are installed, because installing them does execute code.
run_emacs \
--load elsa \
-f elsa-run-files-and-exit \
"${files_project_feature[@]}" \
&& success "Linting with Elsa finished without errors." \
|| error "Linting with Elsa failed."
}
function lint-elint {
# NOTE: Elint gives a lot of spurious warnings, apparently because it doesn't load files
# that are `require'd, so its output isn't very useful. But in case it's improved in
# the future, and since this wrapper code already works, we might as well leave it in.
verbose 1 "Linting with Elint..."
local errors=0
for file in "${files_project_feature[@]}"
do
verbose 2 "Linting with Elint: $file..."
run_emacs \
--load "$(elisp-elint-file)" \
--eval "(makem-elint-file \"$file\")" \
&& verbose 3 "Linting with Elint found no errors." \
|| { error "Linting with Elint failed: $file"; ((errors++)) ; }
done
[[ $errors = 0 ]] \
&& success "Linting with Elint finished without errors." \
|| error "Linting with Elint failed."
}
function lint-indent {
verbose 1 "Linting indentation..."
# We load project source files as well, because they may contain
# macros with (declare (indent)) rules which must be loaded to set
# indentation.
run_emacs \
--load "$(elisp-lint-indent-file)" \
$(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}") \
--funcall makem-lint-indent-batch-and-exit \
"${files_project_feature[@]}" "${files_project_test[@]}" \
&& success "Linting indentation finished without errors." \
|| error "Linting indentation failed."
}
function lint-package {
ensure-package-available package-lint $1 || return $(echo-unset-p $1)
verbose 1 "Linting package..."
run_emacs \
--load package-lint \
--eval "(setq package-lint-main-file \"$(package-main-file)\")" \
--funcall package-lint-batch-and-exit \
"${files_project_feature[@]}" \
&& success "Linting package finished without errors." \
|| error "Linting package failed."
}
function lint-regexps {
ensure-package-available relint $1 || return $(echo-unset-p $1)
verbose 1 "Linting regexps..."
run_emacs \
--load relint \
--funcall relint-batch \
"${files_project_source[@]}" \
&& success "Linting regexps finished without errors." \
|| error "Linting regexps failed."
}
function tests {
verbose 1 "Running all tests..."
test-ert
test-buttercup
}
function test-ert-interactive {
verbose 1 "Running ERT tests interactively..."
unset arg_batch
run_emacs \
$(args-load-files "${files_project_test[@]}") \
--eval "(ert-run-tests-interactively t)"
arg_batch="--batch"
}
function test-buttercup {
ensure-tests-available Buttercup $1 || return $(echo-unset-p $1)
compile || die
verbose 1 "Running Buttercup tests..."
local buttercup_file="$(elisp-buttercup-file)"
paths_temp+=("$buttercup_file")
run_emacs \
$(args-load-files "${files_project_test[@]}") \
--load "$buttercup_file" \
--eval "(progn (setq backtrace-on-error-noninteractive nil) (buttercup-run))" \
&& success "Buttercup tests finished without errors." \
|| error "Buttercup tests failed."
}
function test-ert {
ensure-tests-available ERT $1 || return $(echo-unset-p $1)
compile || die
verbose 1 "Running ERT tests..."
debug "Test files: ${files_project_test[@]}"
run_emacs \
$(args-load-files "${files_project_test[@]}") \
-f ert-run-tests-batch-and-exit \
&& success "ERT tests finished without errors." \
|| error "ERT tests failed."
}
# * Defaults
test_files_regexp='^((tests?|t)/)|-tests?.el$|^test-'
emacs_command=("emacs")
errors=0
verbose=0
compile=true
arg_batch="--batch"
compile=each
# MAYBE: Disable color if not outputting to a terminal. (OTOH, the
# colorized output is helpful in CI logs, and I don't know if,
# e.g. GitHub Actions logging pretends to be a terminal.)
color=true
# TODO: Using the current directory (i.e. a package's repo root directory) in
# load-path can cause weird errors in case of--you guessed it--stale .ELC files,
# the zombie problem that just won't die. It's incredible how many different ways
# this problem presents itself. In this latest example, an old .ELC file, for a
# .EL file that had since been renamed, was present on my local system, which meant
# that an example .EL file that hadn't been updated was able to "require" that .ELC
# file's feature without error. But on another system (in this case, trying to
# setup CI using GitHub Actions), the old .ELC was not present, so the example .EL
# file was not able to load the feature, which caused a byte-compilation error.
# In this case, I will prevent such example files from being compiled. But in
# general, this can cause weird problems that are tedious to debug. I guess
# the best way to fix it would be to actually install the repo's code as a
# package into the sandbox, but doing that would require additional tooling,
# pulling in something like Quelpa or package-build--and if the default recipe
# weren't being used, the actual recipe would have to be fetched off MELPA or
# something, which seems like getting too smart for our own good.
# TODO: Emit a warning if .ELC files that don't match any .EL files are detected.
# ** Colors
COLOR_off='\e[0m'
COLOR_black='\e[0;30m'
COLOR_red='\e[0;31m'
COLOR_green='\e[0;32m'
COLOR_yellow='\e[0;33m'
COLOR_blue='\e[0;34m'
COLOR_purple='\e[0;35m'
COLOR_cyan='\e[0;36m'
COLOR_white='\e[0;37m'
# ** Package system args
args_package_archives=(
--eval "(add-to-list 'package-archives '(\"gnu\" . \"https://elpa.gnu.org/packages/\") t)"
--eval "(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)"
)
args_package_init=(
--eval "(package-initialize)"
)
# * Args
args=$(getopt -n "$0" \
-o dhce:E:i:s::vf:C \
-l compile-batch,exclude:,emacs:,install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,sandbox:: \
-- "$@") \
|| { usage; exit 1; }
eval set -- "$args"
while true
do
case "$1" in
--install-deps)
install_deps=true
;;
--install-linters)
install_linters=true
;;
-d|--debug)
debug=true
verbose=2
args_debug=(--eval "(setq init-file-debug t)"
--eval "(setq debug-on-error t)")
;;
--debug-load-path)
debug_load_path=true
;;
-h|--help)
usage
exit
;;
-c|--compile-batch)
debug "Compiling files in batch mode"
compile=batch
;;
-E|--emacs)
shift
emacs_command=($1)
;;
-i|--install)
shift
args_sandbox_package_install+=(--eval "(package-install '$1)")
;;
-s|--sandbox)
sandbox=true
shift
sandbox_dir="$1"
if ! [[ $sandbox_dir ]]
then
debug "No sandbox dir: installing dependencies."
install_deps=true
else
debug "Sandbox dir: $1"
fi
;;
-v|--verbose)
((verbose++))
;;
-e|--exclude)
shift
debug "Excluding file: $1"
files_exclude+=("$1")
;;
-f|--file)
shift
args_files+=("$1")
;;
--no-color)
unset color
;;
-C|--no-compile)
unset compile
;;
--)
# Remaining args (required; do not remove)
shift
rest=("$@")
break
;;
esac
shift
done
debug "ARGS: $args"
debug "Remaining args: ${rest[@]}"
# Set package elisp (which depends on --no-org-repo arg).
package_initialize_file="$(elisp-package-initialize-file)"
paths_temp+=("$package_initialize_file")
# * Main
trap cleanup EXIT INT TERM
# Change to project root directory first.
cd "$(project-root)"
# Discover project files.
files_project_feature=($(files-project-feature))
files_project_test=($(files-project-test))
files_project_byte_compile=("${files_project_feature[@]}" "${files_project_test[@]}")
if [[ ${args_files[@]} ]]
then
# Add specified files.
files_project_feature+=("${args_files[@]}")
files_project_byte_compile+=("${args_files[@]}")
fi
debug "EXCLUDING FILES: ${files_exclude[@]}"
debug "FEATURE FILES: ${files_project_feature[@]}"
debug "TEST FILES: ${files_project_test[@]}"
debug "BYTE-COMPILE FILES: ${files_project_byte_compile[@]}"
debug "PACKAGE-MAIN-FILE: $(package-main-file)"
if ! [[ ${files_project_feature[@]} ]]
then
error "No files specified and not in a git repo."
exit 1
fi
# Set load path.
args_load_paths=($(args-load-path))
debug "LOAD PATH ARGS: ${args_load_paths[@]}"
# If rules include linters and sandbox-dir is unspecified, install
# linters automatically.
if [[ $sandbox && ! $sandbox_dir ]] && [[ "${rest[@]}" =~ lint ]]
then
debug "Installing linters automatically."
install_linters=true
fi
# Initialize sandbox.
[[ $sandbox ]] && sandbox
# Run rules.
for rule in "${rest[@]}"
do
if [[ $batch || $interactive ]]
then
debug "Adding batch/interactive argument: $rule"
args_batch_interactive+=("$rule")
elif [[ $rule = batch ]]
then
# Remaining arguments are passed to Emacs.
batch=true
elif [[ $rule = interactive ]]
then
# Remaining arguments are passed to Emacs.
interactive=true
elif type -t "$rule" 2>/dev/null | grep function &>/dev/null
then
# Pass called-directly as $1 to indicate that the rule is
# being called directly rather than from a meta-rule.
$rule called-directly
elif [[ $rule = test ]]
then
# Allow the "tests" rule to be called as "test". Since "test"
# is a shell builtin, this workaround is required.
tests
else
error "Invalid rule: $rule"
fi
done
# Batch/interactive rules.
[[ $batch ]] && batch
[[ $interactive ]] && interactive
if [[ $errors -gt 0 ]]
then
log_color red "Finished with $errors errors."
else
success "Finished without errors."
fi
exit $errors