Repository: rougier/agenda Branch: master Commit: 15247448d20b Files: 15 Total size: 182.1 KB Directory structure: gitextract_6z73czd1/ ├── LICENSE.txt ├── README.md ├── agenda-capture.el ├── agenda-edit.el ├── agenda-export.el ├── agenda-faces.el ├── agenda-parse.el ├── agenda-utils.el ├── agenda-view-day.el ├── agenda-view-month.el ├── agenda-view-week.el ├── agenda-view-year.el ├── agenda-view.el ├── agenda.el └── agenda.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: LICENSE.txt ================================================ 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 . ================================================ FILE: README.md ================================================ # Plain Text Agenda The plain text agenda format is very strongly inspired by the calendar.txt idea by [Tero Karvinen](https://terokarvinen.com/2021/calendar-txt/). The major difference is that there is a single event per line and a formal syntax: ``` # Header (not parsed) # Header YYYY-MM-DD wNN Day HH:MM-HH:MM Summary @ACTIONS... +TAGS... [REFERENCE] # Entry [REFERENCE:KEY]: Content # Metadata ``` Only the ISO date `YYYY-MM-DD` is mandatory. All other fields are optional (but order is strict). ## Examples ```markdown # Meetings 2026-01-27 w05 Tue 11:00-12:00 Team meeting @MEET +WORK 2026-01-27 w05 Tue 12:00-13:00 Lunch break @LUNCH +HOME 2026-01-27 w05 Tue 15:00-16:00 Project @MEET +WORK [20260127T1500] 2026-01-28 This is a valid entry # Medatata [20260127T1500:URL]: Some URL [20260127T1500:NOTE]: Some Notes ``` This is both human-readable and easy to parse by any program, including Emacs and standard CLI tools. Here are some examples in Bash: - **Today agenda:** ``` grep `date +"%Y-%m-%d"` agenda.txt ``` - **Week agenda:** ``` grep `date +"^%Y"` agenda.txt \| grep `date +"w%V"` ``` There is also a more elaborate example [agenda.sh](./agenda.sh) that display formatted agenda for the current week.
Show weekly agenda output ```markdown # Monday 02 February 2026 11:00-12:00 🎓 Yousra @MEET +PHD 12:00-13:00 Neurosync @MEET +NEUROSYNC +EUROPE +INRIA 14:00-15:00 🎓 Maeva @MEET +PHD +CANCEL 15:00-16:00 Roshni @MEET # Tuesday 03 February 2026 (today) 10:00-11:00 Team (adm) @MEET +INRIA 11:00-12:00 Team (sci) @MEET +INRIA 15:00-16:00 🎓 Maeva @MEET +PHD 15:30-17:30 OSD (dictionary) @MEET +OSD # Wednesday 04 February 2026 10:00-11:00 C.Dupaix @MEET +INRIA +COSO 14:00-15:00 Vispy @MEET +VISPY # Thursday 05 February 2026 18:30-21:00 OSD Party @MEET +OSD # Friday 06 February 2026 13:30-14:30 Srini Chakravarthy @MEET +INDIA +ANR +UB 18:00-22:00 🎤 IA/Droit pénal @TALK +OSD ```
It is probably possible to have even fancier renderings using bash but I concentrated my efforts on Emacs. ## Roadmap The agenda is pretty usable but it is still **work in progress**. Syntax should not changed much but may be nonetheless modified if bugs or incompatibilities are found. There a few missing things that are planned: - [x] Documentation - [x] Export (ical format) - [ ] Reorganize faces - [ ] Handle multiple agenda files - [ ] Automated git support - [ ] Better handling of TODO/DONE - [ ] A set of bash view commands ## Limitations The agenda is not meant to replace Emacs [org-agenda](https://orgmode.org/manual/Agenda-Views.html) which is much more powerful (by far). The proposed format probably offers less than 1% of org-agenda features: choice is yours. Among the known limitations: - No specific syntax for repeated entries (they have to be created explicitly). - Limited metadata using the reference mechanisms - No record of creation date (but you can use git for that) - No active/inactive status (only the +CANCEL keyword is considered) - No integration with org (but also no org dependencies) And probably many others that I forgot to mention. # Installation # Usage The package provides two modes: - A minor [edit mode](#edit-mode) to edit the source file - A major [view mode](#view-mode) to display the agenda. ## Edit mode | Command | Key Binding | Description | | :--- | :--- | :--- | | **Adjust Date/Time (Forward)** | `S-up` | Increment the value under point
(year, month, day, hour or minute). | | **Adjust Date/Time (Backward)** | `S-down` | Decrement the value under point
(year, month, week, day, hour or minute). | | **Adjust Date/Time (Forward)** | `S-right` | Increment date under point by one day
or time under point by one hour. | | **Adjust Date/Time (Backward)** | `S-left` | Decrement date under point by one day
or time under point by one hour. | | **Go to Date** | `C-c g` | Jumps to a specific date prompted via calendar. | | **Insert Entry** | `C-c i` | Prompt for a date and insert a new entry at relevant place.
When prefixed with `C-u`, insert entry at point. | | **Set Entry Data** | `C-c d` | Opens a prompt to set/modify metadata.
When prefixed with `C-u` prompt for UID. | | **Repeat Entry** | `C-c r` | Prompt for a frequency and count to repeat entry at point. | | **Filter Agenda** | `C-c f` | Prompt for a filter to restrict view (`C-l` to clear). | | **Cleanup** | `C-l` | Clear caches and reparse buffer. | | **Cycle Outline** | `TAB` | Toggles folding of current header. | | **Cycle All** | `S-TAB` | Global floding cycle. | | **Agenda View** | `C-c a` | Switches to agenda view . | Here is a view of my current agenda: ![Edit mode](./screenshots/agenda-edit.png) ## View mode The view mode allows to display the agenda organized by day, week, month, 3 months (trimester) or year. Each view has a dedicated display that is supposed to ease reading (see screenshots below). All views share the same key bindings but action may depends on the view. When an entry is displayed and there is URL metadata attachd, entry can be clicked. | Command | Key Binding | Description | | :--- | :--- | :--- | | **Unit Forward** | `f` or `n` | Forward current date by one unit (d,w,m,3m or y). | | **Unit Backward** | `b` or `p` | Backward current date by one unit (d,w,m,3m or y). | | **Month Forward** | `S-right` | Forward current date by one month. | | **Month Backward** | `S-left` | Backward current date by one month. | | **3 Months Forward** | `S-down` | Forward current date by 3 months (year view). | | **3 Months Backward** | `S-up` | Backward current date by 3 months (year view). | | **Goto entry** | `TAB` or `RET` | Go to entry at point. | | **Capture** | `c` | Capture a new entry using date at point (if any). | | **Refresh** | `r` | Refresh view (reparse). | | **Day mode** | `d` | Switch to day mode. | | **Week mode** | `w` | Switch to week mode. | | **Month mode** | `m` | Switch to month mode. | | **3 Months mode** | `t` | Switch to 3 months (trimester) mode. | | **Year mode** | `y` | Switch to year mode. | | **Goto date** | `g` | Prompt for date and goto to selected date. | | **Goto today** | `.` | Go to today. | ### Day mode A summary message of the day is displayed at the bottom when moving to a new date. ![View mode (day)](./screenshots/agenda-day-view.png) ### Week mode ![View mode (day)](./screenshots/agenda-week-view.png) ### Month mode In month mode, the current week is displayed using default faces, other weeks are displayed using shadow face. ![View mode (day)](./screenshots/agenda-month-1-view.png) ### 3 months mode In month mode, the current week is displayed using default faces, other weeks are displayed using shadow face. ![View mode (day)](./screenshots/agenda-month-3-view.png) ### Year mode In month mode, the selected month is displayed using default faces, other months are displayed using shadow face. A summary message of the day is displayed at the bottom when moving to a new date. ![View mode (day)](./screenshots/agenda-year-view.png) ## Export It is possible to export the whole agenda to ical format in two files: a private file where entries have all the details and a public file where title / tags / actions are simply replaced by "(busy)" or "(away)" when there is "MAP" data attached. The public file can be used to indicate people when you're available without giving details. Synchronization is made using [vdirsyncer](https://github.com/pimutils/vdirsyncer) that you need to have configured. ## Capture Capture is very simple since an entry is exactly one line and can be directly prompted in the minibuffer. Date and time can be prefilled using a provided date or prompted using calendar. When prefixed with `C-u`, data can be set for the new entry. The new entry is inserted at the nearest date inside the agenda file (starting from end). ================================================ FILE: agenda-capture.el ================================================ ;;; agenda-capture.el --- Capture framework -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (defvar agenda-quick-capture-map (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map (kbd "S-") #'agenda-shift-up) (define-key map (kbd "S-") #'agenda-shift-down) (define-key map (kbd "S-") #'agenda-shift-left) (define-key map (kbd "S-") #'agenda-shift-right) map) "Keymap for capture in minibuffer.") ;;;###autoload (defun agenda-capture-with-calendar (&optional with-data) "Open a calendar to choose a date then pre-fill an entry with selected date. If WITH-DATA is non-nil (C-u), also prompt for additional data. Use arrow keys to shift year/month/day/hour/minute based on cursor position in the minibuffer." (interactive "P") (agenda-with-calendar-select date (agenda-capture date with-data))) ;;;###autoload (defun agenda-capture (&optional date with-data) "Prompt for an entry pre-filled with DATE (month day year) or current date and current time. If WITH-DATA is non-nil (C-u), also prompt for additional data. Use arrow keys to shift year/month/day/hour/minute based on cursor position in the minibuffer." (interactive "P") (let* ((timestamp (if date (encode-time (list 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))) (current-time))) (hour (string-to-number (format-time-string "%H"))) (initial (concat (format-time-string "%Y-%m-%d w%V %a" timestamp) " " (format "%02d:00" hour) "-" (format "%02d:00 " (min (1+ hour) 24)))) (minibuffer-prompt-properties '(cursor-intangible t read-only t)) (prompt (concat (propertize "Agenda capture" 'face '(:inherit (link bold))) (propertize "\n" 'face 'default 'display (format "\n%s " (agenda-mark 'capture))))) (entry (read-from-minibuffer prompt initial agenda-quick-capture-map))) (unless (and agenda-file (file-exists-p agenda-file)) (error "Agenda file not found: %s. " agenda-file)) (if (string-match agenda-entry-re entry) (let* ((year (string-to-number (car (agenda-match 'date-y entry)))) (month (string-to-number (car (agenda-match 'date-m entry)))) (day (string-to-number (car (agenda-match 'date-d entry)))) (source-buffer (find-file-noselect agenda-file))) (with-current-buffer source-buffer (agenda--goto-date (list month day year)) (end-of-line) (unless (= (line-beginning-position) (line-end-position)) (insert "\n")) (insert entry) (when with-data (let ((current-prefix-arg nil)) (call-interactively #'agenda-entry-set-data))) (message (concat (propertize "Entry captured " 'face 'bold) (format "(%s)" entry))) (agenda-highlight (line-beginning-position) (line-end-position)))) (message "Entry format not recognized!")))) (provide 'agenda-capture) ;;; agenda-capture.el ends here ================================================ FILE: agenda-edit.el ================================================ ;;; agenda-edit.el --- Agenda edit mode -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'agenda-parse) (require 'agenda-faces) (defun agenda-highlight (beg end) "Move the highlight overlay to cover BEG to END." (unless agenda--highlight-overlay (setq agenda--highlight-overlay (make-overlay (point) (point))) (overlay-put agenda--highlight-overlay 'face 'agenda-edit-highlight)) (move-overlay agenda--highlight-overlay beg end) (add-hook 'pre-command-hook #'agenda-highlight-clear nil t)) (defun agenda-highlight-clear () "Clear highlight only if the last event was a keyboard event." (let ((event last-command-event)) (unless (or (listp event) (memq event '(wheel-up wheel-down mouse-wheel-up-event mouse-wheel-down-event))) (when agenda--highlight-overlay (move-overlay agenda--highlight-overlay (point) (point))) (remove-hook 'pre-command-hook #'agenda-highlight-clear t)))) (defun agenda-mark (what) "Return mark associated with WHAT" (cdr (assoc what agenda-marks))) (defun agenda--set-mark (char &optional face) "Add CHAR in the left margin using FACE." (remove-overlays (line-beginning-position) (line-end-position)) (let* ((start (line-beginning-position)) (overlay (make-overlay start start nil nil t))) (overlay-put overlay 'agenda-mark t) (overlay-put overlay 'before-string (propertize " " 'display `((margin left-margin) ,(propertize (concat " " char) 'face (or face 'default))))))) (defun agenda-mark-entry-at-point () "Set margin mark for entry at point." (save-excursion (save-match-data (beginning-of-line) (when-let ((entry (agenda-entry-at-point))) (cond ((agenda-entry-cancel-p entry) (agenda--set-mark (agenda-mark 'cancel) 'agenda-edit-cancel)) ((agenda-entry-birthday-p entry) (agenda--set-mark (agenda-mark 'birthday))) ((agenda-entry-today-p entry) (agenda--set-mark (agenda-mark 'today))) ((agenda-entry-active-deadline-p entry) (agenda--set-mark (agenda-mark 'deadline) 'agenda-edit-deadline)) ((agenda-entry-inweek-p entry) (agenda--set-mark (agenda-mark 'inweek))) (t (remove-overlays (line-beginning-position) (line-end-position) 'agenda-mark t))))))) (defun agenda--set-link (beg end marker &optional face) "Mark BEG to END with a clickable button that moves point to MARKER. Button face can be specified with FACE." (let ((map (make-sparse-keymap)) (callback (lambda (&rest _) (interactive) (push-mark) (goto-char (marker-position marker)) (recenter)))) (define-key map [mouse-1] callback) (define-key map [mouse-2] callback) (define-key map (kbd "RET") callback) (with-silent-modifications (add-text-properties beg end `(mouse-face highlight face link font-lock-face link follow-link t keymap ,map))))) (defun agenda-link-data-at-point () "Add link to date ref for entry at point." (save-excursion (save-match-data (when-let* ((ref (agenda-match 'ref)) (ref-beg (1+ (cadr ref))) (ref-end (1- (cddr ref))) (ref (substring (car ref) +1 -1)) (ref-marker (save-excursion (goto-char ref-beg) (point-marker)))) (goto-char (point-min)) (when (search-forward-regexp (format "^\\[\\(%s\\):.*\\]:.*$" ref)) (let* ((data-beg (match-beginning 1)) (data-end (match-end 1)) (data-marker (save-excursion (goto-char data-beg) (point-marker)))) (agenda--set-link ref-beg ref-end data-marker) (agenda--set-link data-beg data-end ref-marker))))))) (defun agenda-parse-buffer () "Parse buffer." (interactive) (save-excursion (remove-overlays (point-min) (point-max)) (font-lock-flush) (font-lock-ensure) ;; Process entries (goto-char (point-min)) (while (re-search-forward agenda-entry-re nil t) (let ((entry (agenda-entry-at-point))) ;; Mark entry (save-excursion (goto-char (cadr (agenda-match 'date))) (agenda-mark-entry-at-point)) ;; Create button on data (save-excursion (goto-char (cadr (agenda-match 'date))) (agenda-link-data-at-point)))) ;; Process headers (with-silent-modifications (goto-char (point-min)) (while (re-search-forward agenda-header-re nil t) (let* ((start (match-beginning 0)) (full-prefix (match-string 1)) (prefix (format "%2s" (string-trim full-prefix)))) (put-text-property start (+ start (length full-prefix)) 'display `((margin left-margin) ,(propertize prefix 'face 'agenda-edit-header-prefix)))))))) (defun agenda-date-change-at-point (delta) "Change date at point by DELTA '(year month day). This methods highlights the modified date and update the margin marker." (save-excursion (when-let* ((entry (agenda-entry-at-point)) (date-group (agenda-match 'date)) (date-value (cdr (assoc 'date entry))) (date-beg (cadr date-group)) (date-end (cddr date-group)) (timestamp (encode-time 0 0 0 (+ (nth 2 date-value) (nth 2 delta)) (+ (nth 1 date-value) (nth 1 delta)) (+ (nth 0 date-value) (nth 0 delta)))) (date (format-time-string "%Y-%m-%d w%V %a" timestamp))) (goto-char (cadr date-group)) (delete-region date-beg date-end) (insert date) (agenda-mark-entry-at-point) (agenda-highlight date-beg date-end)))) (defun agenda-time-change-at-point (delta) "Change time or time-range at point by DELTA '(hour minute). This methods highlights the modified date and update the margin marker." (save-excursion (when-let* ((point (point)) (entry (agenda-entry-at-point)) (time-group (agenda-match 'time)) (time-start (cdr (assoc 'time-start entry))) (time-start-group (agenda-match 'time-start))) (let* ((time-end (cdr (assoc 'time-end entry))) (time-end-group (agenda-match 'time-end)) (point-on-time-start (and time-start-group (>= point (cadr time-start-group)) (< point (cddr time-start-group)))) (point-on-time-end (and time-end-group (>= point (cadr time-end-group)) (< point (cddr time-end-group)))) (time-start-ts (encode-time 0 (+ (nth 1 time-start) (if point-on-time-start (nth 1 delta) 0)) (+ (nth 0 time-start) (if point-on-time-start (nth 0 delta) 0)) 1 1 1970)) (time-end-ts (encode-time 0 (+ (nth 1 (or time-end time-start)) (if (or point-on-time-start point-on-time-end) (nth 1 delta) 0)) (+ (nth 0 (or time-end time-start)) (if (or point-on-time-start point-on-time-end) (nth 0 delta) 0)) 1 1 1970)) (time-str (cond (point-on-time-end (format-time-string "%H:%M" time-end-ts)) ((and point-on-time-start time-end) (format "%s-%s" (format-time-string "%H:%M" time-start-ts) (format-time-string "%H:%M" time-end-ts))) (point-on-time-start (format-time-string "%H:%M" time-start-ts)))) (time-region (cond (point-on-time-end (cdr time-end-group)) ((and point-on-time-start time-end) (cdr time-group)) (point-on-time-start (cdr time-start-group))))) (when (and time-str time-region) (delete-region (car time-region) (cdr time-region)) (goto-char (car time-region)) (insert time-str) (agenda-mark-entry-at-point) (agenda-highlight (car time-region) (cdr time-region))))))) (defmacro agenda--with-undoable-edit (&rest body) "Execute BODY as a buffer-modifying operation with undo and point safety. This macro ensures: 1. The cursor (point) is preserved after BODY runs. 2. All changes are recorded in an undo change group. 3. If the user repeatedly invokes the same command, all edits are merged into a single undo step. Intended for use with commands that repeatedly modify dates, times, or other buffer content in-place." `(let ((orig-point (point)) (handle (if (eq last-command this-command) agenda--last-handle (prepare-change-group)))) (setq agenda--last-handle handle) (unwind-protect (progn (activate-change-group handle) ,@body) (goto-char orig-point) (when (eq last-command this-command) (undo-amalgamate-change-group handle))))) (defun agenda--shift-up () "Increment date or time at point, based on the cursor position." (let ((groups (agenda-groups-at-point))) (cond ((memq 'date-y groups) (agenda-date-change-at-point '(+1 0 0))) ((memq 'date-m groups) (agenda-date-change-at-point '(0 +1 0))) ((memq 'date-d groups) (agenda-date-change-at-point '(0 0 +7))) ((memq 'time-start-h groups) (agenda-time-change-at-point '(+1 0))) ((memq 'time-start-m groups) (agenda-time-change-at-point '(0 +5))) ((memq 'time-end-h groups) (agenda-time-change-at-point '(+1 0))) ((memq 'time-end-m groups) (agenda-time-change-at-point '(0 +5)))))) (defun agenda--shift-down () "Decrement date or time at point, based on the cursor position." (let ((groups (agenda-groups-at-point))) (cond ((memq 'date-y groups) (agenda-date-change-at-point '(-1 0 0))) ((memq 'date-m groups) (agenda-date-change-at-point '(0 -1 0))) ((memq 'date-d groups) (agenda-date-change-at-point '(0 0 -7))) ((memq 'time-start-h groups) (agenda-time-change-at-point '(-1 0))) ((memq 'time-start-m groups) (agenda-time-change-at-point '(0 -5))) ((memq 'time-end-h groups) (agenda-time-change-at-point '(-1 0))) ((memq 'time-end-m groups) (agenda-time-change-at-point '(0 -5)))))) (defun agenda--shift-right () "Increment date or time at point by 1 day or 1 hour." (let ((groups (agenda-groups-at-point))) (cond ((memq 'date groups) (agenda-date-change-at-point '(0 0 +1))) ((memq 'time groups) (agenda-time-change-at-point '(+1 0)))))) (defun agenda-shift--left () "Decrement date or time at point by 1 day or 1 hour." (let ((groups (agenda-groups-at-point))) (cond ((memq 'date groups) (agenda-date-change-at-point '(0 0 -1))) ((memq 'time groups) (agenda-time-change-at-point '(-1 0)))))) (defun agenda-shift-down () "Decrement date or time at point, based on the cursor position." (interactive) (agenda--with-undoable-edit (agenda--shift-down))) (defun agenda-shift-up () "Increment date or time at point, based on the cursor position." (interactive) (agenda--with-undoable-edit (agenda--shift-up))) (defun agenda-shift-right () "Increment date or time at point by 1 day or 1 hour." (interactive) (agenda--with-undoable-edit (agenda--shift-right))) (defun agenda-shift-left () "Decrement date or time at point by 1 day or 1 hour." (interactive) (agenda--with-undoable-edit (agenda-shift--left))) (defun agenda-filter (regexp &optional strip-comment) "Hide lines not matching REGEXP. Supports keywords like 'future'. With optional STRIP-COMMENT (prefix arg), comment lines are hidden." (interactive (let* ((keywords '("today" "this week" "this month" "tomorrow" "next week" "next month" "future" "marked")) (all (append keywords agenda-filter-history)) (input (completing-read "Filter: " all nil nil nil 'agenda-filter-history))) (list input current-prefix-arg))) (save-excursion (outline-show-all) (let* ((now (current-time)) (keywords `(("today" . ,(format-time-string "%Y-%m-%d" now)) ("tomorrow" . ,(format-time-string "%Y-%m-%d" (time-add now (days-to-time 1)))) ("this week" . ,(format-time-string "w%V" now)) ("this month" . ,(format-time-string "%Y-%m" now)) ("next week" . ,(format-time-string "w%V" (time-add now (days-to-time 7)))) ("future" . "__agenda_future__") ("marked" . "__agenda_mark__"))) (actual-regexp (or (cdr (assoc (downcase (or regexp "")) keywords)) regexp))) (with-silent-modifications (remove-text-properties (point-min) (point-max) '(invisible nil)) (if (string-blank-p actual-regexp) (progn (setq buffer-read-only nil) (outline-minor-mode 1)) (progn (goto-char (point-min)) (while (not (eobp)) (let* ((is-comment (looking-at-p "#")) (matches (cond ((string= actual-regexp "__agenda_mark__") (agenda-line-marked-p)) ((string= actual-regexp "__agenda_future__") (agenda-line-future-p)) (t (agenda-line-match-p actual-regexp))))) (unless (or matches (and (not strip-comment) is-comment)) (put-text-property (line-beginning-position) (line-beginning-position 2) 'invisible t)) (forward-line 1))) (setq buffer-read-only t) (outline-minor-mode -1))))))) (defun agenda-cleanup () "Reparse buffer and recenter." (interactive) (set-window-margins nil 3) (setq buffer-read-only nil) (with-silent-modifications (remove-text-properties (point-min) (point-max) '(invisible nil))) (agenda-parse-buffer) (let ((agenda-edit-mode nil)) (call-interactively (key-binding (this-command-keys))))) (defun agenda-outline-cycle () "Toggle visibility and show hidden count by hijacking the last character." (interactive) (when outline-minor-mode (condition-case nil (save-excursion (outline-back-to-heading) (let* ((line-end (line-end-position)) (subtree-end (save-excursion (outline-end-of-subtree) (point))) (count 0)) (remove-overlays (line-beginning-position) (1+ line-end) 'agenda-count t) (if (outline-invisible-p line-end) (progn (outline-show-entry) (outline-show-children)) (save-excursion (goto-char line-end) (while (re-search-forward agenda-entry-re subtree-end t) (setq count (1+ count)))) (outline-hide-subtree) (when (> count 0) (let* ((char-pos (1- line-end)) (char-at-pos (char-to-string (char-after char-pos))) (ov (make-overlay char-pos line-end))) (overlay-put ov 'display (concat char-at-pos (propertize (format " (%d entries) " count) 'face 'agenda-edit-header-summary))) (overlay-put ov 'agenda-count t) (overlay-put ov 'priority 1000)))))) (error (indent-for-tab-command))))) (defun agenda-outline-cycle-all () "Toggle visibility for the whole buffer. If any heading is hidden, show all. Otherwise, collapse to Level 1 and show counts." (interactive) (when outline-minor-mode (let ((any-folded nil)) (save-excursion (goto-char (point-min)) (while (and (not any-folded) (re-search-forward outline-regexp nil t)) (when (outline-invisible-p (line-end-position)) (setq any-folded t)))) (if any-folded (progn (remove-overlays (point-min) (point-max) 'agenda-count t) (outline-show-all)) (outline-hide-sublevels 1) (save-excursion (goto-char (point-min)) (while (re-search-forward "^# +.*$" nil t) (let* ((line-end (point)) (subtree-end (save-excursion (outline-end-of-subtree) (point))) (count 0)) (remove-overlays (line-beginning-position) (1+ line-end) 'agenda-count t) (save-excursion (while (re-search-forward agenda-entry-re subtree-end t) (setq count (1+ count)))) (when (> count 0) (let* ((char-pos (1- line-end)) (char-at-pos (char-to-string (char-after char-pos))) (ov (make-overlay char-pos line-end))) (overlay-put ov 'display (concat char-at-pos (propertize (format " (%d entries) " count) 'face 'agenda-edit-header-summary))) (overlay-put ov 'agenda-count t) (overlay-put ov 'priority 1000)))))))))) (defun agenda--goto-date (target &optional exact) "Go to the TARGET date (month day year). If EXACT is non-nil, only stops on a perfect match. Otherwise, stops on the closest date equal to or older than selected date." (let* ((target-time (encode-time 0 0 0 (nth 1 target) (nth 0 target) (nth 2 target))) (target-days (time-to-days target-time)) (best-pos nil)) (save-excursion (goto-char (point-max)) (catch 'found (while (re-search-backward agenda-entry-re nil t) (let* ((entry-date-str (car (agenda-match 'date-iso))) (entry-time-str (or (car (agenda-match 'time-start)) "00:00")) (entry-days (time-to-days (date-to-time (concat entry-date-str " " entry-time-str))))) (if exact (cond ((= entry-days target-days) (setq best-pos (match-beginning 0)) (throw 'found t)) ((< entry-days target-days) (setq best-pos nil) (throw 'found nil))) (setq best-pos (match-beginning 0)) (when (<= entry-days target-days) (throw 'found t))))))) (if best-pos (progn (goto-char best-pos) (beginning-of-line))))) (defun agenda-goto-date (&optional exact) "Open the calendar and go to the selected date when RET is pressed. If EXACT is non-nil, only stops on a perfect match. Otherwise, stops on the closest date equal to or older than selected date." (interactive (list current-prefix-arg)) (agenda-with-calendar-select date (agenda--goto-date date))) (defun agenda-insert-entry (&optional here) "Open the calendar and insert a new entry for the selected date. If HERE is t, insert entry at point, else, search for closest date." (interactive (list current-prefix-arg)) (agenda-with-calendar-select date (unless here (agenda--goto-date date)) (end-of-line) (unless (= (line-beginning-position) (line-end-position)) (insert "\n")) (let* ((timestamp (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))) (hour (string-to-number (format-time-string "%H")))) (insert (concat (format-time-string "%Y-%m-%d w%V %a" timestamp) " " (format "%02d:00" hour) "-" (format "%02d:00 " (min (1+ hour) 24))))))) (defun agenda-repeat-entry (frequency count) "Read current entry and create COUNT copies incremented by FREQUENCY. FREQUENCY is a string like '+1w', '+3d', '+1m', or '+1y'." (interactive "sFrequency (e.g., +1w): \nnCount: ") (save-excursion (beginning-of-line) (if (not (looking-at agenda-entry-re)) (user-error "Not on a valid agenda entry") (let* ((year (string-to-number (car (agenda-match 'date-y)))) (month (string-to-number (car (agenda-match 'date-m)))) (day (string-to-number (car (agenda-match 'date-d)))) (rest (buffer-substring (cddr (agenda-match 'date)) (line-end-position))) (val (string-to-number (substring frequency 1 -1))) (unit (substring frequency -1)) (delta (pcase unit ("d" (list val 0 0)) ("w" (list (* val 7) 0 0)) ("m" (list 0 val 0)) ("y" (list 0 0 val)) (_ (user-error "Unknown unit: %s" unit))))) (end-of-line) (dotimes (i count) (let* ((multiplier (1+ i)) (new-time (encode-time 0 0 0 (+ day (* multiplier (nth 0 delta))) (+ month (* multiplier (nth 1 delta))) (+ year (* multiplier (nth 2 delta)))))) (insert (format-time-string "\n%Y-%m-%d w%V %a" new-time) rest))))))) (defun agenda-collect-uids () "Scan agenda buffer for all UIDs (entry & data lines)." (let (uids) (save-excursion ;; Entry lines (goto-char (point-min)) (while (re-search-forward agenda-entry-re nil t) (when-let ((uid-str (agenda-match 'uid))) (push (substring (car uid-str) 1 -1) uids))) ;; Data lines (goto-char (point-min)) (while (re-search-forward agenda-data-re nil t) (when-let ((uid-str (agenda-match 'data-uid))) (push (car uid-str) uids)))) (delete-dups uids))) (defun agenda-entry-generate-uid (entry) "Generate a unique id for ENTRY. Checks YYYYMMDDTHHMM, then YYYYMMDDT0001, T0002, etc." (let* ((uid-data (cdr (assoc 'uid (assoc 'data entry)))) (used (delete uid-data (agenda-collect-uids))) (date (cdr (assoc 'date entry))) (time (or (cdr (assoc 'time-start entry)) '(0 1))) (uid-prefix (format "%04d%02d%02dT" (nth 0 date) (nth 1 date) (nth 2 date))) (uid-suffix (format "%02d%02d" (nth 0 time) (nth 1 time))) (uid-auto (or uid-data (concat uid-prefix uid-suffix))) (uid-uniq (if (not (member uid-auto used)) uid-auto (let ((count 1) (res nil)) (while (not res) (let ((uid-temp (format "%s%04d" uid-prefix count))) (if (not (member uid-temp used)) (setq res uid-temp) (setq count (1+ count))))) res))) (uid-user (read-string "UID: " uid-uniq))) (while (member uid-user used) (setq uid-user (read-string (format "UID '%s' already used! New UID: " uid-user) uid-uniq))) uid-user)) (defun agenda-entry-set-data (uid key value) "Update or create metadata for entry at point. If C-u is provided, prompts to confirm/modify the UID. Metadata is stored at the END of the buffer. [NOTE]: Co-written with Gemini." (interactive (let* ((entry (or (agenda-entry-at-point) (user-error "No entry at point"))) (data-alist (cdr (assoc 'data entry))) ;; 1. Handle UID: Prompt ONLY if prefix argument (C-u) is active (final-uid (if current-prefix-arg (agenda-entry-generate-uid entry) (or (cdr (assoc 'uid data-alist)) ;; Silent generation if no UID exists (let ((uid-data (cdr (assoc 'uid data-alist))) (used (agenda-collect-uids)) (date (cdr (assoc 'date entry))) (time (or (cdr (assoc 'time-start entry)) '(0 1)))) (let* ((prefix (format "%04d%02d%02dT" (nth 0 date) (nth 1 date) (nth 2 date))) (suffix (format "%02d%02d" (nth 0 time) (nth 1 time))) (base (concat prefix suffix))) (if (not (member base used)) base (let ((c 1) (res nil)) (while (not res) (let ((cand (format "%s%04d" prefix c))) (if (not (member cand used)) (setq res cand) (setq c (1+ c))))) res))))))) ;; 2. Select Key (selected-key (completing-read "Key: " '("URL" "MAP" "NOTE") nil t)) ;; 3. Extract existing value from data alist (key-sym (intern (downcase selected-key))) (current-val (or (cdr (assoc key-sym data-alist)) ""))) (list final-uid selected-key (read-string (format "Value (%s): " selected-key) current-val)))) (let ((entry-pos (copy-marker (line-beginning-position)))) ;; 1. Sync the UID on the entry line (save-excursion (goto-char entry-pos) (let ((existing-uid (cdr (assoc 'uid (assoc 'data (agenda-entry-at-point)))))) (unless (string= uid existing-uid) (when (re-search-forward " +\\[[^]]+\\]" (line-end-position) t) (replace-match "")) (goto-char (line-end-position)) (insert (format " [%s]" uid))))) ;; 2. Update or delete the data line at the end of the buffer (save-excursion (goto-char (point-max)) (unless (bolp) (insert "\n")) (let ((search-re (format "^\\[%s:%s\\]:" (regexp-quote uid) (regexp-quote key))) (found-pos nil)) (save-excursion (when (re-search-backward search-re nil t) (setq found-pos (line-beginning-position)))) (cond ((and found-pos (string-empty-p value)) (goto-char found-pos) (delete-region (line-beginning-position) (progn (forward-line 1) (point)))) ((and found-pos (not (string-empty-p value))) (goto-char found-pos) (delete-region (line-beginning-position) (line-end-position)) (insert (format "[%s:%s]: %s" uid key value))) ((not (string-empty-p value)) (goto-char (point-max)) (unless (bolp) (insert "\n")) (insert (format "[%s:%s]: %s\n" uid key value)))))) ;; 3. Cleanup Header (save-excursion (goto-char (point-min)) (unless (re-search-forward (format "^\\[%s:[[:alpha:]]+\\]:" (regexp-quote uid)) nil t) (goto-char entry-pos) (when (re-search-forward (format " +\\[%s\\]" (regexp-quote uid)) (line-end-position) t) (replace-match "")))) (set-marker entry-pos nil))) (defun agenda-insert-holidays (year &optional no-header) "Generate and insert holidays for YEAR. With a prefix argument (C-u), skip the '# Holidays' header." (interactive (list (read-number "Year: " (nth 5 (decode-time (current-time)))) current-prefix-arg)) (let ((results nil)) (save-window-excursion (list-holidays year year)) (with-current-buffer "*Holidays*" (save-excursion (goto-char (point-min)) (while (re-search-forward "^\\([^:\n]+\\): +\\(.*\\)$" nil t) (let* ((date-raw (match-string 1)) (event-name (match-string 2)) (parsed (parse-time-string date-raw)) (day (nth 3 parsed)) (month (nth 4 parsed)) (item-year (or (nth 5 parsed) year))) (when (and day month) (let* ((time-val (encode-time 0 0 0 day month item-year)) (full-date (format-time-string "%Y-%m-%d w%V %a" time-val))) (push (format "%s %s +HOLIDAYS\n" full-date event-name) results))))))) (when results (unless no-header (insert (format "## Holidays %d\n\n" year))) (dolist (line (reverse results)) (insert line)) (unless no-header (insert "\n"))))) (defvar agenda-edit-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "S-") #'agenda-shift-right) (define-key map (kbd "S-") #'agenda-shift-left) (define-key map (kbd "S-") #'agenda-shift-down) (define-key map (kbd "S-") #'agenda-shift-up) (define-key map (kbd "C-c e") #'agenda-export) (define-key map (kbd "C-c g") #'agenda-goto-date) (define-key map (kbd "C-c i") #'agenda-insert-entry) (define-key map (kbd "C-c r") #'agenda-repeat-entry) (define-key map (kbd "C-c d") #'agenda-entry-set-data) (define-key map (kbd "C-c f") #'agenda-filter) (define-key map (kbd "C-l") #'agenda-cleanup) (define-key map (kbd "TAB") #'agenda-outline-cycle) (define-key map (kbd "") #'agenda-outline-cycle-all) (define-key map (kbd "C-c a") #'agenda-view) map) "Keymap for 'agenda-edit-mode'.") (defconst agenda-font-lock-keywords `((,agenda-data-re (0 'agenda-edit-data) (,(agenda-group 'data-ref) '(agenda-edit-data-ref) prepend t)) (,agenda-header-re (0 'agenda-edit-header)) (,agenda-comment-re (0 'agenda-edit-comment)) (,agenda-entry-re (0 (let* ((date (car (agenda-match 'date))) (time (car (agenda-match 'time))) (tags (car (agenda-match 'tags)))) (setq-local is-today (agenda-date-today-p date)) (setq-local is-now (agenda-date-time-now-p date time)) (setq-local is-inweek (agenda-date-inweek-p (match-string 1))) (setq-local is-cancel (agenda-tags-cancel-p tags)) (setq-local is-deadline (and (agenda-tags-deadline-p tags) (not (agenda-tags-done-p tags)))) (cond (is-cancel 'agenda-edit-cancel) ((and (not is-inweek) (not is-today)) 'agenda-edit-outweek) (t nil)))) (,(agenda-group 'date) (cond (is-cancel 'agenda-edit-cancel) (is-deadline 'agenda-edit-deadline) ((and is-today is-deadline) 'agenda-edit-deadline) (is-today 'agenda-edit-today) (is-inweek 'agenda-edit-inweek) (t 'agenda-edit-outweek)) prepend) (,(agenda-group 'time) (cond (is-cancel 'agenda-edit-cancel) (is-today 'agenda-edit-today) (is-inweek 'agenda-edit-inweek) (t 'agenda-edit-outweek)) prepend t) (,(agenda-group 'title) (cond (is-cancel 'agenda-edit-cancel) (is-today 'agenda-edit-today) (is-inweek 'agenda-edit-inweek) (t 'agenda-edit-outweek)) prepend) (,(agenda-group 'actions) (cond (is-cancel 'agenda-edit-cancel) (is-today '(agenda-edit-action agenda-edit-today)) (is-inweek 'agenda-edit-action) (t 'agenda-edit-outweek)) prepend t) (,(agenda-group 'tags) (cond (is-cancel 'agenda-edit-cancel) (is-today '(agenda-edit-tag agenda-edit-today)) (is-inweek 'agenda-edit-tag) (t 'agenda-edit-outweek)) prepend t) (,(agenda-group 'uid) (cond (is-cancel 'agenda-edit-cancel) (is-today '(agenda-edit-reference agenda-edit-today)) (is-inweek 'agenda-edit-reference) (t 'agenda-edit-outweek)) prepend t))) "Agenda font lock for edit mode.") ;;;###autoload (define-minor-mode agenda-edit-mode "Minor mode for editing agenda files." :lighter "Agenda[E]" :keymap agenda-edit-mode-map (if agenda-edit-mode (progn (font-lock-add-keywords nil agenda-font-lock-keywords 'append) (font-lock-flush) (font-lock-ensure) (set-window-margins nil 3) (setq-local left-margin-width 3) (setq-local outline-regexp "^\\(#+\\) " outline-level (lambda () (length (match-string 1))) outline-heading-end-regexp "\n" outline-end-of-heading-function nil) (outline-minor-mode 1) (agenda-parse-buffer)) (progn (font-lock-remove-keywords nil agenda-font-lock-keywords) (set-window-margins nil 0) (setq-local left-margin-width 0) (agenda-highlight-clear) (with-silent-modifications (remove-text-properties (point-min) (point-max) '(invisible nil)) (remove-text-properties (point-min) (point-max) '(display nil)) (remove-overlays (point-min) (point-max))) (font-lock-flush) (font-lock-ensure)))) (provide 'agenda-edit) ;;; agenda-edit.el ends here ================================================ FILE: agenda-export.el ================================================ ;;; agenda-export.el --- Export functions -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'agenda-parse) (defun agenda-export--ical-sanitize (string) "Sanitize STRING by escaping commas, semicolons, and newlines with a backslash and removing unicode nerd icons." (when (stringp string) (setq string (replace-regexp-in-string (regexp-quote "\\") "\\\\" string t t)) (setq string (replace-regexp-in-string (regexp-quote ",") "\\," string t t)) (setq string (replace-regexp-in-string (regexp-quote ";") "\\;" string t t)) (setq string (replace-regexp-in-string (regexp-quote "\n") "\\n" string t t)) (setq string (replace-regexp-in-string "[\uE000-\uF8FF] " "" string)) string)) (defun agenda-export--ical-uid (date time public) "Generate UID from DATE, TIME and PUBLIC. Public UIDs are suffixed with '-PUBLIC', else with '-PRIVATE'." (format "%04d%02d%02dT%02d%02d%s" (nth 0 date) (nth 1 date) (nth 2 date) (if time (nth 0 time) 0) (if time (nth 1 time) 0) (if public "-PUBLIC" "-PRIVATE"))) (defun agenda-export--ical-timestamp (date time &optional public) (if time (format "%04d%02d%02dT%02d%02d00" (nth 0 date) (nth 1 date) (nth 2 date) (nth 0 time) (nth 1 time)) (format "%04d%02d%02d" (nth 0 date) (nth 1 date) (nth 2 date)))) (defun agenda-export--ical-entry (entry &optional public) "Return regular ENTRY as a VEVENT ical string. Generated UID and informations depends on whether PUBLIC is t." (let* ((date (cdr (assoc 'date entry))) (time-start (cdr (assoc 'time-start entry))) (time-end (cdr (assoc 'time-end entry))) (title (cdr (assoc 'title entry))) (actions (cdr (assoc 'actions entry))) (tags (cdr (assoc 'tags entry))) (is-deadline (member "DEADLINE" tags)) (is-birthday (member "BIRTHDAY" tags)) (data (cdr (assoc 'data entry))) (url (cdr (assoc 'url data))) (note (cdr (assoc 'note data))) (map (cdr (assoc 'map data)))) (concat "BEGIN:VEVENT\n" ;; UID (format "UID:%s\n" (agenda-export--ical-uid date time-start public)) ;; DSTAMP (format "DTSTAMP:%s\n" (format-time-string "%Y%m%dT%H%M%SZ" nil t)) ;; DTSTART or DUE (if is-deadline (concat (format "DUE:%s\n" (agenda-export--ical-timestamp date time-start)) "STATUS:NEEDS-ACTION\n") (format "DTSTART:%s\n" (agenda-export--ical-timestamp date time-start))) ;; DTEND (when (and time-end (not is-deadline) (not is-birthday)) (format "DTEND:%s\n" (agenda-export--ical-timestamp date time-end))) ;; BIRTHDAY (when is-birthday (concat "RRULE:FREQ=YEARLY\n" "TRANSP:TRANSPARENT\n" "X-APPLE-SPECIAL-DAY:BIRTHDAY\n")) ;; PUBLIC part (if public ;; SUMMARY (if map (format "SUMMARY:(away)\n") (format "SUMMARY:(busy)\n")) ;; PRIVATE part (concat ;; SUMMARY (format "SUMMARY:%s (%s)\n" (agenda-export--ical-sanitize title) (mapconcat #'string-trim actions ",")) ;; CATEGORIES (when tags (format "CATEGORIES:%s\n" (mapconcat #'string-trim tags ","))) ;; URL (when url (format "URL:%s\n" url)) ;; LOCATION (when map (format "LOCATION:%s\n" map)) ;; DESCRIPTION (when note (format "DESCRIPTION: %s\n" (agenda-export--ical-sanitize note))))) "END:VEVENT\n"))) (defun agenda-export-ical (filename &optional public) (let ((entries (agenda-collect-entries t))) (with-temp-buffer (insert "BEGIN:VCALENDAR\n" "VERSION:2.0\n" "CALSCALE:GREGORIAN\n" (format "X-WR-CALNAME:%s/%s\n" (upcase user-login-name) (upcase (if public "public" "private"))) (format-time-string "X-WR-TIMEZONE:%Z\n") "\n") (dolist (entry entries) (insert (agenda-export--ical-entry entry public) "\n")) (insert "\n" "END:VCALENDAR\n") (write-region (point-min) (point-max) filename)))) (defun agenda-export-sync () "Run 'vdirsyncer sync' and report status / time." (interactive) (let* ((buf-name "*Vdirsyncer Output*") (buf (get-buffer-create buf-name)) (proc (get-buffer-process buf)) (start-time (float-time (current-time)))) (if (process-live-p proc) (message "vdirsyncer is already running.") (progn (with-current-buffer buf (let ((inhibit-read-only t)) (erase-buffer))) (message "vdirsyncer: sync started...") (let ((new-proc (start-process-shell-command "vdir-sync" buf "vdirsyncer sync"))) (set-process-sentinel new-proc (lambda (p event) (let* ((elapsed (- (float-time (current-time)) start-time)) (p-buf (process-buffer p))) (cond ((string-match-p "finished" event) (message "vdirsyncer: sync complete (%.2fs)." elapsed)) ((string-match-p "exited abnormally" event) (message "vdirsyncer: sync failed (%.2fs)." elapsed) (pop-to-buffer p-buf))))))))))) (defun agenda-export (&optional no-sync) "Export agenda in public and private ical files and synchronize them using vdirsyncer unless NO-SYNC is t." (interactive) (if (and agenda-file-ical-public (file-exists-p agenda-file-ical-public)) (agenda-export-ical agenda-file-ical-public t) (error "Public ical file (%s) does not exist." agenda-file-ical-public)) (if (and agenda-file-ical-private (file-exists-p agenda-file-ical-private)) (agenda-export-ical agenda-file-ical-private nil) (error "Private ical file (%s) does not exist." agenda-file-ical-private)) (unless no-sync (agenda-export-sync))) (provide 'agenda-export) ;;; agenda-export.el ends here ================================================ FILE: agenda-faces.el ================================================ ;;; agenda-faces.el --- Visual styles and customization -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (defgroup agenda nil "Agenda" :group 'applications) (defgroup agenda-edit-faces nil "Agenda faces for edit mode." :group 'agenda) (defgroup agenda-view-faces nil "Agenda faces for view mode." :group 'agenda) (defface agenda-edit-highlight '((t :inherit (widget-field bold default) :inverse-video nil)) "Face for transient highlighting (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-inweek '((t :inherit (default))) "Face for entries in current week (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-outweek '((t :inherit (shadow))) "Face for entries oustide current week (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-today '((t :inherit (bold))) "Face for today entries (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-tag '((t :inherit (warning))) "Face for tags (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-action '((t :inherit (link))) "Face for actions (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-reference '((t :inherit shadow)) "Face for references (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-data '((t :inherit shadow)) "Face for data line (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-data-ref '((t :inherit (shadow bold))) "Face for key on data line (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-cancel '((t :strike-through t :inherit shadow)) "Face for cancelled entries (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-deadline '((t :inherit (error bold))) "Face for deadline entries (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-header '((t :inherit (bold))) "Face for headers (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-header-prefix '((t :inherit (shadow default))) "Face for headers prefix (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-header-summary '((t :inherit (warning))) "Face for headers entries summary (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-data '((t :inherit (shadow))) "Face for date line (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-ref '((t :inherit (bold))) "Face for date line reference (edit mode)." :group 'agenda-edit-faces) (defface agenda-edit-comment '((t :inherit (shadow))) "Face for comments (edit mode)." :group 'agenda-edit-faces) (defface agenda-view-title '((t :inherit (bold))) "Face for title (week, view mode)." :group 'agenda-view-faces) (defface agenda-view-subtitle '((t :inherit (shadow))) "Face for subtitle (week extent, view mode)." :group 'agenda-view-faces) (defface agenda-view-date '((t :inherit (bold))) "Face for date (view mode)." :group 'agenda-view-faces) (defface agenda-view-tag '((t :inherit (agenda-edit-tag))) "Face for tags (view mode)." :group 'agenda-view-faces) (defface agenda-view-action '((t :inherit (agenda-edit-action))) "Face for actions (view mode)." :group 'agenda-view-faces) (defface agenda-view-cancel '((t :inherit agenda-edit-cancel)) "Face for cancelled entries (view mode)." :group 'agenda-view-faces) (defface agenda-view-button '((t :inherit (link bold))) "Face for buttons (view mode)." :group 'agenda-view-faces) (defface agenda-view-time '((t :inherit (bold))) "Face for time (view mode)." :group 'agenda-view-faces) (defface agenda-view-deadline-header '((t :inherit (bold error))) "Face for deadline header (view mode)." :group 'agenda-view-faces) (defface agenda-view-date-today '((t :inherit (bold error))) "Face for today text in view mode." :group 'agenda-faces) (defface agenda-view-time-today '((t :inherit (bold))) "Face for today time (view mode)." :group 'agenda-view-faces) (defface agenda-view-time-now '((t :inverse-video t :inherit bold)) "Face for now time (view mode)." :group 'agenda-view-faces) (defface agenda-deadline-0 '((t :inverse-video t :inherit (bold))) "Face for deadline with priority 0." :group 'agenda-view-faces) (defface agenda-deadline-1 '((t :inverse-video t :inherit (bold error))) "Face for deadline with priority 1." :group 'agenda-view-faces) (defface agenda-deadline-2 '((t :inherit (bold error))) "Face for deadline with priority 2." :group 'agenda-view-faces) (defface agenda-deadline-3 '((t :inherit (bold))) "Face for deadline with priority 3." :group 'agenda-view-faces) (defface agenda-slot-free '((t :inherit region)) "Face for free slot." :group 'agenda-view-faces) (defface agenda-slot-busy '((t :inverse-video t :inherit (bold shadow))) "Face for busy slot." :group 'agenda-view-faces) (defface agenda-slot-busy-inweek '((t :inverse-video t :inherit (bold))) "Face for busy slot for the current week." :group 'agenda-view-faces) (defface agenda-slot-deadline '((t :inverse-video t :inherit (error bold))) "Face for busy & deadline slot." :group 'agenda-view-faces) (defface agenda-slot-personal '((t :inverse-video t :inherit (link bold))) "Face for busy & personal slot." :group 'agenda-view-faces) (provide 'agenda-faces) ;;; agenda-faces.el ends here ================================================ FILE: agenda-parse.el ================================================ ;;; agenda-parse.el --- Parsing, test and collect functions -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;; Commentary: ;; This module provides all parsing and test functions for processing ;; agenda source file. ;; ;; It handles: ;; - Identification of entries via regular expressions. ;; - Various tests on string or entries ;; - Convertion of raw text lines into entry ;; - Conversion of entries field into string ;; - Collect entries based on a filter function ;; - Compute 30mn slots for a given date ;; ;; All collect functions use a cache whose invalidation is based on ;; buffer modified tick. Cache can be bypassed with the force ;; parameter in relevant functions. ;;; Code: (require 'rx) (defconst agenda-entry-re (rx line-start ;; --- DATE BLOCK --- (submatch-n 1 ;; date (e.g., "2026-01-17 W02 Sat") (submatch-n 2 ;; date-iso (e.g., "2026-01-17") (submatch-n 3 (repeat 4 digit)) "-" ;; date-y (submatch-n 4 (repeat 2 digit)) "-" ;; date-m (submatch-n 5 (repeat 2 digit))) ;; date-d (optional (one-or-more space) (any "Ww") (one-or-more digit)) (optional (one-or-more space) (one-or-more letter))) (one-or-more space) ;; --- TIME BLOCK --- (optional (submatch-n 6 ;; time (e.g., "08:30-10:00") (submatch-n 7 ;; time-start (e.g., "08:30") (submatch-n 8 (repeat 2 digit)) ":" ;; time-start-h (submatch-n 9 (repeat 2 digit))) ;; time-start-m (optional "-" (submatch-n 10 ;; time-end (e.g., "10:00") (submatch-n 11 (repeat 2 digit)) ":" ;; time-end-h (submatch-n 12 (repeat 2 digit)))))) ;; time-end-m (optional (one-or-more space) (one-or-more "-")) ;; Aesthetic dashes (one-or-more space) ;; --- CONTENT BLOCK --- ;; (submatch-n 13 (minimal-match (zero-or-more (not (any "@+#")))) ;; (not (any "@+# "))) ;; non-empty title (submatch-n 13 (zero-or-more (not (any "@+#\n")))) ;; title (optional (one-or-more space) (submatch-n 14 (one-or-more (seq "@" (one-or-more (not (any space "+@#"))) (zero-or-more space))))) ;; actions (optional (one-or-more space) (submatch-n 15 (one-or-more (seq "+" (one-or-more (not (any space "+@#"))) (zero-or-more space))))) ;; tags ;; --- UID BLOCK --- (optional (one-or-more space) (submatch-n 16 "[" (one-or-more (any alnum "-")) "]")) ;; [UID] line-end) "Matches an entry line with several groups that can be accessed using the 'agenda-match' function.") (defconst agenda-data-re (rx line-start "[" (submatch-n 1 ;; Full data ref (UID:KEY) (submatch-n 2 (one-or-more (any alnum "-"))) ;; UID ":" (submatch-n 3 (one-or-more alpha))) ;; KEY "]:" (zero-or-more space) (submatch-n 4 (zero-or-more not-newline)) ;; Content (value) line-end) "Matches a data line with several groups that can be accessed using the 'agenda-match' function.") (defconst agenda-header-re (rx line-start (submatch-n 1 (one-or-more "#") (one-or-more space)) (group (one-or-more (not (any ":" "\n")))) ;; No colons allowed line-end) "Matches a header line.") (defconst agenda-comment-re (rx line-start "#" (one-or-more space) (group (zero-or-more not-newline)) line-end) "Matches a comment line.") (defconst agenda-group-map '(;; All (all . 0) ;; Entry line (1-16) (date . 1) (date-iso . 2) (date-y . 3) (date-m . 4) (date-d . 5) (time . 6) (time-start . 7) (time-start-h . 8) (time-start-m . 9) (time-end . 10) (time-end-h . 11) (time-end-m . 12) (title . 13) (actions . 14) (tags . 15) (uid . 16) (ref . 16) ;; Data line (1-4) (data . 0) (data-ref . 1) (data-uid . 2) (data-key . 3) (data-value . 4)) "Fixed mapping of semantic names to group indices for both 'agenda-entry-re' and 'agenda-data-re'") (defun agenda-group (type) "Get the group number for TYPE (from the 'agenda-group map')." (or (cdr (assoc type agenda-group-map)) (error "Unknown agenda group: %s" type))) (defun agenda-match (type &optional string) "Return (MATCH-STRING . (BEG . END)) for group TYPE and optional STRING by the previous search or regexp operation." (let ((group (agenda-group type))) (when (match-beginning group) (cons (match-string-no-properties group string) (cons (match-beginning group) (match-end group)))))) (defun agenda-groups-at-point () "Return list of groups at point, sorted by descending specificity." (save-excursion (let ((point (point))) (beginning-of-line) (when-let* ((line-type (cond ((looking-at agenda-entry-re) :entry) ((looking-at agenda-data-re) :data) (t nil)))) (let (matches) (dolist (entry agenda-group-map) (let* ((sym (car entry)) (group (cdr entry)) (is-data (string-prefix-p "data-" (symbol-name sym)))) (when (eq (if is-data :data :entry) line-type) (let ((beg (match-beginning group)) (end (match-end group))) (when (and beg end (>= point beg) (<= point end)) (push (cons sym (- end beg)) matches)))))) (mapcar #'car (sort matches (lambda (a b) (> (cdr a) (cdr b)))))))))) (defun agenda-lookup-data (uid) "Scan buffer backwards for data lines matching UID and return an alist of (key . value)." (save-match-data (save-excursion (goto-char (point-max)) (let ((results `((uid . ,uid)))) (while (re-search-backward agenda-data-re nil t) (when (string= (car (agenda-match 'data-uid)) uid) (push (cons (intern (downcase (car (agenda-match 'data-key)))) (car (agenda-match 'data-value))) results))) results)))) (defun agenda-entry-from-match () "Return an entry from previous search or regexp operation." (let* ((date (list (string-to-number (car (agenda-match 'date-y))) (string-to-number (car (agenda-match 'date-m))) (string-to-number (car (agenda-match 'date-d))))) (time-start (when-let ((h (car (agenda-match 'time-start-h))) (m (car (agenda-match 'time-start-m)))) (list (string-to-number h) (string-to-number m)))) (time-end (when-let ((h (car (agenda-match 'time-end-h))) (m (car (agenda-match 'time-end-m)))) (list (string-to-number h) (string-to-number m)))) (title (when-let ((title (car (agenda-match 'title)))) (string-trim title))) (actions (when-let ((actions (car (agenda-match 'actions)))) (save-match-data (split-string (string-trim actions) "@" t)))) (tags (when-let ((tags (car (agenda-match 'tags)))) (save-match-data (split-string (string-trim tags) "+" t)))) (marker (save-excursion (goto-char (match-beginning 0)) (point-marker))) (uid (when-let ((uid (car (agenda-match 'uid)))) (substring uid +1 -1))) ;; Remove [ and ] (data (when uid (agenda-lookup-data uid)))) `((date . ,date) (marker . ,marker) (time-start . ,time-start) (time-end . ,time-end) (title . ,title) (actions . ,actions) (tags . ,tags) (data . ,data)))) (defun agenda-entry-at-point () "Get entry at point (if any)." (save-excursion (beginning-of-line) (when (looking-at agenda-entry-re) (agenda-entry-from-match)))) (defun agenda-data-at-point () "Get data at point (if any)." (save-excursion (beginning-of-line) (when (looking-at agenda-data-re) (let ((uid (car (agenda-match 'data-uid))) (key (intern (downcase (car (agenda-match 'data-key))))) (val (car (agenda-match 'data-value)))) (cons uid (cons key val)))))) (defun agenda-entry-date-string (entry &optional format) "Return ENTRY date as a formatted string using FORMAT. Default format is YYYY-MM-DD wXX Day." (let* ((format (or format "%Y-%m-%d w%V %a")) (date (cdr (assoc 'date entry))) (year (nth 0 date)) (month (nth 1 date)) (day (nth 2 date)) (timestamp (encode-time (list 0 0 0 day month year)))) (format-time-string format timestamp))) (defun agenda-entry-date-iso-string (entry) "Return ENTRY date as an ISO date format YYYY-MM-DD." (agenda-entry-date-string entry "%Y-%m-%d")) (defun agenda-entry-time-start-string (entry) "Return ENTRY time start as a formatted string HH:MM or nil." (when-let* ((time (cdr (assoc 'time-start entry))) (time-h (nth 0 time)) (time-m (nth 1 time))) (format "%02d:%02d" time-h time-m))) (defun agenda-entry-time-end-string (entry) "Return ENTRY time end ad a formatted string HH:MM or nil." (when-let* ((time (cdr (assoc 'time-end entry))) (time-h (nth 0 time)) (time-m (nth 1 time))) (format "%02d:%02d" time-h time-m))) (defun agenda-entry-time-string (entry) "Convert ENTRY time as a formatted string [HH:MM[-HH:MM]]." (let* ((time-start (agenda-entry-time-start-string entry)) (time-end (agenda-entry-time-end-string entry))) (cond ((and time-start time-end) (format "%s-%s" time-start time-end)) (time-start time-start)))) (defun agenda-entry-tags-string (entry) "Return ENTRY tags formatted for display." (when-let* ((tags (cdr (assoc 'tags entry)))) (mapconcat (lambda (tag) (concat "+" tag)) tags ""))) (defun agenda-entry-actions-string (entry) "Return ENTRY actions formatted for display." (when-let* ((actions (cdr (assoc 'actions entry)))) (mapconcat (lambda (action) (concat "@" action)) actions ""))) (defun agenda-entry-title-string (entry) "Return ENTRY title formatted for display." (cdr (assoc 'title entry))) (defun agenda-entry-less-p (entry-1 entry-2) "Return non-nil if ENTRY1 is before ENTRY2 (lexicographic order based on entries date+time)." (let ((entry-1-str (concat (agenda-entry-date-iso-string entry-1) " " (agenda-entry-time-string entry-1))) (entry-2-str (concat (agenda-entry-date-iso-string entry-2) " " (agenda-entry-time-string entry-2)))) (string< entry-1-str entry-2-str))) (defun agenda-line-marked-p () "Return non-nil if current line has a margin-mark overlay." (seq-find (lambda (ov) (overlay-get ov 'agenda-mark)) (overlays-in (line-beginning-position) (line-end-position)))) (defun agenda-line-future-p () "Return non-nil if line starts with a date >= today." (let ((today (format-time-string "%Y-%m-%d")) (date (buffer-substring (line-beginning-position) (+ (line-beginning-position) (length today))))) (or (string= date today) (string> date today)))) (defun agenda-line-match-p (regex) "Return non-nil if REGEX matches the current line." (let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) (case-fold-search t)) (string-match-p regex line))) (defun agenda-date-today-p (date-str) "Return t if DATE-STR (formatted as 'YYYY-MM-DD') is today." (when (stringp date-str) (string-prefix-p (format-time-string "%Y-%m-%d") date-str))) (defun agenda-date-time-now-p (date-str time-str) "Return t if DATE-STR (formatted as 'YYYY-MM-DD') is today and current time is within TIME-STR range (formatted as 'HH:MM-HH:MM')" (when (and (stringp date-str) (stringp time-str) (agenda-date-today-p date-str)) (save-match-data (when-let* ((now (current-time)) (times (string-split time-str "-")) (start-str (nth 0 times)) (end-str (or (nth 1 times) start-str)) (time-start (date-to-time (concat date-str " " start-str))) (time-end (date-to-time (concat date-str " " end-str)))) (and (not (time-less-p now time-start)) (time-less-p now time-end)))))) (defun agenda-date-inweek-p (date-str) "Return t if DATE-STR (formatted as 'YYYY-MM-DD wXX Day') is in current week." (when (stringp date-str) (save-match-data (string-match-p (format-time-string "[wW]%V") date-str)))) (defun agenda-tags-cancel-p (tags-str) "Check if +CANCEL is present in TAGS-STR." (when (stringp tags-str) (save-match-data (string-match-p "+CANCEL" tags-str)))) (defun agenda-tags-deadline-p (tags-str) "Check if +DEADLINE is present in TAGS-STR." (when (stringp tags-str) (save-match-data (string-match-p "+DEADLINE" tags-str)))) (defun agenda-tags-active-deadline-p (tags-str) "Check if +DEADLINE is present in TAGS-STR but not +DONE." (when (stringp tags-str) (save-match-data (and (string-match-p "+DEADLINE" tags-str) (not (string-match-p "+DONE" tags-str)))))) (defun agenda-tags-done-p (tags-str) "Check if +DONE is present in TAGS-STR." (when (stringp tags-str) (save-match-data (string-match-p "+DONE" tags-str)))) (defun agenda-tags-personal-p (tags-str) "Check if +PERSONAL is present in TAGS-STR." (when (stringp tags-str) (save-match-data (string-match-p "+PERSONAL" tags-str)))) (defun agenda-tags-birthday-p (tags-str) "Check if +BIRTHDAY is present in TAGS-STR." (when (stringp tags-str) (save-match-data (string-match-p "+BIRTHDAY" tags-str)))) (defun agenda-entry-inweek-p (entry &optional week year) "Return t if entry is in WEEK (str) of YEAR (str)." (let* ((date (agenda-entry-date-string entry)) (week (or week (string-to-number (format-time-string "%V")))) (week (format "[wW]%02d" week)) (year (or year (string-to-number (format-time-string "%Y")))) (year (format "%04d" year))) (and (string-prefix-p year date) (string-match-p week date)))) (defun agenda-entry-between-p (entry &optional beg end) "Return t if entry is between BEG and END (YYYY-MM-DD format). If BEG is nil, there is no lower bound. If END is nil, there is no upper bound." (let ((date (agenda-entry-date-string entry "%Y-%m-%d"))) (and date (or (null beg) (not (string< date beg))) (or (null end) (not (string< end date)))))) (defun agenda-entry-strictly-between-p (entry &optional beg end) "Return t if entry is strictly between BEG and END (strings in YYYY-MM-DD format). If BEG is nil, there is no lower bound. If END is nil, there is no upper bound." (let ((date (agenda-entry-date-string entry "%Y-%m-%d"))) (and date (or (null beg) (string< beg date)) (or (null end) (string< date end))))) (defun agenda-entry-after-p (entry &optional date) "Return t if entry is on or after DATE (YYYY-MM-DD). If DATE is nil, defaults to today." (let ((after-date (or date (format-time-string "%Y-%m-%d"))) (entry-date (agenda-entry-date-string entry "%Y-%m-%d"))) (not (string< entry-date after-date)))) (defun agenda-entry-strictly-after-p (entry &optional date) "Return t if entry is strictly after DATE (YYYY-MM-DD). If DATE is nil, defaults to today." (let ((after-date (or date (format-time-string "%Y-%m-%d"))) (entry-date (agenda-entry-date-string entry "%Y-%m-%d"))) (string< after-date entry-date))) (defun agenda-entry-before-p (entry &optional date) "Return t if entry is on or before DATE (YYYY-MM-DD). If DATE is nil, defaults to today." (let ((before-date (or date (format-time-string "%Y-%m-%d"))) (entry-date (agenda-entry-date-string entry "%Y-%m-%d"))) (not (string< before-date entry-date)))) (defun agenda-entry-strictly-before-p (entry &optional date) "Return t if entry is strictly before DATE (YYYY-MM-DD). If DATE is nil, defaults to today." (let ((before-date (or date (format-time-string "%Y-%m-%d"))) (entry-date (agenda-entry-date-string entry "%Y-%m-%d"))) (string< entry-date before-date))) (defun agenda-entry-date-p (entry &optional date) "Return t if entry falls on DATE (YYYY-MM-DD). If DATE is nil, defaults to today." (string= (or date (format-time-string "%Y-%m-%d")) (agenda-entry-date-iso-string entry))) (defun agenda-entry-today-p (entry) "Return t if entry is today." (agenda-entry-date-p entry)) (defun agenda-entry-now-p (entry) "Return t if entry is now." (let ((time-start-hm (agenda-entry-time-start-string entry)) (time-end-hm (agenda-entry-time-end-string entry)) (now-hm (format-time-string "%H:%M")) (is-today (agenda-entry-today-p entry))) (and is-today time-start-hm (not (string< now-hm time-start-hm)) (or (not time-end-hm) (string< now-hm time-end-hm))))) (defun agenda-entry-cancel-p (entry) "Return t if entry has CANCEL in tags" (when-let ((tags (cdr (assoc 'tags entry)))) (member "CANCEL" tags))) (defun agenda-entry-deadline-p (entry) "Return t if entry has DEADLINE in tags" (when-let ((tags (cdr (assoc 'tags entry)))) (member "DEADLINE" tags))) (defun agenda-entry-active-deadline-p (entry) "Return t if entry has DEADLINE in tags" (when-let ((tags (cdr (assoc 'tags entry)))) (and (member "DEADLINE" tags) (not (member "DONE" tags))))) (defun agenda-entry-todo-p (entry) "Return t if entry has TODO in actions" (when-let ((actions (cdr (assoc 'actions entry)))) (member "DONE" actions))) (defun agenda-entry-done-p (entry) "Return t if entry has DONE in tags" (when-let ((tags (cdr (assoc 'tags entry)))) (member "DONE" tags))) (defun agenda-entry-birthday-p (entry &optional week day) "Return t if entry has BIRTHDAY in tags and week is WEEK and DAY." (when-let* ((date (agenda-entry-date-string entry)) (entry-date (cdr (assoc 'date entry))) (tags (cdr (assoc 'tags entry))) (week (or week (string-to-number (format-time-string "%V")))) (week (format "[wW]%02d" week))) (and (member "BIRTHDAY" tags) (or (not day) (eq day (nth 2 entry-date))) (string-match-p week date)))) (defvar-local agenda-source-buffer nil "Agenda source buffer") (defun agenda-source-buffer () "Return the agenda source buffer." (unless (and agenda-source-buffer (buffer-live-p agenda-source-buffer)) (unless (and agenda-file (file-exists-p agenda-file)) (error "Agenda file not found: %s. " agenda-file)) (setq agenda-source-buffer (find-file-noselect agenda-file))) agenda-source-buffer) (defvar-local agenda--entries-cache nil "Cache storage for entries as (TICK . ENTRIES).") (defun agenda-collect-entries (&optional force) "Retrieve all entries from the source buffer. If FORCE is non-nil, ignore the cache and re-scan." (with-current-buffer (agenda-source-buffer) (let ((current-tick (buffer-chars-modified-tick (agenda-source-buffer)))) (if (and (not force) agenda--entries-cache (eq (car agenda--entries-cache) current-tick)) (cdr agenda--entries-cache) (let ((entries nil)) (save-excursion (goto-char (point-min)) (while (re-search-forward agenda-entry-re nil t) (push (agenda-entry-from-match) entries))) (setq agenda--entries-cache (cons current-tick entries)) entries))))) (defun agenda-filter-entries (filter-fn &rest args) "Collect and return a sorted list of entries that satisfy FILTER-FN. FILTER-FN is called on each entry with supplementary ARGS." (let* ((filtered nil)) (dolist (entry (agenda-collect-entries)) (when (apply filter-fn entry args) (push entry filtered))) (sort filtered #'agenda-entry-less-p))) (defvar-local agenda--uids-cache nil "Cache storage for UIDs as (TICK . UIDS).") (defun agenda-collect-uids (&optional force) "Scan agenda buffer for all UIDs (entry or data lines). If FORCE is non-nil, ignore the cache and re-scan." (let ((current-tick (buffer-chars-modified-tick (agenda-source-buffer)))) (if (and (not force) agenda--uids-cache (eq (car agenda--uids-cache) current-tick)) (cdr agenda--uids-cache) (let (uids) (save-excursion ;; Entry lines (goto-char (point-min)) (while (re-search-forward agenda-entry-re nil t) (when-let ((uid-str (agenda-match 'uid))) (push (substring (car uid-str) 1 -1) uids))) ;; Data lines (goto-char (point-min)) (while (re-search-forward agenda-data-re nil t) (when-let ((uid-str (agenda-match 'data-uid))) (push (car uid-str) uids)))) (let ((result (delete-dups uids))) (setq agenda--uids-cache (cons current-tick result)) result))))) (defvar-local agenda--slots-cache nil "Cache storage for slots as (TICK . ((DATE . SLOTS) ...)).") (defun agenda-collect-slots (date &optional force) "Compute 30-minute slots for a given calendar DATE (month day year). If FORCE is non-nil, ignore the cache and re-scan." (let ((current-tick (buffer-chars-modified-tick (agenda-source-buffer)))) (unless (and (not force) agenda--slots-cache (eq (car agenda--slots-cache) current-tick)) (setq agenda--slots-cache (cons current-tick nil))) (let* ((date-cache (cdr agenda--slots-cache)) (cached-entry (assoc date date-cache))) (if cached-entry (cdr cached-entry) (let* ((date-iso (format "%04d-%02d-%02d" (nth 2 date) (nth 0 date) (nth 1 date))) (entries (agenda-filter-entries (lambda (entry date) (and (not (agenda-entry-cancel-p entry)) (agenda-entry-date-p entry date))) date-iso)) (slots (make-list 48 nil))) (dolist (entry entries) (let* ((start (cdr (assoc 'time-start entry))) (start-h (nth 0 start)) (start-m (nth 1 start)) (end (cdr (assoc 'time-end entry))) (end-h (cond (end (nth 0 end)) (start start-h))) (end-m (cond (end (nth 1 end)) (start (+ start-m 30))))) (when (and start-h start-m end-h end-m) (let* ((slot-start (/ (+ (* start-h 60) start-m) 30)) (slot-end (/ (+ (* end-h 60) end-m) 30))) (dotimes (i 48) (when (and (>= i slot-start) (< i slot-end)) (push entry (nth i slots)))))))) (setcdr agenda--slots-cache (cons (cons date slots) date-cache)) slots))))) (provide 'agenda-parse) ;;; agenda-parse.el ends here ================================================ FILE: agenda-utils.el ================================================ ;;; agenda-utils.el --- Utility functions -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;; Commentary: ;; This module provides various utility functions. ;;; Code: (defvar agenda--last-selected-date nil "Stores the last selected date (month day year).") (defmacro agenda-with-calendar-select (var &rest body) "Open calendar and bind the selected date to VAR, then execute BODY. When a date is selected, it is saved for next call." (declare (indent 1)) (let ((callback-sym (make-symbol "callback"))) `(let ((,callback-sym (lambda (,var) ,@body))) (calendar) (when agenda--last-selected-date (calendar-goto-date agenda--last-selected-date)) (let ((map (make-sparse-keymap))) (set-keymap-parent map calendar-mode-map) (define-key map (kbd "RET") `(lambda () (interactive) (let ((selected-date (calendar-cursor-to-date))) (setq agenda--last-selected-date selected-date) (calendar-exit) (funcall ,,callback-sym selected-date)))) (define-key map (kbd "C-g") (lambda () (interactive) (calendar-exit))) (use-local-map map))))) (defun agenda-date-forward (date &optional n unit) "Forward calendar DATE (month day year) by N UNIT. Supports negative N for moving backward." (let* ((n (or n 1)) (unit (or unit 'day)) (month (nth 0 date)) (day (nth 1 date)) (year (nth 2 date))) (pcase unit ((or 'day 'week) (let ((delta (if (eq unit 'week) (* n 7) n))) (calendar-gregorian-from-absolute (+ (calendar-absolute-from-gregorian date) delta)))) ((or 'month 'month-3) (let* ((total-months (+ month -1 (if (eq unit 'month-3) (* n 3) n))) (new-month (+ (mod total-months 12) 1)) (new-year (+ year (floor total-months 12))) (last-day (calendar-last-day-of-month new-month new-year)) (new-day (min day last-day))) (list new-month new-day new-year))) ('year (let* ((new-year (+ year n)) (last-day (calendar-last-day-of-month month new-year)) (new-day (min day last-day))) (list month new-day new-year))) (_ (error "Invalid unit: %s" unit))))) (defun agenda-url-button-string (text url) "Return TEXT as a clickable string that opens URL." (let ((map (make-sparse-keymap)) (callback (lambda (&optional _ignore) (interactive) (browse-url url)))) (define-key map [mouse-1] callback) (define-key map [mouse-2] callback) (define-key map (kbd "RET") callback) (propertize text 'face 'agenda-view-button 'font-lock-face 'agenda-view-button 'mouse-face 'highlight 'help-echo (concat "Go to " (propertize url 'face 'agenda-view-button)) 'follow-link t 'keymap map))) (provide 'agenda-utils) ;;; agenda-utils.el ends here ================================================ FILE: agenda-view-day.el ================================================ ;;; agenda-view-day.el --- Daily view -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'cal-iso) (require 'agenda-parse) (require 'agenda-faces) (defun agenda-view-day--display-title (date) "Return DATE string." (let* ((ts (encode-time (list 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date))))) (propertize (format-time-string "%A, %d %B %Y" ts) 'face 'agenda-view-title))) (defun agenda-view-day--display-date (date) "Return DATE string for day header." (let* ((today-iso (format-time-string "%Y-%m-%d")) (date-ts (encode-time (list 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) (date-iso (format-time-string "%Y-%m-%d" date-ts)) (date-str (format-time-string "%A %d %B %Y" date-ts))) (concat (propertize date-str 'face 'agenda-view-date) (if (string= date-iso today-iso) (propertize " (today)\n\n" 'face 'agenda-view-date-today) "\n\n")))) (defun agenda-view-day--display-entry (entry &optional time-str) "Return ENTRY string, optionally with time replaced by TIME-STR." (let* ((today-iso (format-time-string "%Y-%m-%d")) (date-iso (agenda-entry-date-string entry "%Y-%m-%d")) (time-start-hm (agenda-entry-time-start-string entry)) (time-end-hm (agenda-entry-time-end-string entry)) (data (cdr (assoc 'data entry))) (url (cdr (assoc 'url data))) (title (cdr (assoc 'title entry))) (title (if url (agenda-url-button-string title url) title)) (actions (agenda-entry-actions-string entry)) (tags (agenda-entry-tags-string entry)) (marker (cdr (assoc 'marker entry))) (line-face (if (agenda-entry-cancel-p entry) 'agenda-view-cancel nil)) (time-face (cond ((agenda-entry-now-p entry) 'agenda-view-time-now) ((agenda-entry-today-p entry) 'agenda-view-time-today) (t 'default))) (time-str (if time-str (format " %11s " time-str) (propertize (cond ((and time-start-hm time-end-hm) (format " %s-%s " time-start-hm time-end-hm)) (time-start-hm (format " %s " time-start-hm)) (t " ----------- ")) 'face (or time-face line-face))))) (propertize (concat " " time-str " " title (when actions (concat " " (propertize actions 'face (or line-face 'agenda-edit-action)))) (when tags (concat " " (propertize tags 'face (or line-face 'agenda-edit-tag)))) "") 'agenda-entry-marker marker))) (defun agenda-view-day-display (&optional date force) "Display the agenda for DATE. When FORCE is t, force update." (let* ((date (or date agenda-view-date)) (year (or (nth 2 date) (string-to-number (format-time-string "%Y")))) (month (or (nth 0 date) (string-to-number (format-time-string "%m")))) (day (or (nth 1 date) (string-to-number (format-time-string "%d")))) (date (list month day year)) (date-str (format "%4d-%02d-%02d" year month day)) (ts (encode-time (list 0 0 0 day month year))) (week (string-to-number (format-time-string "%V" ts))) (today (format-time-string "%Y-%m-%d")) (now (format-time-string "%H:%M")) ;; Entries (filtered by week/year) (entries (agenda-filter-entries (lambda (entry date) (and (not (agenda-entry-cancel-p entry)) (agenda-entry-date-p entry date))) date-str)) ;; Birthdays (filtered by week and post-processed) (birthdays (agenda-filter-entries (lambda (entry week year) (and (not (agenda-entry-cancel-p entry)) (agenda-entry-birthday-p entry week (nth 1 date)))) week year)) (birthdays (agenda-view--process-birthdays birthdays year)) ;; Deadlines (future only) (deadlines (agenda-filter-entries (lambda (entry week year) (and (not (agenda-entry-cancel-p entry)) (not (agenda-entry-done-p entry)) (agenda-entry-deadline-p entry))) week year)) (entries (sort (append entries birthdays) #'agenda-entry-less-p))) ;; Calendar (save-excursion (insert (agenda-view-calendar date t))) (agenda-view--next-line 1 24) (insert " " (agenda-view-day--display-title date)) (agenda-view--next-line 2 24) ;; Entries and birthdays (if entries (dolist (entry entries) (let ((date (cdr (assoc 'date entry)))) (insert (agenda-view-day--display-entry entry)) (agenda-view--next-line 1 24))) (progn (insert (propertize " No event found." 'face 'shadow)) (agenda-view--next-line 1 24))) ;; Future deadlines (when (> (length deadlines) 0) (agenda-view--next-line 1 24) (insert (propertize " Upcoming deadlines" 'face 'agenda-view-date)) (agenda-view--next-line 2 24) (dolist (entry deadlines) (let* ((date (cdr (assoc 'date entry))) (time (encode-time (list 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) (days (- (time-to-days time) (time-to-days (current-time)))) (face (agenda-view--deadline-face days)) (time-str (propertize (format "In %2d days " days) 'face face))) (when (<= days 21) (insert (agenda-view-day--display-entry entry time-str)) (agenda-view--next-line 1 24))))) ;; Move point to relevant place on mini-calendar (goto-char (point-min)) (when-let ((prop (text-property-search-forward 'agenda-date-marker date #'equal))) (goto-char (prop-match-beginning prop))))) (provide 'agenda-view-day) ;;; agenda-view-day.el ends here ================================================ FILE: agenda-view-month.el ================================================ ;;; agenda-view-month.el --- Monthly view -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'calendar) (require 'agenda-parse) (require 'agenda-faces) (defun agenda-view-month--display-week (date &optional no-newline show-week) "Return DATE literal string, prefixed by a newline for Mondays, unless NO-NEWLINE is t. Week number is shown for Mondays or when SHOW-WEEK it t." (let* ((ts (encode-time (list 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) (weekday (nth 6 (decode-time ts))) (is-monday (eq weekday 1)) (is-weekend (memq weekday '(0 6))) (line-prefix (if (and is-monday (not no-newline)) "\n" "")) (week-prefix (format-time-string "Week %V, %a, %d %b %Y " ts)) (date-prefix (format-time-string " %a, %d %b %Y " ts)) (week-prefix (format-time-string "%a %d " ts)) (date-prefix (format-time-string "%a %d " ts)) (face (cond (is-weekend 'shadow) (is-monday 'bold) (t 'shadow)))) (propertize (concat line-prefix (if (or is-monday show-week) week-prefix date-prefix)) 'font-lock-face face 'face face))) (defun agenda-view-month--display-entry (entry) "Return a display string for ENTRY." (let ((time (agenda-entry-time-string entry)) (title (agenda-entry-title-string entry)) (actions (agenda-entry-actions-string entry)) (tags (agenda-entry-tags-string entry))) (concat (when time (concat (propertize time 'face 'bold) " ")) title " " actions " " tags))) (defun agenda-view-month--slot-face (entries) "Return face for entries (=slot)." (let* ((entry (car entries)) (inweek (when entry (agenda-entry-inweek-p entry))) (face (cond (inweek 'agenda-slot-busy-inweek) (entries 'agenda-slot-busy) (t 'agenda-slot-free)))) (catch 'found (dolist (slot agenda-slot-faces) (let* ((slot-key (car slot)) (slot-face (cdr slot))) (dolist (entry entries) (let ((tags (agenda-entry-tags-string entry))) (when (and (stringp tags) (string-match-p slot-key tags)) (setq face slot-face) (throw 'found face))))))) face)) (defun agenda-view-month--display-slot (entries &optional date) "Return a one char string for SLOT." (let* ((first (car entries)) (count (length entries)) (is-deadline (seq-some #'agenda-entry-deadline-p entries)) (marker (when first (cdr (assoc 'marker first)))) (help (when entries (mapconcat #'agenda-view-month--display-entry entries "\n"))) (face (agenda-view-month--slot-face entries)) (char (cond (is-deadline (agenda-mark 'deadline)) ((> count 1) (agenda-mark 'conflict)) (t " ")))) (propertize char 'face face 'agenda-date-marker date 'agenda-entry-marker marker 'help-echo help))) (defun agenda-view-month--display-summary (slots) "Given a list of slots, return a single line summary of entries." (let ((summaries) (entries (nreverse (seq-uniq (seq-mapcat #'identity slots))))) (dolist (entry entries) (let* ((time (cdr (assoc 'time-start entry))) (title (cdr (assoc 'title entry))) (inweek (agenda-entry-inweek-p entry)) (now (agenda-entry-now-p entry)) (title-face (if inweek 'default 'shadow)) (time-face (cond (now '(:inverse-video t :inherit bold)) (inweek 'bold) (t '(bold shadow)))) (data (cdr (assoc 'data entry))) (url (cdr (assoc 'url data))) (title (if (and inweek url) (agenda-url-button-string title url) (propertize title 'face title-face))) (marker (cdr (assoc 'marker entry))) (summary (if time (concat (propertize (format (if now " %02d:%02d " "%02d:%02d") (nth 0 time) (nth 1 time)) 'face time-face) " " title) (format "%s" title))) (summary (propertize summary 'agenda-entry-marker marker))) (push summary summaries))) (mapconcat #'identity summaries (propertize " " 'face 'shadow)))) (defun agenda-view-month--display-slots (date &optional hour-start hour-end with-summary) "Return slots string for calendar DATE (month day year) between HOUR-START and HOUR-END. When WITH-SUMMRAY is t, append a summary with all entries." (let* ((slots (agenda-collect-slots date)) (slots-str "") (hour-start (or hour-start 8)) (hour-start (min (max hour-start 0) 23)) (hour-end (or hour-end 18)) (hour-end (min (max (1+ hour-start) hour-end) 24)) (index-start (* hour-start 2)) (index-max (* hour-end 2)) (index index-start)) (while (<= index index-max) (setq slots-str (concat slots-str (agenda-view-month--display-slot (nth index slots) date) (agenda-view-month--display-slot (nth (1+ index) slots) date))) (setq index (+ index 2))) (concat slots-str (when with-summary (concat " " (agenda-view-month--display-summary slots)))))) (defun agenda-view-month--display-clock (&optional hour-start hour-end) "Return time string for calendar DATE (month day year) between HOUR-START and HOUR-END." (let* ((time "") (hour-start (or hour-start 8)) (hour-end (or hour-end 18)) (hour-start (min (max hour-start 0) 23)) (hour-end (min (max (1+ hour-start) hour-end) 24)) (index-start (* hour-start 2)) (index-max (* hour-end 2)) (index index-start)) (while (<= index index-max) (setq time (concat time (if (eq (% (- index index-start) 4) 0) (propertize (concat (format "%02d" (/ index 2))) 'face 'shadow) " "))) (setq index (+ index 2))) time)) (defun agenda-view-month--display (month year column &optional hour-start hour-end with-summary) "" (let* ((year (or year (string-to-number (format-time-string "%Y")))) (month (or month (string-to-number (format-time-string "%m")))) (today (calendar-current-date)) (day (list month 1 year)) (day (calendar-absolute-from-gregorian day)) (day-last (list month (calendar-last-day-of-month month year) year)) (day-last (calendar-absolute-from-gregorian day-last)) (dates (let ((dates)) (while (<= day day-last) (push (calendar-gregorian-from-absolute day) dates) (setq day (1+ day))) (nreverse dates)))) (dolist (date dates) (let* ((ts (encode-time (list 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))) (weekday (nth 6 (decode-time ts))) (is-today (equal date today)) (is-inweek (string= (format-time-string "%G-%V" ts) (format-time-string "%G-%V"))) (is-monday (eq weekday 1)) (is-weekend (memq weekday '(0 6))) (is-first (eq date (car dates)))) ;; Month header (when is-first (agenda-view--next-line 1 column) (insert " " (propertize (format " %s " (format-time-string "%B %Y" ts)) 'agena-hl-range t 'face 'bold) " ") (agenda-view--next-line 1 column)) ;; Time header (when (or is-monday is-first) (agenda-view--next-line 1 column) (insert (propertize (format-time-string "Week %V " ts) 'agenda-hl-range t 'face (cond (is-inweek 'bold) (t '(bold shadow)))) " " (propertize (agenda-view-month--display-clock hour-start hour-end) ;; 'agenda-hl-range t 'face (cond (is-inweek 'default) (t 'shadow))) " ") (agenda-view--next-line 1 column)) ;; Day slots (insert (propertize (format-time-string " %a %d " ts) 'agenda-hl-range t 'agenda-date-marker date 'face (cond (is-today '(:inverse-video t :inherit bold)) (is-inweek 'default) ;; (is-monday 'shadow) ;; (is-weekend 'shadow) (t 'shadow))) " " (agenda-view-month--display-slots date hour-start hour-end with-summary) " ") (agenda-view--next-line 1 column))))) (defun agenda-view-month-1-display (&optional date force) "Display month agenda for DATE with summary next to each day. When FORCE is t, force update." (interactive) (let* ((date (or date agenda-view-date)) (month (nth 0 date)) (year (nth 2 date)) (hour-start 8) (hour-end 18) (month-col-size (+ 7 ;; Date prefix (* (- hour-end hour-start -1) 2) ;; Slots 5)) ;; Spacing between months (month (or month (car agenda-view-month-date) (string-to-number (format-time-string "%m")))) (year (or year (cdr agenda-view-month-date) (string-to-number (format-time-string "%Y")))) (buffer (get-buffer-create agenda-view-buffer))) (save-excursion (agenda-view-month--display month year (* 0 month-col-size) hour-start hour-end t)) (goto-char (point-min)) (when-let ((prop (text-property-search-forward 'agenda-date-marker date #'equal))) (goto-char (prop-match-beginning prop))))) (defun agenda-view-month-3-display (&optional date force) "Display 3 months agenda for DATE. When FORCE is t, force update." (interactive) (let* ((date (or date agenda-view-date)) (month (nth 0 date)) (year (nth 2 date)) (hour-start 8) (hour-end 18) (month-col-size (+ 7 ;; Date prefix (* (- hour-end hour-start -1) 2) ;; Slots 5))) ;; Spacing between months (dolist (index '(0 1 2)) (save-excursion (agenda-view-month--display month year (* index month-col-size) hour-start hour-end) (calendar-increment-month month year 1))) (goto-char (point-min)) (when-let ((prop (text-property-search-forward 'agenda-date-marker date #'equal))) (goto-char (prop-match-beginning prop))))) (provide 'agenda-view-month) ;;; agenda-view-month.el ends here ================================================ FILE: agenda-view-week.el ================================================ ;;; agenda-view-week.el --- Weekly view -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'cal-iso) (require 'agenda-parse) (require 'agenda-faces) (defun agenda-view-week-extent (&optional week year) "Return timestamp for first & last days of WEEK YEAR." (let* ((year (or year (string-to-number (format-time-string "%Y")))) (year (or year (string-to-number (format-time-string "%V")))) (abs-mon (calendar-iso-to-absolute (list week 1 year))) (mon-greg (calendar-gregorian-from-absolute abs-mon)) (sun-greg (calendar-gregorian-from-absolute (+ abs-mon 6)))) (cons (encode-time 0 0 0 (nth 1 mon-greg) (nth 0 mon-greg) (nth 2 mon-greg)) (encode-time 0 0 0 (nth 1 sun-greg) (nth 0 sun-greg) (nth 2 sun-greg))))) (defun agenda-view-week--display-title (week year) "Return WEEK / YEAR string." (let* ((week-extent (agenda-view-week-extent week year)) (week-start (format-time-string "%d %B %Y" (car week-extent))) (week-end (format-time-string "%d %B %Y" (cdr week-extent)))) (propertize (format "Year %s, week %02d\n" year week) 'face 'agenda-view-title))) (defun agenda-view-week--display-subtitle (week year) "Return WEEK / YEAR extend string." (let* ((week-extent (agenda-view-week-extent week year)) (week-start (format-time-string "%d %B %Y" (car week-extent))) (week-end (format-time-string "%d %B %Y" (cdr week-extent)))) (propertize (format "%s - %s\n" week-start week-end) 'face 'agenda-view-subtitle))) (defun agenda-view-week--display-date (date) "Return DATE string for day header." (let* ((today-iso (format-time-string "%Y-%m-%d")) (date-ts (encode-time (list 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) (date-iso (format-time-string "%Y-%m-%d" date-ts)) (date-str (format-time-string "%A %d %B %Y" date-ts))) (concat (propertize date-str 'agenda-hl-range t 'face 'agenda-view-date ) (if (string= date-iso today-iso) (propertize " (today)\n\n" 'face 'agenda-view-date-today) "\n\n")))) (defun agenda-view-week--display-entry (entry &optional time-str) "Return ENTRY string, optionally with time replaced by TIME-STR." (let* ((today-iso (format-time-string "%Y-%m-%d")) (date-iso (agenda-entry-date-string entry "%Y-%m-%d")) (time-start-hm (agenda-entry-time-start-string entry)) (time-end-hm (agenda-entry-time-end-string entry)) (data (cdr (assoc 'data entry))) (url (cdr (assoc 'url data))) (title (cdr (assoc 'title entry))) (title (if url (agenda-url-button-string title url) title)) (actions (agenda-entry-actions-string entry)) (tags (agenda-entry-tags-string entry)) (marker (cdr (assoc 'marker entry))) (line-face (if (agenda-entry-cancel-p entry) 'agenda-view-cancel nil)) (time-face (cond ((agenda-entry-now-p entry) 'agenda-view-time-now) ((agenda-entry-today-p entry) 'agenda-view-time-today))) (time-str (if time-str (format " %11s " time-str) (propertize (cond ((and time-start-hm time-end-hm) (format " %s-%s " time-start-hm time-end-hm)) (time-start-hm (format " %s " time-start-hm)) (t " ----------- ")) 'agenda-hl-range t 'face (or time-face line-face))))) (propertize (concat " " time-str " " title (when actions (concat " " (propertize actions 'face (or line-face 'agenda-edit-action)))) (when tags (concat " " (propertize tags 'face (or line-face 'agenda-edit-tag)))) "\n") 'agenda-entry-marker marker))) (defun agenda-view-week-display (&optional date force) "Display the agenda for DATE. When FORCE is t, force update" (interactive) (let* ((date (or date agenda-view-date)) (month (nth 0 date)) (day (nth 1 date)) (year (nth 2 date)) (week (car (calendar-iso-from-absolute (calendar-absolute-from-gregorian date)))) (today (format-time-string "%Y-%m-%d")) (now (format-time-string "%H:%M")) (point-first nil) (point-date nil) (buffer (get-buffer-create agenda-view-buffer)) ;; Entries (filtered by week/year) (entries (agenda-filter-entries (lambda (entry week year) (and (not (agenda-entry-cancel-p entry)) (agenda-entry-inweek-p entry week year))) week year)) ;; Birthdays (filtered by week and post-processed) (birthdays (agenda-filter-entries (lambda (entry week year) (and (not (agenda-entry-cancel-p entry)) (agenda-entry-birthday-p entry week))) week year)) (birthdays (agenda-view--process-birthdays birthdays year)) ;; Deadlines (future only) (deadlines (agenda-filter-entries (lambda (entry week year) (and (not (agenda-entry-cancel-p entry)) (not (agenda-entry-done-p entry)) (agenda-entry-deadline-p entry))) week year)) (entries (sort (append entries birthdays) #'agenda-entry-less-p))) (insert (agenda-view-week--display-title week year) (agenda-view-week--display-subtitle week year)) ;; Entries and birthdays (let ((current-date nil)) (dolist (entry entries) (let* ((entry-date (cdr (assoc 'date entry))) (cal-date (list (nth 1 entry-date) (nth 2 entry-date) (nth 0 entry-date)))) (unless (equal entry-date current-date) (insert "\n" (agenda-view-week--display-date entry-date)) (setq current-date entry-date)) (when (and (not point-date) (equal cal-date date)) (setq point-date (line-beginning-position))) (unless point-first (setq point-first (line-beginning-position))) (insert (propertize (agenda-view-week--display-entry entry) 'agenda-date-marker cal-date))))) ;; Future deadlines (when (> (length deadlines) 0) (insert (propertize "\nUpcoming deadlines\n\n" 'face 'agenda-view-date)) (dolist (entry deadlines) (let* ((date (cdr (assoc 'date entry))) (time (encode-time (list 0 0 0 (nth 2 date) (nth 1 date) (nth 0 date)))) (days (- (time-to-days time) (time-to-days (current-time)))) (face (agenda-view--deadline-face days)) (time-str (propertize (format " In %2d days " days) 'agenda-hl-range t 'face face))) (when (<= days 30) (insert (propertize (agenda-view-week--display-entry entry time-str) 'agenda-date-marker date)))))) (goto-char (or point-date point-first (point-min))))) (provide 'agenda-view-week) ;;; agenda-view-week.el ends here ================================================ FILE: agenda-view-year.el ================================================ ;;; agenda-view-year.el --- Yearly view -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'cal-iso) (require 'agenda-parse) (require 'agenda-faces) (defvar agenda-view-year--layout '(3 . 4) "Year view calendar layout as (ROWS . COLS).") (defun agenda-view-year-display (&optional date force layout) "Display a grid of months for YEAR based on LAYOUT (rows . cols). Default LAYOUT is (3 . 4). Each month is 24 columns wide and 10 rows high." (let* ((date (or date agenda-view-date)) (year (nth 2 date)) (month (nth 0 date)) (day (nth 1 date)) (layout (or layout '(3 . 4))) (rows (car layout)) (cols (cdr layout))) (setq agenda-view-year--layout layout) (dotimes (row rows) (let ((months nil)) (dotimes (col cols) (let* ((month-index (+ 1 (* row cols) col)) (month-string (agenda-view-calendar (list month-index day year) (eq month-index month) force))) (push (split-string month-string "\n" t) months))) (setq months (nreverse months)) (dotimes (line 10) (dolist (month-lines months) (insert (nth line month-lines) " ")) (insert "\n")))) (goto-char (point-min)) (when-let ((prop (text-property-search-forward 'agenda-date-marker date #'equal))) (goto-char (prop-match-beginning prop))))) (defun agenda-view-year-display-auto (&optional date force) "Calculate the best (rows . cols) layout based on window width." (let* ((width (window-width)) ;; Each month is 24 chars + 1 char space = 25 (max-cols (max 1 (/ width 25))) (cols (cond ((>= max-cols 12) 12) ((>= max-cols 6) 6) ((>= max-cols 4) 4) ((>= max-cols 3) 3) ((>= max-cols 2) 2) (t 1))) (rows (/ 12 cols)) (layout (cons rows cols))) (agenda-view-year-display date force layout))) (provide 'agenda-view-year) ;;; agenda-view-year.el ends here ================================================ FILE: agenda-view.el ================================================ ;;; agenda-view.el --- Agenda view -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Code: (require 'agenda-parse) (require 'agenda-faces) (require 'agenda-utils) (require 'agenda-view-day) (require 'agenda-view-week) (require 'agenda-view-month) (require 'agenda-view-year) (defvar agenda-view-date nil "Date currently displayed.") (defvar agenda-view-unit 'day "Unit view (day, week, month, month-3 or year.") (defun agenda-view--process-birthdays (entries year &optional month) "Return a new list of ENTRIES with updated date and title related tp YEAR and MONTH." (mapcar (lambda (entry) (let* ((birth-date (cdr (assoc 'date entry))) (birth-year (car birth-date)) (age (- year birth-year)) (new-date (list year (nth 1 birth-date) (nth 2 birth-date))) (old-title (cdr (assoc 'title entry))) (new-title (concat (agenda-mark 'birthday) " " (format old-title age))) (new-entry (assq-delete-all 'date (assq-delete-all 'title (copy-sequence entry))))) (cons (cons 'date new-date) (cons (cons 'title new-title) new-entry)))) entries)) (defun agenda-view--deadline-face (days) "Return face for deadline (=slot)." (let ((face 'default)) (catch 'found (dolist (deadline agenda-deadline-faces) (let* ((deadline-days (car deadline)) (deadline-face (cdr deadline))) (unless (< deadline-days days) (setq face deadline-face) (throw 'found face))))) face)) (defun agenda-view--next-line (&optional n column) "Move point forward ? line at specified column." (dotimes (i (or n 1)) (if (eobp) (newline) (forward-line 1))) (move-to-column (or column 24) t)) (defun agenda-view--display-summary (slots) "Given a list of slots, return a single line summary of entries." (let ((summaries) (entries (nreverse (seq-uniq (seq-mapcat #'identity slots))))) (dolist (entry entries) (let* ((time (cdr (assoc 'time-start entry))) (title (cdr (assoc 'title entry))) (data (cdr (assoc 'data entry))) (summary (if time (concat (propertize (format "%02d:%02d" (nth 0 time) (nth 1 time)) 'face 'bold) " " title) title))) (push summary summaries))) (mapconcat #'identity summaries " "))) (defvar agenda-view--calendar-cache (make-hash-table :test 'equal) "Cache for agenda calendar strings. Key is (month year active).") (defun agenda-view-calendar (date &optional active force) "Generate a calendar representation for DATE (month day year). Uses a cache based on month, year, and ACTIVE status unless FORCE is non-nil." (let* ((month (nth 0 date)) (day (nth 1 date)) (year (nth 2 date)) (cache-key (list month year active)) (cache-val (gethash cache-key agenda-view--calendar-cache))) (if (and (not force) cache-val) cache-val (let* ((first (list month 1 year)) (first-day (calendar-absolute-from-gregorian first)) (first-mon (- first-day (mod (+ (calendar-day-of-week first) 6) 7))) (header (format "%s %d" (calendar-month-name month) year)) (spaces (- 20 (length header))) (face (if (not active) 'shadow nil)) (calendar nil)) (push (concat (propertize (concat (make-string (/ spaces 2) ?\s) header (make-string (- spaces (/ spaces 2)) ?\s)) 'face `(:inverse-video t :inherit (,face bold))) " ") calendar) (push (concat (propertize "Mo Tu We Th Fr " 'face `(bold ,face)) (propertize "Sa Su "'face face)) calendar) (dotimes (i 6) (let ((line "")) (dotimes (j 7) (let* ((index (+ (* i 7) j)) (day-date (calendar-gregorian-from-absolute (+ first-mon index))) (is-today (and (eq (nth 1 day-date) day) (eq (nth 0 day-date) month))) (is-month (eq (nth 0 day-date) month)) (is-weekend (memq (calendar-day-of-week day-date) '(0 6))) (slots (agenda-collect-slots day-date)) (entries (seq-find #'identity slots)) (has-deadline (seq-some (lambda (entry) (member "DEADLINE" (cdr (assoc 'tags entry)))) entries)) ;; FIXME: Does that work a slot has several entries? (first-entry (car entries)) (marker (cdr (assoc 'marker first-entry))) (help (agenda-view--display-summary slots)) (total (/ (seq-count #'identity slots) 2)) (palette agenda-calendar-palette) (total (min total (length palette))) (face (cond ;; ((and is-month has-deadline) ;; '(:background "#FFFF00" :foreground "#000000")) ((and is-month (> total 0)) `( :inherit ,(if has-deadline 'bold 'default) :foreground ,(car (nth total palette)) :background ,(cdr (nth total palette)))) ((and is-month is-weekend) '(:inherit shadow)))) (day (if is-month (if has-deadline (format "%2d%s" (nth 1 day-date) (agenda-mark 'deadline)) (format "%2d " (nth 1 day-date))) " "))) (setq line (concat line (propertize day 'agenda-entry-marker marker 'agenda-date-marker (when is-month day-date) 'help-echo help 'face face))))) (push line calendar))) (let ((result (concat (propertize "┌──────────────────────┐\n" 'face face) (mapconcat (lambda (line) (concat (propertize "│ " 'face face) line (propertize "│" 'face face))) (reverse calendar) "\n") (propertize "\n└──────────────────────┘\n" 'face face)))) (puthash cache-key result agenda-view--calendar-cache) result))))) (defun agenda-view-refresh () "Refresh the current view with forced update." (interactive) (agenda-view nil nil t)) (defun agenda-view-goto-today () "Jump to the current week." (interactive) (agenda-view (calendar-current-date))) (defun agenda-view-goto-date () "Select a date via calendar and open the view for that week." (interactive) (agenda-with-calendar-select date (agenda-view date))) (defun agenda-view-goto-next () "Go to the next week." (interactive) (let ((date (agenda-date-forward agenda-view-date +1 agenda-view-unit))) (agenda-view date))) (defun agenda-view-goto-prev () "Go to the next week." (interactive) (let ((date (agenda-date-forward agenda-view-date -1 agenda-view-unit))) (agenda-view date))) (defun agenda-view-goto-date-at-point () "Select a date via calendar and open the view for that week." (interactive) (when-let* ((date (get-text-property (point) 'agenda-date-marker))) (agenda-view date))) (defun agenda-view-goto-up () (interactive) (if-let* ((date (get-text-property (point) 'agenda-date-marker))) (cond ((memq agenda-view-unit '(day year)) (agenda-view (agenda-date-forward date -7 'day))) ((memq agenda-view-unit '(month month-3)) (when-let* ((date-prev (agenda-date-forward date -1 'day)) (prop (save-excursion (goto-char (point-min)) (text-property-search-forward 'agenda-date-marker date-prev t)))) (goto-char (prop-match-beginning prop)))) ((memq agenda-view-unit '(week)) (when-let* ((prop (save-excursion (text-property-search-backward 'agenda-date-marker)))) (goto-char (prop-match-beginning prop)))) (t (call-interactively #'previous-line))) (call-interactively #'previous-line))) (defun agenda-view-goto-down () (interactive) (if-let* ((date (get-text-property (point) 'agenda-date-marker))) (cond ((memq agenda-view-unit '(day year)) (agenda-view (agenda-date-forward date +7 'day))) ((memq agenda-view-unit '(month month-3)) (when-let* ((date-prev (agenda-date-forward date +1 'day)) (prop (save-excursion (goto-char (point-min)) (text-property-search-forward 'agenda-date-marker date-prev t)))) (goto-char (prop-match-beginning prop)))) ((memq agenda-view-unit '(week)) (when-let* ((prop (save-excursion (text-property-search-forward 'agenda-date-marker nil nil t)))) (goto-char (prop-match-beginning prop)))) (t (call-interactively #'next-line))) (call-interactively #'next-line))) (defun agenda-view-goto-left () (interactive) (if-let* ((date (get-text-property (point) 'agenda-date-marker))) (cond ((memq agenda-view-unit '(day year)) (agenda-view (agenda-date-forward date -1 'day))) ((memq agenda-view-unit '(month month-3)) (if-let* ((date-prev (agenda-date-forward date -1 'month)) (prop (save-excursion (goto-char (point-min)) (text-property-search-forward 'agenda-date-marker date-prev t)))) (goto-char (prop-match-beginning prop)) (call-interactively #'left-char))) (t (call-interactively #'left-char))) (call-interactively #'left-char))) (defun agenda-view-goto-right () (interactive) (if-let* ((date (get-text-property (point) 'agenda-date-marker))) (cond ((memq agenda-view-unit '(day year)) (agenda-view (agenda-date-forward date +1 'day))) ((memq agenda-view-unit '(month month-3)) (if-let* ((date-prev (agenda-date-forward date +1 'month)) (prop (save-excursion (goto-char (point-min)) (text-property-search-forward 'agenda-date-marker date-prev t)))) (goto-char (prop-match-beginning prop)) (call-interactively #'right-char))) (t (call-interactively #'right-char))) (call-interactively #'right-char))) (defun agenda-view-goto-shift-left () (interactive) (if-let* ((date (and (memq agenda-view-unit '(day year month)) agenda-view-date))) (agenda-view (agenda-date-forward date -1 'month)) (call-interactively #'left-char))) (defun agenda-view-goto-shift-right () (interactive) (if-let* ((date (and (memq agenda-view-unit '(day year month)) agenda-view-date))) (agenda-view (agenda-date-forward date +1 'month)) (call-interactively #'right-char))) (defun agenda-view-goto-shift-up () (interactive) (if-let* ((date (and (memq agenda-view-unit '(year)) agenda-view-date))) (agenda-view (agenda-date-forward date (- (cdr agenda-view-year--layout)) 'month)) (call-interactively #'previous-line))) (defun agenda-view-goto-shift-down () (interactive) (if-let* ((date (and (memq agenda-view-unit '(year)) agenda-view-date))) (agenda-view (agenda-date-forward date (cdr agenda-view-year--layout) 'month)) (call-interactively #'next-line))) (defun agenda-view-goto-entry () "Jump to the source line of the entry at point or to the closest date if no entry at point. When in year mode, switch to week mode instead." (interactive) (let* ((marker (get-text-property (point) 'agenda-entry-marker)) (date (get-text-property (point) 'agenda-date-marker))) (cond ((eq agenda-view-unit 'year) (agenda-view-week)) (marker (pop-to-buffer (marker-buffer marker)) (agenda-filter "") (goto-char (marker-position marker)) (agenda-highlight (line-beginning-position) (line-end-position)) (recenter)) (date (pop-to-buffer (agenda-source-buffer)) (agenda-filter "") (remove-text-properties (point-min) (point-max) '(invisible nil)) (agenda--goto-date date) (agenda-highlight (line-beginning-position) (line-end-position)) (recenter))))) (defun agenda-view-day (&optional date force) "Display the agenda for DATE in day mode. When FORCE is t, force update from source." (interactive) (agenda-view date 'day force)) (defun agenda-view-week (&optional date force) "Display the agenda for DATE in week mode. When FORCE is t, force update from source." (interactive) (agenda-view date 'week force)) (defun agenda-view-month-1 (&optional date force) "Display the agenda for DATE in month mode. When FORCE is t, force update from source." (interactive) (agenda-view date 'month force)) (defun agenda-view-month-3 (&optional date force) "Display the agenda for DATE in 3 months mode. When FORCE is t, force update from source." (interactive) (agenda-view date 'month-3 force)) (defun agenda-view-year (&optional date force) "Display the agenda for DATE in year mode. When FORCE is t, force update from source." (interactive) (agenda-view date 'year force)) (defun agenda-view-capture (&optional with-data) "Capture a new entry using date at point (if any)." (interactive "P") (when-let ((date (or (get-text-property (point) 'agenda-date-marker) (agenda-view-date) (calendar-current-date)))) (agenda-capture date with-data))) (defun agenda-view (&optional date unit force) "Display the agenda for DATE in UNIT mode. When FORCE is t, force update from source." (interactive) (let* ((buffer (get-buffer-create agenda-view-buffer)) (date (or date agenda-view-date (calendar-current-date))) (unit (or unit agenda-view-unit 'day))) (setq agenda-view-date date) (setq agenda-view-unit unit) (if (memq agenda-view-unit '(week month month-3)) (hl-line-mode 1) (hl-line-mode -1)) (setq-local hl-line-range-function #'agenda-view--hl-line-range) (with-current-buffer buffer (let ((inhibit-read-only t)) (erase-buffer) (cond ((eq unit 'day) (agenda-view-day-display nil force)) ((eq unit 'week) (agenda-view-week-display nil force)) ((eq unit 'month) (agenda-view-month-1-display nil force)) ((eq unit 'month-3) (agenda-view-month-3-display nil force)) ((eq unit 'year) (agenda-view-year-display-auto nil force)) (t (error (format "Unknown view mode (%s)" unit)))) (set-buffer-modified-p nil) (unless (derived-mode-p 'agenda-view-mode) (agenda-view-mode)) (setq mode-name (concat "Agenda View: " (cond ((eq agenda-view-unit 'day) "Day") ((eq agenda-view-unit 'week) "Week") ((eq agenda-view-unit 'month) "Month") ((eq agenda-view-unit 'month-3) "3 Months") ((eq agenda-view-unit 'year) "Year")))) (pop-to-buffer buffer))))) (defvar agenda-view-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "RET") #'agenda-view-goto-entry) (define-key map (kbd "TAB") #'agenda-view-goto-entry) (define-key map (kbd "") #'agenda-view-goto-date-at-point) (define-key map (kbd "c") #'agenda-view-capture) (define-key map (kbd "r") #'agenda-view-refresh) (define-key map (kbd "C-l") #'agenda-view-refresh) (define-key map (kbd "e") #'agenda-export) (define-key map (kbd "d") #'agenda-view-day) (define-key map (kbd "w") #'agenda-view-week) (define-key map (kbd "m") #'agenda-view-month-1) (define-key map (kbd "t") #'agenda-view-month-3) (define-key map (kbd "y") #'agenda-view-year) (define-key map (kbd "g") #'agenda-view-goto-date) (define-key map (kbd ".") #'agenda-view-goto-today) (define-key map (kbd "") #'agenda-view-goto-left) (define-key map (kbd "") #'agenda-view-goto-right) (define-key map (kbd "") #'agenda-view-goto-up) (define-key map (kbd "") #'agenda-view-goto-down) (define-key map (kbd "S-") #'agenda-view-goto-shift-left) (define-key map (kbd "S-") #'agenda-view-goto-shift-right) (define-key map (kbd "S-") #'agenda-view-goto-shift-up) (define-key map (kbd "S-") #'agenda-view-goto-shift-down) (define-key map (kbd "f") #'agenda-view-goto-next) (define-key map (kbd "n") #'agenda-view-goto-next) (define-key map (kbd "b") #'agenda-view-goto-prev) (define-key map (kbd "p") #'agenda-view-goto-prev) map) "Keymap for `agenda-view-mode'.") (defun agenda-view--hl-line-range () "Restrict line highlight to some parts of the line. Each view mode defines relevant range as 'agenda-hl-range'." (save-excursion (save-restriction (save-match-data (let* ((prop 'agenda-hl-range) (val t) (lbp (line-beginning-position)) (lep (line-end-position)) beg end) ;; Restrict all buffer operations to just this line (narrow-to-region lbp lep) (cond ;; 1. Check if point is already ON the property ((eq (get-text-property (point) prop) val) (setq beg (previous-single-property-change (min (1+ (point)) (point-max)) prop nil lbp) end (next-single-property-change (point) prop nil lep))) ;; 2. BACKWARD search: Only if NOT at the very start of the line ((and (> (point) lbp) (let ((match (text-property-search-backward prop val t))) (when (and match (>= (prop-match-beginning match) lbp)) (setq beg (prop-match-beginning match) end (prop-match-end match)) t)))) ; Return t to break the cond ;; 3. FORWARD search: Look ahead within the same line (t (let ((match-fwd (text-property-search-forward prop val t))) (when (and match-fwd (< (prop-match-beginning match-fwd) lep)) (setq beg (prop-match-beginning match-fwd) end (prop-match-end match-fwd)))))) (cons (or beg lbp) (or end lep))))))) (define-derived-mode agenda-view-mode special-mode "Agenda view" "Major mode for displaying the agenda dashboard." (setq truncate-lines t) (hl-line-mode 1) (setq-local hl-line-range-function #'agenda-view--hl-line-range) (face-remap-add-relative 'hl-line 'nano-salient-h) (add-hook 'post-command-hook (lambda () (let ((message-log-max nil)) (display-local-help t)) nil t))) (provide 'agenda-view) ;;; agenda-view.el ends here ================================================ FILE: agenda.el ================================================ ;;; agenda.el --- A fast & simple text-based agenda -*- lexical-binding: t; -*- ;; Copyright (C) 2026 Nicolas P. Rougier ;; Author: Nicolas P. Rougier ;; URL: https://github.com/rougier/agenda ;; Version: 0.1.0 ;; Package-Requires: ((emacs "27.1")) ;; Keywords: calendar, agenda, convenience ;; This file is not part of GNU Emacs. ;; This file 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, or (at your option) ;; any later version. ;; This file 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. ;; For a full copy of the GNU General Public License ;; see . ;;; Commentary: ;; This package provides a fast, lightweight agenda system based on a ;; simple text file format. It provides an edit mode, to ease entering ;; information and a view mode to render the agenda for day, week, ;; month, 3 months or year. ;; ;; The project is structured into several sub-modules: ;; - agenda-faces.el : Faces definition ;; - agenda-parse.el : Parsing and test functions ;; - agenda-utils.el : Various utility functions ;; - agenda-edit.el : Minor edit mode ;; - agenda-view.el : Major view mode ;; - agenda-view-day.el : Day view ;; - agenda-view-week.el : Week view ;; - agenda-view-month.el : Single month and 3 months view ;; - agenda-view-year.el : Year view ;; - agenda-export.el ; Export functions (ical) ;; - agenda-capture.el : Capture functions ;; Note on date formats: ;; - Calendar format is (month day year) ;; - Agenda entry format is (year month day) ;; - Timestamp format is (second minute hour day month year) ;; - ISO commercial format is (week weekday year) ;; It is important to distinguish between two modes: ;; - agenda-edit-mode: For the editing the source file ;; - agenda-view-mode: For the viewing the agenda ;;; Code: (require 'cal-iso) (require 'calendar) (require 'agenda-faces) (require 'agenda-parse) (require 'agenda-utils) (require 'agenda-view) (require 'agenda-edit) (require 'agenda-export) (require 'agenda-capture) (defcustom agenda-file (expand-file-name "agenda.txt" user-emacs-directory) "Agenda file" :group 'agenda :type 'file) (defcustom agenda-file-ical-public "~/.calendars/Public.ics" "Agenda export filename for public agenda (personal information stripped)." :group 'agenda :type 'file) (defcustom agenda-file-ical-private "~/.calendars/Private.ics" "Agenda export filename for public agenda (personal information visible)." :group 'agenda :type 'file) (defconst agenda-view-buffer "*agenda*" "Name of the agenda view buffer") (defvar agenda--highlight-overlay nil "Overlay used for transient highlighting.") (defcustom agenda-marks '((inweek . "○") (today . "●") (cancel . "") (capture . " ") (birthday . "󰃫") (conflict . "*") (deadline . "!")) "List of margin marks." :group 'agenda :type '(alist :key-type (symbol :tag "State") :value-type (string :tag "Mark"))) (defcustom agenda-slot-faces '(("DEADLINE" . agenda-slot-deadline) ("PERSONAL\\|HOME" . agenda-slot-personal)) "Mapping of tag to faces." :type '(alist :key-type (string :tag "Tags filter") :value-type (face :tag "Face")) :group 'agenda) (defcustom agenda-deadline-faces '(( 0 . agenda-deadline-0) ( 7 . agenda-deadline-1) (15 . agenda-deadline-2) (30 . agenda-deadline-3)) "Mapping of days to deadlines faces (view week mode)." :type '(alist :key-type (integer :tag "Number of days") :value-type (face :tag "Face")) :group 'agenda) (defcustom agenda-calendar-palette (let* ((black (face-foreground 'default nil 'default)) (white (face-background 'default nil 'default))) (list (cons black white) ;; Base entry ;; Material deep orange shades (cons black "#FBE9E7") ;; 50 (cons black "#FFCCBC") ;; 100 (cons black "#FFAB91") ;; 200 (cons black "#FF8A65") ;; 300 (cons black "#FF7043") ;; 400 (cons white "#FF5722") ;; 500 (cons white "#F4511E") ;; 600 (cons white "#E64A19") ;; 700 (cons white "#D84315") ;; 800 (cons white "#BF360C"))) ;; 900 "List of (FG . BG) color pairs for calendar highlighting. The first entry is a base (foreground . background) pair using the default Emacs colors. Subsequent entries correspond to the standard Deep Orange shades (50–900), with foreground chosen for readability (black on light backgrounds, white on dark)." :type '(repeat (cons color color)) :group 'nano-agenda) ;; Installing agenda-mode for the agenda-file (add-to-list 'auto-mode-alist (cons agenda-file 'agenda-edit-mode)) ;;;###autoload (defun agenda (&optional empty-cache) "Invalidate all caches if EMPTY-CACHE is t and popup the agenda." (interactive) (unless (and agenda-file (file-exists-p agenda-file)) (error "Agenda file not found: %s. " agenda-file)) (setq agenda-source-buffer (find-file-noselect agenda-file)) (with-current-buffer agenda-source-buffer (when empty-cache (setq agenda--entries-cache nil agenda--uids-cache nil agenda--slots-cache nil) (when agenda-view--calendar-cache (clrhash agenda-view--calendar-cache))) (agenda-edit-mode) (agenda-parse-buffer) (agenda-view))) (bind-key (kbd "M-a") #'agenda) (bind-key (kbd "M-c") #'agenda-capture-with-calendar) (provide 'agenda) ;;; agenda.el ends here ================================================ FILE: agenda.sh ================================================ #!/bin/bash # Configuration: Define your agenda source file here AGENDA_FILE="/Users/rougier/.nano.d/agenda.txt" # Clear the terminal screen for a clean workspace clear # Get current year and ISO week number for filtering YEAR=$(date +%Y) WEEK=$(date +w%V) TODAY=$(date +%Y-%m-%d) # Regex Breakdown re="^([0-9]{4}-[0-9]{2}-[0-9]{2}( [wW][0-9]+)?( [[:alpha:]]+)?)" re+="[[:space:]]+([0-9]{2}:[0-9]{2}(-[0-9]{2}:[0-9]{2})?)?" re+="([[:space:]]+-+)*[[:space:]]+" re+="([^@+\[]+[^@+\[[:space:]])" re+="[[:space:]]*((@[^[:space:]+\[]+[[:space:]]*)*)" re+="[[:space:]]*(([+][^[:space:]\[]+[[:space:]]*)*)" re+="[[:space:]]*(\[([[:alnum:]]+)\])?$" # UI Styling Constants BOLD="\033[1m" STRIKE="\033[9m" # ANSI Strikethrough BRIGHT_RED="\033[91m" # For @ACTIONS LIGHT_GRAY="\033[38;5;250m" # For +TAGS RESET="\033[0m" current_date_header="" if [[ -f "$AGENDA_FILE" ]]; then # Filter for week, then SORT alphabetically (chronological by date/time) grep "^${YEAR}.*${WEEK}" "$AGENDA_FILE" | sort | while read -r line; do if [[ $line =~ $re ]]; then iso_date="${BASH_REMATCH[1]:0:10}" time_str="${BASH_REMATCH[4]:- }" title="${BASH_REMATCH[7]}" actions="${BASH_REMATCH[8]}" actions="${actions#"${actions%%[![:space:]]*}"}" actions="${actions%"${actions##*[![:space:]]}"}" tags="${BASH_REMATCH[10]}" tags="${tags#"${tags%%[![:space:]]*}"}" tags="${tags%"${tags##*[![:space:]]}"}" # --- STRIKETHROUGH LOGIC --- # Check if +CANCEL exists in the tags string line_style="" if [[ "$tags" == *"+CANCEL"* ]]; then line_style="$STRIKE" fi # Date Header Logic if [[ "$iso_date" != "$current_date_header" ]]; then [[ -n "$current_date_header" ]] && printf "\n" pretty_date=$(date -j -f "%Y-%m-%d" "$iso_date" +"%A %d %B %Y" 2>/dev/null || \ date -d "$iso_date" +"%A %d %B %Y" 2>/dev/null) if [[ "$iso_date" == "$TODAY" ]]; then printf "${BOLD}%s${RESET} (today)\n\n" "${pretty_date:-$iso_date}" else printf "${BOLD}%s${RESET}\n\n" "${pretty_date:-$iso_date}" fi current_date_header="$iso_date" fi # Print the line using the line_style (Empty or Strikethrough) printf " ${line_style}%s %s${RESET}" "$time_str" "$title" if [[ -n "$actions" ]]; then printf " ${BRIGHT_RED}%s${RESET}" "$actions" fi if [[ -n "$tags" ]]; then printf " ${LIGHT_GRAY}%s${RESET}" "$tags" fi printf "\n" fi done else echo -e "${BRIGHT_RED}Error: File '$AGENDA_FILE' not found.${RESET}" fi printf "\n"