├── .gitignore ├── LICENSE ├── README.org ├── guix.scm ├── img ├── logo.svg ├── monero-logo.png └── monero-qr-address.png ├── org-timeblock.el ├── screenshots ├── multi-day-view.png ├── org-timeblock-mode.png └── org-timeblock-with-list-mode.png └── test ├── org-timeblock-test.el ├── test-date.el ├── test-daterangep.el ├── test-intersectp.el ├── test-schedule.el └── test-ts-to-org-timerange.el /.gitignore: -------------------------------------------------------------------------------- 1 | # Added automatically by ‘eldev init’. 2 | /.eldev 3 | run-tests.sh 4 | *.elc 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+html:
2 | #+html:

org-timeblock

3 | #+html:

Emacs package that provides interactive multiple-day timeblock 4 | #+html: view for orgmode tasks.

5 | 6 | * Contents 7 | 8 | - [[#screenshots][Screenshots]] 9 | - [[#screencast][Screencast]] 10 | - [[#why][Why I wrote this package]] 11 | - [[#installation][Installation]] 12 | - [[#usage][Usage]] 13 | - [[#customization][Customization]] 14 | - [[#todos][TODOs]] 15 | - [[#donations][Donations]] 16 | - [[#changelog][Changelog]] 17 | 18 | * Screenshots 19 | :PROPERTIES: 20 | :CUSTOM_ID: screenshots 21 | :END: 22 | 23 | org-timeblock-mode buffer: 24 | 25 | [[file:screenshots/org-timeblock-mode.png]] 26 | 27 | You can press ~[T]~ to toggle the display of org-timeblock-list-mode 28 | buffer. Foreground colors for timeblocks are generated randomly, but 29 | you can assign specific background and foreground colors in 30 | customizable variable ~org-timeblock-tag-colors~: 31 | 32 | [[file:screenshots/org-timeblock-with-list-mode.png]] 33 | 34 | You can switch to a multi-day view using ~org-timeblock-change-span [V]~: 35 | 36 | [[file:screenshots/multi-day-view.png]] 37 | 38 | * Screencast 39 | :PROPERTIES: 40 | :CUSTOM_ID: screencast 41 | :END: 42 | 43 | [[https://youtu.be/lVV9gVp5nxU]] 44 | 45 | * Why 46 | :PROPERTIES: 47 | :CUSTOM_ID: why 48 | :END: 49 | 50 | The builtin orgmode package for collecting and displaying open 51 | tasks/events/deadlines relevant for a particular set of dates, org-agenda, does 52 | not have a timeblock representation which is available in almost all modern 53 | calendars. 54 | 55 | Sometimes, a list representation (like in org-agenda) is not sufficient, because 56 | it can be difficult to quickly get an overview of a day or week schedule. 57 | 58 | * Installation 59 | :PROPERTIES: 60 | :CUSTOM_ID: installation 61 | :END: 62 | 63 | Requirements: 64 | 65 | - Emacs 28.1 (or higher) 66 | - SVG support in your Emacs build 67 | 68 | ** MELPA 69 | 70 | You can install the package from MELPA using ~M-x package-install org-timeblock~ 71 | 72 | ** package-vc-install (Emacs 29) 73 | 74 | If you use Emacs 29, you can install the package via 75 | 76 | ~M-x package-vc-install RET https://github.com/ichernyshovvv/org-timeblock/ RET~ 77 | 78 | ** Guix 79 | 80 | If you use Guix, you can install the package from the official Guix channel. 81 | 82 | ** Quelpa 83 | 84 | 1. Install ~quelpa-use-package~ (which can be installed directly from MELPA). 85 | 2. Add this form to your init file: 86 | 87 | #+begin_src elisp 88 | (use-package org-timeblock 89 | :quelpa (org-timeblock :fetcher github :repo "ichernyshovvv/org-timeblock")) 90 | #+end_src 91 | 92 | ** Straight 93 | 94 | Add this form to your init file: 95 | 96 | #+begin_src elisp 97 | (use-package org-timeblock 98 | :straight (org-timeblock :type git 99 | :host github 100 | :repo "ichernyshovvv/org-timeblock")) 101 | #+end_src 102 | 103 | * Usage 104 | :PROPERTIES: 105 | :CUSTOM_ID: usage 106 | :END: 107 | 108 | There are two major modes provided by the package: 109 | 110 | - ~org-timeblock-mode~. Displays timeblock view of ~SCHEDULED/DEADLINE~ org 111 | tasks or events (entries that have active timestamps in the body or heading) 112 | for specific days. 113 | - ~org-timeblock-list-mode~. Displays a list of tasks (including those that are 114 | not time-specific). 115 | 116 | Run ~M-x org-timeblock~ to open 3-day view that starts from today's date. The 117 | default days span can be customized via ~org-timeblock-span~ variable. In the 118 | view you will see only entries that have time specified in their timestamps. To 119 | see other found tasks/events (entries that have timestamps without time), press 120 | ~T~ (M-x org-timeblock-toggle-timeblock-list). 121 | 122 | Tasks and events are searched in ~org-timeblock-files~ which defaults to 123 | ~(org-agenda-files)~. 124 | 125 | To navigate between the blocks, use ~[fbpn]~, arrow keys or mouse (yes, the 126 | blocks are clickable). 127 | 128 | To open other dates, you can run the following the following commands: 129 | 130 | - org-timeblock-day-later ~[C- / C-f]~ 131 | - org-timeblock-day-earlier ~[C- / C-b]~ 132 | - org-timeblock-jump-to-day ~j~ 133 | - org-timeblock-change-span ~V~ 134 | 135 | To reschedule or change the duration of the task bound to the selected block, 136 | use these commands: 137 | 138 | - org-timeblock-schedule ~s~ 139 | - org-timeblock-set-duration ~d~ 140 | 141 | Also, you can mark the blocks and operate on them via ~M-x org-timeblock-schedule [s]~: 142 | - org-timeblock-mark-block ~m~ 143 | - org-timeblock-mark-by-regexp ~%~ 144 | - org-timeblock-unmark-block ~u~ 145 | - org-timeblock-unmark-all-blocks ~U~ 146 | 147 | If you want to add a new task, press ~+~ (M-x org-timeblock-new-task). 148 | 149 | Almost all commands with the same bindings are available in 150 | ~org-timeblock-list~. 151 | 152 | * Customization 153 | :PROPERTIES: 154 | :CUSTOM_ID: customization 155 | :END: 156 | 157 | ~M-x customize-group org-timeblock~ to see available customizable variables. 158 | 159 | * TODOs 160 | :PROPERTIES: 161 | :CUSTOM_ID: todos 162 | :END: 163 | - [ ] Implement caching mechanism for SVG data 164 | - [ ] Improve timeblocks layout algorithm 165 | - [ ] Split each column into a separate SVG image to improve the speed of 166 | ~*org-timeblock*~ buffer redisplay 167 | - [ ] Create timeblock.el library that could be used for iCalendar and other 168 | time data 169 | 170 | * Donations 171 | :PROPERTIES: 172 | :CUSTOM_ID: donations 173 | :END: 174 | #+html:
175 | #+html: 176 | ~444GDw7rkd3Mj5hi6ZzEXZ4QN565TFw4J5ithFcywsMnJn7dFsxWTEQ4vtSMQC1sckFBu7neS8yZZRLnY8EYpS4UNMEAvpL~ 177 | #+html:

178 | #+html:
179 | #+html: liberapay.com/ichernyshovvv 180 | #+html:
181 | 182 | * Changelog 183 | :PROPERTIES: 184 | :CUSTOM_ID: changelog 185 | :END: 186 | 187 | ** 0.1 188 | First tagged release. 189 | ** 0.2 190 | - Added mark commands (~mark-block~, ~unmark-block~, ~mark-by-regexp~) for 191 | timeblocks that can be used to reschedule multiple tasks at once 192 | - Replaced ts.el with built-in time API 193 | - Replaced org-ql with own searching and caching functions 194 | - dom.el is now used instead of regexps to fetch and change SVG data (much 195 | cleaner code) 196 | - Deadline timestamps are now treated as it should be, not as events 197 | - Now, each active timestamp in a heading body is displayed (as event), not only 198 | the first one 199 | - Added custom variable org-timeblock-files 200 | - Other minor bug fixes and improvements 8) 201 | -------------------------------------------------------------------------------- /guix.scm: -------------------------------------------------------------------------------- 1 | (use-modules 2 | (guix gexp) 3 | (guix packages) 4 | (guix git-download) 5 | (guix build-system emacs) 6 | ((guix licenses) #:prefix license:) 7 | (gnu packages emacs) 8 | (gnu packages emacs-xyz)) 9 | 10 | (define %source-dir (dirname (current-filename))) 11 | 12 | (define-public emacs-org-timeblock 13 | (package 14 | (name "emacs-org-timeblock") 15 | (version "git") 16 | (source (local-file %source-dir 17 | #:recursive? #t 18 | #:select? (git-predicate %source-dir))) 19 | (build-system emacs-build-system) 20 | (arguments `(#:tests? #t 21 | #:test-command '("emacs" "--batch" 22 | "-l" "test/org-timeblock-test.el" 23 | "-f" "ert-run-tests-batch-and-exit"))) 24 | (propagated-inputs (list emacs-compat)) 25 | (home-page "https://github.com/ichernyshovvv/org-timeblock") 26 | (synopsis "Timeblocking tool for orgmode inside Emacs") 27 | (description "Emacs package that provides interactive multiple-day timeblock 28 | view for orgmode tasks.") 29 | (license license:gpl3+))) 30 | 31 | emacs-org-timeblock 32 | -------------------------------------------------------------------------------- /img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | Org unicorn on background with timeblocks, modus opreandi colorsOrg-timeblock unicornt no frame modus opreandi colors 216 | -------------------------------------------------------------------------------- /img/monero-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ichernyshovvv/org-timeblock/e61e5734b49f933ed178029f804a0499f3308e1e/img/monero-logo.png -------------------------------------------------------------------------------- /img/monero-qr-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ichernyshovvv/org-timeblock/e61e5734b49f933ed178029f804a0499f3308e1e/img/monero-qr-address.png -------------------------------------------------------------------------------- /org-timeblock.el: -------------------------------------------------------------------------------- 1 | ;;; org-timeblock.el --- Interactive SVG calendar for orgmode tasks -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2023 Ilya Chernyshov 4 | 5 | ;; Author: Ilya Chernyshov 6 | ;; Version: 0.2 7 | ;; Package-Requires: ((emacs "28.1") (compat "29.1.4.1") (org "9.0") (svg "1.1")) 8 | ;; Keywords: org, calendar, timeblocking, agenda 9 | ;; URL: https://github.com/ichernyshovvv/org-timeblock 10 | 11 | ;;; License: 12 | 13 | ;; This program is free software; you can redistribute it and/or modify 14 | ;; it under the terms of the GNU General Public License as published by 15 | ;; the Free Software Foundation, either version 3 of the License, or 16 | ;; (at your option) any later version. 17 | 18 | ;; This program is distributed in the hope that it will be useful, 19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | ;; GNU General Public License for more details. 22 | 23 | ;; You should have received a copy of the GNU General Public License 24 | ;; along with this program. If not, see . 25 | 26 | ;;; Commentary: 27 | 28 | ;; org-timeblock.el is a package that allows you to visually 29 | ;; understand your day schedule, quickly reschedule your tasks and set 30 | ;; TODO statuses 31 | 32 | ;;; Code: 33 | 34 | ;;;; Requirements 35 | 36 | (require 'org) 37 | (require 'svg) 38 | (require 'seq) 39 | (require 'compat) 40 | (require 'compat-macs) 41 | 42 | ;;;; Faces 43 | 44 | ;; The colors are borrowed from pulsar.el project written by Protesilaos Stavrou 45 | 46 | (defface org-timeblock-red 47 | '((default :extend t) 48 | (((class color) (min-colors 88) (background light)) 49 | :background "#ffcccc" :foreground "#77002a") 50 | (((class color) (min-colors 88) (background dark)) 51 | :background "#77002a" :foreground "#ffcccc") 52 | (t :inverse-video t)) 53 | "Red face." 54 | :group 'org-timeblock) 55 | 56 | (defface org-timeblock-green 57 | '((default :extend t) 58 | (((class color) (min-colors 88) (background light)) 59 | :background "#aceaac" :foreground "#00422a") 60 | (((class color) (min-colors 88) (background dark)) 61 | :background "#00422a" :foreground "#aceaac") 62 | (t :inverse-video t)) 63 | "Green face." 64 | :group 'org-timeblock) 65 | 66 | (defface org-timeblock-yellow 67 | '((default :extend t) 68 | (((class color) (min-colors 88) (background light)) 69 | :background "#fff29a" :foreground "#693200") 70 | (((class color) (min-colors 88) (background dark)) 71 | :background "#693200" :foreground "#fff29a") 72 | (t :inverse-video t)) 73 | "Yellow face." 74 | :group 'org-timeblock) 75 | 76 | (defface org-timeblock-blue 77 | '((default :extend t) 78 | (((class color) (min-colors 88) (background light)) 79 | :background "#8fcfff" :foreground "#242679") 80 | (((class color) (min-colors 88) (background dark)) 81 | :background "#242679" :foreground "#8fcfff") 82 | (t :inverse-video t)) 83 | "Blue face." 84 | :group 'org-timeblock) 85 | 86 | (defface org-timeblock-magenta 87 | '((default :extend t) 88 | (((class color) (min-colors 88) (background light)) 89 | :background "#ffccff" :foreground "#71206a") 90 | (((class color) (min-colors 88) (background dark)) 91 | :background "#71206a" :foreground "#ffccff") 92 | (t :inverse-video t)) 93 | "Magenta face." 94 | :group 'org-timeblock) 95 | 96 | (defface org-timeblock-cyan 97 | '((default :extend t) 98 | (((class color) (min-colors 88) (background light)) 99 | :background "#8eecf4" :foreground "#004065") 100 | (((class color) (min-colors 88) (background dark)) 101 | :background "#004065" :foreground "#8eecf4") 102 | (t :inverse-video t)) 103 | "Cyan face." 104 | :group 'org-timeblock) 105 | 106 | (defface org-timeblock-list-header '((t (:inherit org-agenda-structure))) 107 | "Face used in org-timeblock-list for dates." 108 | :group 'org-timeblock) 109 | 110 | (defface org-timeblock-select 111 | '((default :extend t) 112 | (((class color) 113 | (min-colors 88) 114 | (background light)) 115 | :background "#f3d000") 116 | (((class color) (min-colors 88) (background dark)) 117 | :background "#3f1651") 118 | (t :inverse-video t)) 119 | "Face used for selected blocks." 120 | :group 'org-timeblock) 121 | 122 | (defface org-timeblock-mark 123 | '((default :extend t) 124 | (((class color) 125 | (min-colors 88) 126 | (background light)) 127 | :background "#7b435c") 128 | (((class color) (min-colors 88) (background dark)) 129 | :background "#7b435c") 130 | (t :inverse-video t)) 131 | "Face used for marked blocks." 132 | :group 'org-timeblock) 133 | 134 | (defface org-timeblock-hours-line 135 | '((default :extend t) 136 | (((class color) 137 | (min-colors 88) 138 | (background light)) 139 | :background "#7b435c") 140 | (((class color) (min-colors 88) (background dark)) 141 | :background "#cdcdcd") 142 | (t :inverse-video t)) 143 | "Face used for hour lines." 144 | :group 'org-timeblock) 145 | 146 | (defface org-timeblock-current-time-indicator 147 | '((default :extend t) 148 | (((class color) 149 | (min-colors 88) 150 | (background light)) 151 | :background "red") 152 | (((class color) (min-colors 88) (background dark)) 153 | :background "red") 154 | (t :inverse-video t)) 155 | "Color face used for current time indicator." 156 | :group 'org-timeblock) 157 | 158 | ;;;; Custom Variables 159 | 160 | (defgroup org-timeblock nil 161 | "Customization for `org-timeblock'." 162 | :group 'org 163 | :link '(url-link "https://github.com/ichernyshovvv/org-timeblock")) 164 | 165 | (defcustom org-timeblock-show-future-repeats nil 166 | "Non-nil shows repeated entries in the future dates of repeat. 167 | When set to the symbol `next' only the first future repeat is shown." 168 | :group 'org-timeblock 169 | :type '(choice 170 | (const :tag "Show all repeated entries" t) 171 | (const :tag "Show next repeated entry" next) 172 | (const :tag "Do not show repeated entries" nil))) 173 | 174 | (defcustom org-timeblock-files 'agenda 175 | "Org files with agenda items to display with `org-timeblock'. 176 | When set to the symbol \\+`agenda', `org-agenda-files' are used. 177 | Otherwise, it may be set to a list of filenames." 178 | :group 'org-timeblock 179 | :type '(choice 180 | (repeat :tag "List of files" file) 181 | (const :tag "Files from (org-agenda-files)" agenda))) 182 | 183 | (defcustom org-timeblock-show-outline-path nil 184 | "Non-nil means show outline path in echo area for the selected item." 185 | :group 'org-timeblock 186 | :type '(choice 187 | (const :tag "Don't show outline path with prepended file name." nil) 188 | (const :tag "Show outline path." t))) 189 | 190 | (defcustom org-timeblock-span 3 191 | "Number of days displayed in `org-timeblock'." 192 | :group 'org-timeblock 193 | :type 'integer) 194 | 195 | (defcustom org-timeblock-display-time t 196 | "Non-nil means show end and start time inside timeblocks." 197 | :group 'org-timeblock 198 | :type '(choice 199 | (const :tag "Show time." t) 200 | (const :tag "Do not show time." nil))) 201 | 202 | (defcustom org-timeblock-inbox-file 203 | (expand-file-name "inbox.org" org-directory) 204 | "Org file in which new tasks are created via `org-timeblock-new-task'." 205 | :group 'org-timeblock 206 | :type 'file) 207 | 208 | (defcustom org-timeblock-new-task-time 209 | 'pick 210 | "Time to which new tasks are scheduled via `org-timeblock-new-task'." 211 | :group 'org-timeblock 212 | :type 213 | '(choice 214 | (const :tag "Unspecified. The new task will be scheduled to a date with no time" nil) 215 | (const :tag "The new task will be scheduled to a time picked by user." pick) 216 | (string :tag "Time of the format \"HH:MM\". The new task will be scheduled to a time."))) 217 | 218 | (defcustom org-timeblock-scale-options t 219 | "Options that are used to decide which part of visual schedule must be hidden." 220 | :group 'org-timeblock 221 | :type '(choice 222 | (const :tag "Hide hours in the past (if there are no timeblocks)." t) 223 | (const :tag "Do not hide anything. All 24 hours will be displayed." nil) 224 | (const :tag "Hide all free hours before the first timeblock." hide-all) 225 | (cons :tag "Display specified range of hours [earliest; latest)." 226 | (integer :tag "Min Hour") 227 | (integer :tag "Max Hour")))) 228 | 229 | (defcustom org-timeblock-current-time-indicator t 230 | "Whether to show current time indicator in the `org-timeblock-list' buffer." 231 | :group 'org-timeblock 232 | :type 'boolean) 233 | 234 | (defcustom org-timeblock-tag-colors 235 | nil 236 | "Faces for specific tags. 237 | 238 | Alist of the form 239 | ((\"tag1\" . face-1) 240 | (\"tag2\" . face-2)). 241 | 242 | In `org-timeblock-mode', timeblocks tagged with a tag in car are 243 | painted in :background color of the face in cdr. In 244 | `org-timeblock-list-mode', faces are used to colorize items that 245 | are tagged with a tag in car." 246 | :type 'list 247 | :group 'org-timeblock) 248 | 249 | ;;;; Variables 250 | 251 | (defvar org-timeblock-markers nil) 252 | 253 | (defvar org-timeblock-buffers nil) 254 | 255 | (defvar org-timeblock-mark-count 0) 256 | 257 | (defvar org-timeblock-colors nil) 258 | 259 | (defvar org-timeblock-data nil) 260 | (defvar org-timeblock-column 1 261 | "Currently selected column.") 262 | 263 | (defvar org-timeblock-cache nil) 264 | (defvar org-timeblock-svg nil) 265 | (defvar org-timeblock-svg-width 0) 266 | (defvar org-timeblock-svg-height 0) 267 | 268 | (defvar org-timeblock-daterange nil 269 | "The date range that is used to get and display schedule data.") 270 | 271 | (defvar org-timeblock-duration-multipliers 272 | '((?w . 10080) 273 | (?d . 1440) 274 | (?h . 60) 275 | (?m . 1)) 276 | "Duration multipliers used in `org-timeblock-read-duration'.") 277 | 278 | (defvar org-timeblock-buffer 279 | "*org-timeblock*" "The name of the buffer displaying visual schedule.") 280 | 281 | (defvar org-timeblock-list-buffer "*org-timeblock-list*" 282 | "The name of the buffer displaying the list of tasks and events.") 283 | 284 | ;;;; Keymaps 285 | 286 | (defvar-keymap org-timeblock-mode-map 287 | "+" #'org-timeblock-new-task 288 | "" #'org-timeblock-select-block-with-cursor 289 | "" #'org-timeblock-forward-block 290 | "n" #'org-timeblock-forward-block 291 | "" #'org-timeblock-backward-block 292 | "p" #'org-timeblock-backward-block 293 | "" #'org-timeblock-forward-column 294 | "f" #'org-timeblock-forward-column 295 | "" #'org-timeblock-backward-column 296 | "b" #'org-timeblock-backward-column 297 | "C-" #'org-timeblock-day-later 298 | "C-f" #'org-timeblock-day-later 299 | "C-" #'org-timeblock-day-earlier 300 | "C-b" #'org-timeblock-day-earlier 301 | "RET" #'org-timeblock-goto 302 | "TAB" #'org-timeblock-goto-other-window 303 | "d" #'org-timeblock-set-duration 304 | "i" #'org-timeblock-clock-in 305 | "o" #'org-clock-out 306 | "g" #'org-timeblock-redraw-buffers 307 | "j" #'org-timeblock-jump-to-day 308 | "C-s" #'org-save-all-org-buffers 309 | "s" #'org-timeblock-schedule 310 | "T" #'org-timeblock-toggle-timeblock-list 311 | "t" #'org-timeblock-todo 312 | "v" #'org-timeblock-switch-scaling 313 | "V" #'org-timeblock-change-span 314 | "m" #'org-timeblock-mark-block 315 | "%" #'org-timeblock-mark-by-regexp 316 | "u" #'org-timeblock-unmark-block 317 | "U" #'org-timeblock-unmark-all-blocks 318 | "w" #'org-timeblock-write) 319 | 320 | (defvar-keymap org-timeblock-list-mode-map 321 | "+" #'org-timeblock-new-task 322 | " " #'org-timeblock-list-next-line 323 | "n" #'org-timeblock-list-next-line 324 | " " #'org-timeblock-list-previous-line 325 | "p" #'org-timeblock-list-previous-line 326 | "C-" #'org-timeblock-day-later 327 | "f" #'org-timeblock-day-later 328 | "C-" #'org-timeblock-day-earlier 329 | "b" #'org-timeblock-day-earlier 330 | "C-s" #'org-save-all-org-buffers 331 | "RET" #'org-timeblock-list-goto 332 | "TAB" #'org-timeblock-list-goto-other-window 333 | "d" #'org-timeblock-list-set-duration 334 | "i" #'org-timeblock-list-clock-in 335 | "o" #'org-clock-out 336 | "g" #'org-timeblock-redraw-buffers 337 | "j" #'org-timeblock-jump-to-day 338 | "q" #'org-timeblock-quit 339 | "s" #'org-timeblock-list-schedule 340 | "T" #'org-timeblock-list-toggle-timeblock 341 | "t" #'org-timeblock-todo 342 | "v" #'org-timeblock-switch-scaling 343 | "V" #'org-timeblock-change-span) 344 | 345 | ;;;; Modes 346 | 347 | (define-derived-mode org-timeblock-mode 348 | special-mode "Org-Timeblock" :interactive nil 349 | (setq 350 | org-timeblock-daterange 351 | (cons (decode-time) 352 | (org-timeblock-time-inc 'day (1- org-timeblock-span) 353 | (decode-time))) 354 | cursor-type nil 355 | buffer-read-only t) 356 | (org-timeblock-redisplay)) 357 | 358 | (define-derived-mode org-timeblock-list-mode 359 | special-mode "Org-Timeblock-List" :interactive nil 360 | (setq truncate-lines t)) 361 | 362 | ;;;; Functions 363 | 364 | (compat-version "29.1") 365 | 366 | (compat-defun org-fold-show-context (&optional key) 367 | "Make sure point and context are visible." 368 | (org-show-context key)) 369 | 370 | (defun org-timeblock-show-context () 371 | "Make sure point and context are visible." 372 | (compat-call org-fold-show-context 'agenda)) 373 | 374 | (defsubst org-timeblock-format-time (format-string time) 375 | "Use FORMAT-STRING to format the time value TIME." 376 | (let ((time (copy-sequence time))) 377 | (unless (decoded-time-second time) 378 | (setf (decoded-time-second time) 0)) 379 | (unless (decoded-time-minute time) 380 | (setf (decoded-time-minute time) 0)) 381 | (unless (decoded-time-hour time) 382 | (setf (decoded-time-hour time) 0)) 383 | (format-time-string format-string (encode-time time)))) 384 | 385 | (cl-defsubst org-timeblock-get-ts-prop (&optional object (position 0)) 386 | "Return POSITION's \\='timestamp property, in OBJECT." 387 | (get-text-property position 'timestamp object)) 388 | 389 | (cl-defsubst org-timeblock-get-ts-type (&optional object (position 0)) 390 | "Return POSITION's \\='type property, in OBJECT." 391 | (get-text-property position 'type object)) 392 | 393 | (defun org-timeblock-cursor-pos () 394 | "Return cursor position in the window of the *org-timeblock* buffer. 395 | If cursor position is outside of the window, return nil. 396 | 397 | Cursor position is of the form (X . Y)." 398 | (when-let ((cursor-pos (cdr (mouse-pixel-position))) 399 | (window (get-buffer-window org-timeblock-buffer)) 400 | (pos (window-edges window t nil t))) 401 | (when (and (> (- (car cursor-pos) (car pos)) 0) 402 | (> (- (cdr cursor-pos) (cadr pos)) 0)) 403 | (cons (- (car cursor-pos) (car pos)) 404 | (- (cdr cursor-pos) (cadr pos)))))) 405 | 406 | (defun org-timeblock-selected-block-marker () 407 | "Return a marker pointing to the org entry of selected timeblock." 408 | (when-let ((node (org-timeblock-selected-block)) 409 | (id (dom-attr node 'id))) 410 | (org-timeblock-get-marker-by-id 411 | (car (split-string id "_"))))) 412 | 413 | (defun org-timeblock-get-marker-by-id (id) 414 | "Return a marker of entry with ID." 415 | (cadr (seq-find (lambda (x) (string= (car x) id)) org-timeblock-data))) 416 | 417 | (defun org-timeblock-get-dates (from to) 418 | "Return a list of decoded-time dates between FROM and TO." 419 | (let (dates) 420 | (while (and 421 | (push from dates) 422 | (setq from (org-timeblock-time-inc 'day 1 from)) 423 | (org-timeblock-date<= from to))) 424 | (nreverse dates))) 425 | 426 | (defun org-timeblock-selected-block () 427 | "Return an id of the entry of selected timeblock. 428 | id is constructed via `org-timeblock-construct-id'" 429 | (car (dom-search 430 | org-timeblock-svg 431 | (lambda (node) (dom-attr node 'select))))) 432 | 433 | (defmacro org-timeblock-on (accessor op lhs rhs) 434 | "Run OP on ACCESSOR's return values from LHS and RHS." 435 | `(,op (,accessor ,lhs) (,accessor ,rhs))) 436 | 437 | (defun org-timeblock-date= (a b) 438 | "Return non-nil if dates of A and B time values are equal." 439 | (cond 440 | ((and (null a) (null b))) 441 | ((and a b) 442 | (and (org-timeblock-on decoded-time-year = a b) 443 | (org-timeblock-on decoded-time-month = a b) 444 | (org-timeblock-on decoded-time-day = a b))))) 445 | 446 | (defun org-timeblock-date< (a b) 447 | "Return non-nil if A's date is less than B's date." 448 | (cond 449 | ;; nil is less than non-nil 450 | ((null b) nil) 451 | ((null a) t) 452 | (t 453 | (or (org-timeblock-on decoded-time-year < a b) 454 | (and 455 | (org-timeblock-on decoded-time-year = a b) 456 | (or (org-timeblock-on decoded-time-month < a b) 457 | (and (org-timeblock-on decoded-time-month = a b) 458 | (org-timeblock-on decoded-time-day < a b)))))))) 459 | 460 | (defun org-timeblock-time-diff (a b) 461 | "Return difference between times A and B in minutes." 462 | (when-let ((a (encode-time a)) 463 | (b (encode-time b))) 464 | (/ (time-convert (time-subtract a b) 'integer) 60))) 465 | 466 | (defun org-timeblock-decoded< (a b) 467 | "Return non-nil if A is earlier then B." 468 | (cond 469 | ;; nil is less than non-nil 470 | ((null b) nil) 471 | ((null a) t) 472 | (t 473 | (time-less-p 474 | (encode-time a) 475 | (encode-time b))))) 476 | 477 | (defun org-timeblock-decoded= (a b) 478 | "Return non-nil if A is earlier then B." 479 | (cond 480 | ;; nil is less than non-nil 481 | ((null b) nil) 482 | ((null a) t) 483 | (t 484 | (time-equal-p 485 | (encode-time a) 486 | (encode-time b))))) 487 | 488 | (defun org-timeblock-time< (a b) 489 | "Return non-nil if A's time is earlier then B's time. 490 | Compare only hours and minutes." 491 | (cond 492 | ;; nil is less than non-nil 493 | ((null b) nil) 494 | ((null a) t) 495 | (t 496 | (or (org-timeblock-on decoded-time-hour < a b) 497 | (and 498 | (org-timeblock-on decoded-time-hour = a b) 499 | (org-timeblock-on decoded-time-minute < a b)))))) 500 | 501 | (defun org-timeblock-date<= (a b) 502 | "Return non-nil if A's date is <= B's date." 503 | (cond 504 | ;; nil is less than non-nil 505 | ((null b) nil) 506 | ((null a) t) 507 | (t 508 | (or (org-timeblock-on decoded-time-year < a b) 509 | (and 510 | (org-timeblock-on decoded-time-year = a b) 511 | (or (org-timeblock-on decoded-time-month < a b) 512 | (and (org-timeblock-on decoded-time-month = a b) 513 | (org-timeblock-on decoded-time-day <= a b)))))))) 514 | 515 | (defsubst org-timeblock-get-ts (item) 516 | "Return ITEM's \\='timestamp text property as decoded time." 517 | (org-timeblock-timestamp-to-time (org-timeblock-get-ts-prop item))) 518 | 519 | (defsubst org-timeblock-get-saved-random-face (title) 520 | "Get saved random color face for TITLE. 521 | If not found, generate it with `org-timeblock--random-color', 522 | save it and return." 523 | (or (alist-get title org-timeblock-colors nil nil #'equal) 524 | (setf (alist-get title org-timeblock-colors nil nil #'equal) 525 | (org-timeblock--random-color)))) 526 | 527 | (defun org-timeblock-timestamp< (a b) 528 | "Return t, if A's \\='timestamp is less then B's." 529 | (org-timeblock-on org-timeblock-get-ts org-timeblock-time< a b)) 530 | 531 | (defun org-timeblock-select-block-for-current-entry () 532 | "Select block for the entry at point in `org-timeblock-list-mode'." 533 | (when-let (((get-buffer-window org-timeblock-buffer)) 534 | (timestamp (org-timeblock-get-ts-prop 535 | nil (line-beginning-position))) 536 | ((org-element-property :hour-start timestamp)) 537 | ((not (org-timeblock--daterangep timestamp))) 538 | (id (get-text-property (line-beginning-position) 'id)) 539 | (column-number 540 | (save-excursion 541 | (let ((count 0)) 542 | (while (not (bobp)) 543 | (while (not (eq (get-text-property (point) 'face) 544 | 'org-timeblock-list-header)) 545 | (forward-line -1)) 546 | (cl-incf count) 547 | (forward-line -1)) 548 | count))) 549 | (inhibit-read-only t)) 550 | (org-timeblock-unselect-block) 551 | (when-let ((node (car (dom-by-id org-timeblock-svg id)))) 552 | (dom-set-attribute node 'orig-fill (dom-attr node 'fill)) 553 | (dom-set-attribute 554 | node 'fill 555 | (face-attribute 556 | 'org-timeblock-select :background)) 557 | (dom-set-attribute node 'select t) 558 | (setq org-timeblock-column (dom-attr node 'column))) 559 | (with-current-buffer org-timeblock-buffer 560 | (org-timeblock-redisplay)))) 561 | 562 | (defun org-timeblock-intersect-p (entry1 entry2) 563 | "Return t, if two entries intersect each other. 564 | Otherwise, return nil. 565 | `ENTRY1',`ENTRY2' - strings returned from `org-timeblock-get-entries'." 566 | (when-let ((y1 (get-text-property 0 'y entry1)) 567 | (y2 (get-text-property 0 'y entry2))) 568 | (let ((y1-end (+ (get-text-property 0 'block-height entry1) y1)) 569 | (y2-end (+ (get-text-property 0 'block-height entry2) y2))) 570 | (or 571 | (= y2 y1) 572 | (and 573 | y2-end 574 | (< y2 y1) 575 | (< y1 y2-end)) 576 | (and 577 | y1-end 578 | (< y1 y2) 579 | (< y2 y1-end)))))) 580 | 581 | (defun org-timeblock--random-color () 582 | "Return random org-timeblock color face." 583 | (seq-random-elt 584 | '(org-timeblock-red 585 | org-timeblock-green 586 | org-timeblock-yellow 587 | org-timeblock-blue 588 | org-timeblock-magenta 589 | org-timeblock-cyan))) 590 | 591 | (defun org-timeblock--timestamp-relevant-p (timestamp date) 592 | "Check if org-element TIMESTAMP is relevant to DATE. 593 | DATE is decoded-time value." 594 | (let ((start-ts (org-timeblock-timestamp-to-time timestamp))) 595 | (or 596 | (org-timeblock-date= start-ts date) 597 | (when-let ((org-timeblock-show-future-repeats) 598 | (value (org-element-property 599 | :repeater-value timestamp)) 600 | (unit 601 | (pcase (org-element-property 602 | :repeater-unit timestamp) 603 | (`week 604 | (setq value (* value 7)) 605 | 'day) 606 | ((and _ u) u))) 607 | (start start-ts)) 608 | (or 609 | (and (eq unit 'day) 610 | (= value 1) 611 | (if (eq org-timeblock-show-future-repeats 'next) 612 | (org-timeblock-date= (org-timeblock-time-inc 'day 1 start) date) 613 | (org-timeblock-date<= start date))) 614 | (progn 615 | (if (eq org-timeblock-show-future-repeats 'next) 616 | (setq start (org-timeblock-time-inc unit value start)) 617 | (while (org-timeblock-date< start date) 618 | (setq start (org-timeblock-time-inc unit value start)))) 619 | (org-timeblock-date= start date)))) 620 | (when-let ((end-ts (org-timeblock-timestamp-to-time timestamp t))) 621 | (and (org-timeblock-date< start-ts date) 622 | (org-timeblock-date<= date end-ts)))))) 623 | 624 | (defun org-timeblock-redraw-timeblocks () 625 | "Redraw *org-timeblock* buffer." 626 | (with-current-buffer (get-buffer-create org-timeblock-buffer) 627 | (let ((inhibit-read-only t)) 628 | (erase-buffer) 629 | (if-let ((entries (org-timeblock-get-entries 630 | (car org-timeblock-daterange) 631 | (cdr org-timeblock-daterange) 632 | t)) 633 | (dates (org-timeblock-get-dates 634 | (car org-timeblock-daterange) 635 | (cdr org-timeblock-daterange))) 636 | (window (get-buffer-window org-timeblock-buffer)) 637 | ((setq org-timeblock-svg-height (window-body-height window t) 638 | org-timeblock-svg-width (window-body-width window t)))) 639 | (let* ((column-width (/ org-timeblock-svg-width (length dates))) 640 | (timeline-left-padding (* 2 (default-font-width))) 641 | (block-max-width (- column-width timeline-left-padding)) 642 | (max-hour (if (consp org-timeblock-scale-options) 643 | (if (= (cdr org-timeblock-scale-options) 24) 644 | 24 645 | (1+ (cdr org-timeblock-scale-options))) 646 | 24)) 647 | (cur-time (decode-time))) 648 | (setq org-timeblock-svg (svg-create org-timeblock-svg-width org-timeblock-svg-height)) 649 | (dotimes (iter (length dates)) 650 | (if-let ((entries 651 | (seq-filter 652 | (lambda (x) 653 | (let ((timestamp (org-timeblock-get-ts-prop x))) 654 | (and 655 | (org-timeblock--timestamp-relevant-p 656 | timestamp (nth iter dates)) 657 | (or (not (consp org-timeblock-scale-options)) 658 | (<= (car org-timeblock-scale-options) 659 | (org-element-property :hour-start timestamp) 660 | (cdr org-timeblock-scale-options)) 661 | (and 662 | (org-element-property :hour-end timestamp) 663 | (or (<= 664 | (org-element-property :hour-start timestamp) 665 | (car org-timeblock-scale-options) 666 | (org-element-property :hour-end timestamp)) 667 | (<= (car org-timeblock-scale-options) 668 | (org-element-property :hour-end timestamp) 669 | (cdr org-timeblock-scale-options)))))))) 670 | entries))) 671 | (let* ((order -1) 672 | (min-hour 673 | (pcase org-timeblock-scale-options 674 | ((pred consp) (car org-timeblock-scale-options)) 675 | (`nil 0) 676 | (_ (apply #'min (remove 677 | nil 678 | (append 679 | (list (unless (eq org-timeblock-scale-options 'hide-all) (decoded-time-hour (decode-time)))) 680 | (mapcar 681 | (lambda (entry) 682 | (let ((s-or-e (org-timeblock-get-ts-prop entry))) 683 | (if (and (org-timeblock-date< (org-timeblock-timestamp-to-time s-or-e) (nth iter dates)) 684 | (not (org-element-property :repeater-type s-or-e))) 685 | 0 686 | (org-element-property :hour-start s-or-e)))) 687 | entries))))))) 688 | (scale (/ org-timeblock-svg-height (float (* (- max-hour min-hour) 60)))) 689 | (cur-time-indicator 690 | (and org-timeblock-current-time-indicator 691 | (* scale 692 | (- 693 | (+ (* (decoded-time-hour cur-time) 60) 694 | (decoded-time-minute cur-time)) ;; minutes 695 | (* min-hour 60))))) 696 | (columns 697 | (mapcar (lambda (x) (cons (get-text-property 0 'id x) 1)) entries)) 698 | placed 699 | (hour-lines-color 700 | (face-attribute 'org-timeblock-hours-line :background nil t))) 701 | (dolist (entry entries) 702 | (let* ((timestamp (org-timeblock-get-ts-prop entry)) 703 | (repeated (org-element-property 704 | :repeater-type timestamp)) 705 | (start-ts (org-timeblock-timestamp-to-time 706 | timestamp)) 707 | (end-ts (org-timeblock-timestamp-to-time 708 | timestamp t)) 709 | (start-date-earlier-p (org-timeblock-date< 710 | start-ts (nth iter dates))) 711 | (end-date-later-p (org-timeblock-date< 712 | (nth iter dates) end-ts))) 713 | (add-text-properties 714 | 0 (length entry) 715 | `( time-string 716 | ,(and 717 | org-timeblock-display-time 718 | (or repeated (not 719 | (or end-date-later-p 720 | start-date-earlier-p))) 721 | (concat 722 | (org-timeblock-format-time " %H:%M" start-ts) 723 | (and end-ts (org-timeblock-format-time "-%H:%M" end-ts)) 724 | (and repeated 725 | (concat 726 | " " 727 | (pcase (org-element-property :repeater-type timestamp) 728 | (`cumulate "+") (`catch-up "++") (`restart ".+")) 729 | (let ((val (org-element-property :repeater-value timestamp))) 730 | (and val (number-to-string val))) 731 | (pcase (org-element-property :repeater-unit timestamp) 732 | (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))))) 733 | block-height 734 | ,(- (if (and start-ts end-ts) 735 | (max 736 | (default-font-height) 737 | (round 738 | (* (org-timeblock-time-diff 739 | (if (or (and end-date-later-p (not repeated)) 740 | (org-timeblock-decoded< 741 | (org-timeblock-time-apply 742 | (nth iter dates) 743 | :hour (1- max-hour) 744 | :minute 59 :second 0) 745 | (org-timeblock-time-apply 746 | (nth iter dates) 747 | :hour (decoded-time-hour end-ts) 748 | :minute (decoded-time-minute end-ts)))) 749 | (org-timeblock-time-apply 750 | (nth iter dates) 751 | :hour (1- max-hour) 752 | :minute 59 753 | :second 0) 754 | end-ts) 755 | (if (or (and start-date-earlier-p (not repeated)) 756 | (org-timeblock-decoded< 757 | (org-timeblock-time-apply 758 | (nth iter dates) 759 | :hour (decoded-time-hour start-ts) 760 | :minute (decoded-time-minute start-ts)) 761 | (org-timeblock-time-apply 762 | (nth iter dates) 763 | :hour min-hour :minute 0 764 | :second 0))) 765 | (org-timeblock-time-apply 766 | (nth iter dates) 767 | :hour min-hour :minute 0 768 | :second 0) 769 | start-ts)) 770 | scale))) 771 | (default-font-height)) 772 | (if (eq 'event (org-timeblock-get-ts-type entry)) 2 1)) 773 | y 774 | ,(if-let ((value (+ (round (* (if (or (and start-date-earlier-p (not repeated)) 775 | (org-timeblock-decoded< 776 | (org-timeblock-time-apply 777 | (nth iter dates) 778 | :hour (decoded-time-hour start-ts) 779 | :minute (decoded-time-minute start-ts)) 780 | (org-timeblock-time-apply 781 | (nth iter dates) 782 | :hour min-hour :minute 0 783 | :second 0))) 784 | 0 785 | (- (+ (* 60 (org-element-property :hour-start timestamp)) 786 | (org-element-property :minute-start timestamp)) 787 | (* min-hour 60))) 788 | scale)) 789 | (if (eq 'event (org-timeblock-get-ts-type entry)) 2 1))) 790 | ((< (- org-timeblock-svg-height value) (default-font-height)))) 791 | (- org-timeblock-svg-height (default-font-height)) 792 | value) 793 | n-day-indicator 794 | ,(and (not repeated) 795 | (cond 796 | ((and end-date-later-p start-date-earlier-p) "↕️") 797 | (end-date-later-p "⬇️") 798 | (start-date-earlier-p "⬆️")))) 799 | entry))) 800 | ;; Timeblocks layout algorithm 801 | (dolist (entry entries) 802 | (let ((id (get-text-property 0 'id entry))) 803 | (push entry placed) 804 | (setcdr (assoc id columns) 805 | (catch 'found-column 806 | (let ((k 1)) 807 | (while t 808 | (catch 'next-column 809 | (dolist (el (seq-filter 810 | (lambda (x) 811 | (eq (cdr (assoc (get-text-property 0 'id x) columns)) k)) 812 | placed)) 813 | (and (not (string= (get-text-property 0 'id el) id)) 814 | (org-timeblock-intersect-p entry el) 815 | (cl-incf k) 816 | (throw 'next-column t))) 817 | (throw 'found-column k)))))))) 818 | ;; Drawing hour lines 819 | (let ((lines-iter (if (> min-hour 0) (1- min-hour) 0)) y) 820 | (while (< (cl-incf lines-iter) max-hour) 821 | (setq y (round (* scale (- lines-iter min-hour) 60))) 822 | (svg-line 823 | org-timeblock-svg 824 | (+ timeline-left-padding (* column-width iter)) 825 | y 826 | (+ column-width (* column-width iter)) 827 | y 828 | :stroke-dasharray "4" 829 | :stroke hour-lines-color) 830 | (svg-text 831 | org-timeblock-svg (format "%d" lines-iter) 832 | :y (+ y 5) 833 | :x (* column-width iter) 834 | :fill (face-attribute 'default :foreground)))) 835 | ;; Drawing current time indicator 836 | (and cur-time-indicator 837 | (org-timeblock-date= (nth iter dates) cur-time) 838 | (svg-line 839 | org-timeblock-svg 840 | (* column-width iter) 841 | cur-time-indicator 842 | (+ column-width (* column-width iter)) 843 | cur-time-indicator 844 | :stroke (face-attribute 845 | 'org-timeblock-current-time-indicator 846 | :background nil t))) 847 | ;; Drawing all the entries inside the timeline 848 | (dolist (entry entries) 849 | (when-let ((length 850 | (1+ (length 851 | (seq-uniq 852 | (mapcar 853 | ;; get columns for those entries 854 | (lambda (x) 855 | (cdr (assoc (get-text-property 0 'id x) columns))) 856 | ;; find those with which current entry is in intersection 857 | (seq-filter 858 | (lambda (x) 859 | (unless 860 | (equal 861 | (get-text-property 0 'id entry) 862 | (get-text-property 0 'id x)) 863 | (org-timeblock-intersect-p entry x))) 864 | entries)) 865 | #'eq)))) 866 | (y (get-text-property 0 'y entry)) 867 | (block-height 868 | (get-text-property 0 'block-height entry)) 869 | ((> (+ y block-height) 0)) 870 | (x (+ (+ timeline-left-padding 871 | (round 872 | (* (1- (cdr 873 | (assoc 874 | (get-text-property 0 'id entry) 875 | columns))) 876 | (/ block-max-width length)))) 877 | (* column-width iter) 878 | (if (eq 'event (org-timeblock-get-ts-type entry)) 2 1))) 879 | (block-width 880 | (- (round (/ block-max-width length)) 881 | (if (eq 'event (org-timeblock-get-ts-type entry)) 2 1))) 882 | (title 883 | (concat (get-text-property 0 'title entry) 884 | (get-text-property 0 'n-day-indicator entry))) 885 | ;; Splitting the title of an entry 886 | (heading-list 887 | (if (> (* (length title) (default-font-width)) 888 | block-width) 889 | (seq-take 890 | (seq-partition title (/ block-width (default-font-width))) 891 | (let ((lines-count 892 | (round 893 | (/ block-height (default-font-height))))) 894 | (if (= 0 lines-count) 1 lines-count))) 895 | `(,title)))) 896 | (let ((time-string 897 | (get-text-property 0 'time-string entry)) 898 | (face (org-timeblock-get-colors 899 | (get-text-property 0 'tags entry)))) 900 | (when (< (/ block-width (default-font-width)) 901 | (length time-string)) 902 | (setq time-string nil)) 903 | (when-let ((time-string) 904 | ((< (- block-height 905 | (* (length heading-list) (default-font-height))) 906 | (- (default-font-height) 6))) 907 | (diff (- 908 | (+ (length (car (last heading-list))) 909 | (length time-string)) 910 | (/ block-width (default-font-width)))) 911 | ((> diff 0))) 912 | (cl-callf 913 | (lambda (x) 914 | (if (> (- (length x) diff) 10) 915 | (substring x 0 (- diff)) 916 | (setq time-string nil) 917 | x)) 918 | (car (last heading-list)))) 919 | (push (list (get-text-property 0 'id entry) 920 | (get-text-property 0 'marker entry)) 921 | org-timeblock-data) 922 | ;; Appending generated rectangle for current entry 923 | (svg-rectangle 924 | org-timeblock-svg x y block-width block-height 925 | :column (1+ iter) 926 | :stroke 927 | (if (eq 'event (org-timeblock-get-ts-type entry)) 928 | "#5b0103" "#cdcdcd") 929 | :stroke-width 930 | (if (eq 'event (org-timeblock-get-ts-type entry)) 931 | 2 1) 932 | :opacity "0.7" 933 | :order (cl-incf order) 934 | :fill 935 | (or 936 | (and 937 | (eq 'deadline (org-timeblock-get-ts-type entry)) 938 | "#5b0103") 939 | (and face (face-attribute face :background nil 'default)) 940 | (face-attribute 941 | (org-timeblock-get-saved-random-face title) 942 | :background nil 'default)) 943 | ;; Same timestamp can be displayed in multiple 944 | ;; columns, so _column-number postfix is used to tell 945 | ;; that blocks apart 946 | :id (format "%s_%d" 947 | (get-text-property 0 'id entry) 948 | (1+ iter)) 949 | :type (org-timeblock-get-ts-type entry)) 950 | ;; Setting the title of current entry 951 | (let ((y (- y 5))) 952 | (dolist (heading-part heading-list) 953 | (svg-text org-timeblock-svg heading-part 954 | :x x 955 | :y (cl-incf y (default-font-height)) 956 | :fill 957 | (or 958 | (and 959 | (eq 'deadline (org-timeblock-get-ts-type entry)) 960 | "#ffffff") 961 | (and face (face-attribute face :foreground nil 'default)) 962 | (face-attribute 963 | (org-timeblock-get-saved-random-face title) 964 | :foreground nil 'default)) 965 | :font-size 966 | (aref (font-info (face-font 'default)) 2)))) 967 | (when time-string 968 | (svg-text org-timeblock-svg time-string 969 | :x (- (+ x block-width) 970 | (* (length time-string) 971 | (default-font-width))) 972 | :y (- (+ y block-height) 2) 973 | :fill 974 | (or 975 | (and 976 | (eq 'deadline 977 | (org-timeblock-get-ts-type entry)) 978 | "#ffffff") 979 | (and face (face-attribute face :foreground nil 'default)) 980 | hour-lines-color) 981 | :font-size 982 | (aref (font-info (face-font 'default)) 2))))))) 983 | (let ((message "No data.")) 984 | (svg-text org-timeblock-svg message 985 | :y (/ org-timeblock-svg-height 2) 986 | :x (+ (- (/ column-width 2) 987 | (/ (* (default-font-width) 988 | (length message)) 989 | 2)) 990 | (* column-width iter)) 991 | :fill (face-attribute 'default :foreground) 992 | :font-size 993 | (aref (font-info (face-font 'default)) 2))))) 994 | (svg-insert-image org-timeblock-svg)) 995 | (let* ((window (get-buffer-window org-timeblock-buffer)) 996 | (window-height (window-body-height window t)) 997 | (window-width (window-body-width window t)) 998 | (message "No data.")) 999 | (setq org-timeblock-svg (svg-create window-width window-height)) 1000 | (svg-text 1001 | org-timeblock-svg message 1002 | :y (/ window-height 2) 1003 | :x (- (/ window-width 2) 1004 | (/ (* (default-font-width) (length message)) 2)) 1005 | :fill (face-attribute 'default :foreground)) 1006 | (svg-insert-image org-timeblock-svg))) 1007 | (setq org-timeblock-mark-count 0) 1008 | (org-timeblock-redisplay)))) 1009 | 1010 | (defun org-timeblock-redisplay () 1011 | "Redisplay *org-timeblock* buffer." 1012 | (let ((inhibit-read-only t)) 1013 | (when-let ((window (get-buffer-window org-timeblock-buffer))) 1014 | (if (or (< (window-body-height window t) org-timeblock-svg-height) 1015 | (< (window-body-width window t) org-timeblock-svg-width)) 1016 | (org-timeblock-redraw-timeblocks) 1017 | (setq header-line-format 1018 | (let* ((dates (org-timeblock-get-dates 1019 | (car org-timeblock-daterange) 1020 | (cdr org-timeblock-daterange))) 1021 | (left-fringe (/ (car (window-fringes window)) 1022 | (default-font-width))) 1023 | (max-length (/ (+ (/ (window-body-width window t) 1024 | (default-font-width)) 1025 | left-fringe) 1026 | (length dates))) 1027 | (date-format 1028 | (pcase max-length 1029 | ((pred (< 15)) "[%Y-%m-%d %a]") 1030 | ((pred (< 11)) "[%Y-%m-%d]") 1031 | ((pred (< 6)) "[%m-%d]") 1032 | ((pred (< 3)) "[%d]"))) 1033 | (right-margin (format "%% -%ds" max-length)) 1034 | (result (make-string left-fringe ? ))) 1035 | (dotimes (iter (length dates)) 1036 | (cl-callf concat result 1037 | (propertize 1038 | (format right-margin 1039 | (org-timeblock-format-time date-format (nth iter dates))) 1040 | 'face 1041 | (and (= org-timeblock-column (1+ iter)) 1042 | 'org-timeblock-select)))) 1043 | result)))) 1044 | (svg-possibly-update-image org-timeblock-svg))) 1045 | 1046 | (defun org-timeblock-show-timeblocks () 1047 | "Switch to *org-timeblock* buffer in another window." 1048 | (switch-to-buffer-other-window org-timeblock-buffer) 1049 | (other-window 1)) 1050 | 1051 | (defun org-timeblock-show-timeblock-list () 1052 | "Switch to *org-timeblock-list* buffer in another window." 1053 | (switch-to-buffer-other-window org-timeblock-list-buffer) 1054 | (other-window 1)) 1055 | 1056 | (defun org-timeblock-quit () 1057 | "Exit `org-timeblock-list-mode'." 1058 | (interactive) 1059 | (quit-window t)) 1060 | 1061 | (defun org-timeblock--schedule-time (&optional marker) 1062 | "Interactively change time in DATE for Org entry timestamp at MARKER. 1063 | If MARKER is nil, use entry at point. 1064 | If DATE is not specified, use `org-timeblock-date'. 1065 | 1066 | Date won't be changed. The time might be a 1067 | timerange which depends on user choice. 1068 | 1069 | Time format is \"HHMM\"" 1070 | (when marker 1071 | (unless (marker-buffer marker) 1072 | (user-error "Non-existent marker's buffer"))) 1073 | (org-with-point-at (or marker (point)) 1074 | (org-timeblock-show-context) 1075 | (let* (ts-type 1076 | go-back-p 1077 | prev-date 1078 | (timestamp (org-element-timestamp-parser)) 1079 | (date (org-timeblock-timestamp-to-time timestamp))) 1080 | (while (null ts-type) 1081 | (pcase (read-char-from-minibuffer 1082 | "Change timestamp: time[s]tamp, time[r]ange, other [d]ay" 1083 | '(?s ?r ?d)) 1084 | (?r (setq ts-type 'timerange)) 1085 | (?s (setq ts-type 'timestamp)) 1086 | (?d (setq prev-date date 1087 | date (decode-time (org-read-date nil t nil nil (encode-time date)))) 1088 | (unless (and 1089 | (org-timeblock-date<= 1090 | date (cdr org-timeblock-daterange)) 1091 | (org-timeblock-date<= 1092 | (car org-timeblock-daterange) date)) 1093 | (org-timeblock-jump-to-day date) 1094 | (setq go-back-p t))))) 1095 | (let* ((start-ts (org-timeblock-timestamp-to-time timestamp)) 1096 | (end-ts (org-timeblock-timestamp-to-time timestamp t)) 1097 | (duration (when (and start-ts end-ts) 1098 | (org-timeblock-time-diff end-ts start-ts))) 1099 | (new-start-ts (org-timeblock-read-ts date "START-TIME: ")) 1100 | (new-end-ts 1101 | (if (eq ts-type 'timerange) 1102 | (let (ts) 1103 | (while (progn (setq ts (org-timeblock-read-ts date "END-TIME: ")) 1104 | (org-timeblock-decoded< ts new-start-ts)) 1105 | (ding)) 1106 | ts) 1107 | (when duration (org-timeblock-time-inc 1108 | 'minute duration new-start-ts))))) 1109 | (when (and prev-date go-back-p) 1110 | (org-timeblock-jump-to-day prev-date)) 1111 | (org-timeblock--schedule new-start-ts new-end-ts))))) 1112 | 1113 | (defun org-timeblock--daterangep (timestamp) 1114 | "Return t if org timestamp object TIMESTAMP is a daterange with no time." 1115 | (when-let ((day-end (org-element-property :day-end timestamp)) 1116 | (month-end (org-element-property :month-end timestamp)) 1117 | (year-end (org-element-property :year-end timestamp))) 1118 | (and 1119 | (or 1120 | (/= (org-element-property :day-start timestamp) day-end) 1121 | (/= (org-element-property :month-start timestamp) month-end) 1122 | (/= (org-element-property :year-start timestamp) year-end)) 1123 | (null (org-element-property :hour-start timestamp)) 1124 | (null (org-element-property :hour-end timestamp))))) 1125 | 1126 | (defun org-timeblock--construct-prefix (timestamp type) 1127 | "Construct prefix for TIMESTAMP of type TYPE. 1128 | 1129 | TIMESTAMP is org-element timestamp object which is used to 1130 | construct a timerange inside the prefix." 1131 | (let ((hstart (org-element-property :hour-start timestamp)) 1132 | (mstart (org-element-property :minute-start timestamp)) 1133 | (hend (org-element-property :hour-end timestamp)) 1134 | (mend (org-element-property :minute-end timestamp)) 1135 | (type-str (pcase type 1136 | (`event "EVENT") 1137 | (`sched "SCHED") 1138 | (`deadline "DEADL")))) 1139 | (propertize 1140 | (format 1141 | " %s % -12s % -6s " 1142 | type-str 1143 | (if (org-timeblock--daterangep timestamp) 1144 | "" 1145 | (concat (and hstart mstart 1146 | (format 1147 | "%02d:%02d" 1148 | hstart 1149 | mstart)) 1150 | (and hend mend 1151 | (or (/= hend hstart) 1152 | (/= mend mstart)) 1153 | (format 1154 | "-%02d:%02d" 1155 | hend 1156 | mend)))) 1157 | (concat 1158 | "" 1159 | (pcase (org-element-property :repeater-type timestamp) 1160 | (`cumulate "+") (`catch-up "++") (`restart ".+")) 1161 | (when-let ((val (org-element-property :repeater-value timestamp))) 1162 | (number-to-string val)) 1163 | (pcase (org-element-property :repeater-unit timestamp) 1164 | (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))) 1165 | 'prefix t))) 1166 | 1167 | (cl-defun org-timeblock-read-ts (ts &optional (prompt "TIME:")) 1168 | "Read a time in \"HHMM\" format and apply it to TS. 1169 | Return the changed time struct. 1170 | 1171 | PROMPT can overwrite the default prompt." 1172 | (let (time) 1173 | (catch 'exit 1174 | (while t 1175 | (let ((len (length time)) 1176 | (ch (read-char-exclusive 1177 | (concat "[format: HHMM] " prompt (reverse time))))) 1178 | (cond 1179 | ((or (and (= len 0) (<= ?0 ch ?2)) 1180 | (and (= len 1) 1181 | (if (< (car time) ?2) (<= ?0 ch ?9) (<= ?0 ch ?3))) 1182 | (and (= len 2) (<= ?0 ch ?5))) 1183 | (push ch time)) 1184 | ((and (= len 3) (<= ?0 ch ?9)) 1185 | (push ch time) 1186 | (throw 'exit t)) 1187 | ((and (/= len 0) (eq ch ?\C-?)) 1188 | (pop time)) 1189 | (t (ding)))))) 1190 | (cl-macrolet ((pop-digit () '(- (pop time) 48))) 1191 | (org-timeblock-time-apply 1192 | ts 1193 | :minute (+ (pop-digit) (* 10 (pop-digit))) 1194 | :hour (+ (pop-digit) (* 10 (pop-digit))))))) 1195 | 1196 | (defun org-timeblock-construct-id (&optional marker) 1197 | "Construct identifier for the timestamp at MARKER. 1198 | If MARKER is nil, use timestamp at point." 1199 | (org-with-point-at (or marker (point)) 1200 | (md5 1201 | (format 1202 | "%s%d%s" 1203 | (buffer-file-name (buffer-base-buffer)) 1204 | (point) 1205 | (when (or (looking-at org-tr-regexp) 1206 | (looking-at org-ts-regexp)) 1207 | (match-string 0))) 1208 | nil nil 'utf-8))) 1209 | 1210 | (defun org-timeblock-files () 1211 | "Get a list of files in which tasks are searched." 1212 | (pcase org-timeblock-files 1213 | (`agenda (org-agenda-files)) 1214 | ((and list (pred listp)) list))) 1215 | 1216 | (defun org-timeblock-get-buffer-entries-all (buffer) 1217 | "Get all not done and not archived entries with any active timestamp in BUFFER." 1218 | (let (entries tags 1219 | update-markers-alist-p 1220 | (buffer-markers 1221 | (alist-get buffer 1222 | org-timeblock-markers nil nil #'equal))) 1223 | (with-current-buffer buffer 1224 | (org-with-wide-buffer 1225 | (goto-char (point-min)) 1226 | (while (re-search-forward org-tsr-regexp nil t) 1227 | (if (save-match-data 1228 | (or (org-entry-is-done-p) 1229 | (progn 1230 | (setq tags 1231 | (mapcar #'substring-no-properties 1232 | (org-get-tags))) 1233 | (member org-archive-tag tags)))) 1234 | (org-get-next-sibling) 1235 | (when-let 1236 | ((timestamp-and-type 1237 | (save-excursion 1238 | (goto-char (match-beginning 0)) 1239 | (list 1240 | (org-element-timestamp-parser) 1241 | (save-excursion 1242 | (cond 1243 | ((re-search-backward 1244 | (concat org-scheduled-regexp "[ \t]*\\=") 1245 | nil 1246 | t) 1247 | 'sched) 1248 | ((re-search-backward 1249 | (concat org-deadline-regexp "[ \t]*\\=") 1250 | nil 1251 | t) 1252 | 'deadline) 1253 | (t 'event))) 1254 | (or (seq-find (lambda (x) (= x (point))) buffer-markers) 1255 | (let ((marker (copy-marker (point) t))) 1256 | (setq update-markers-alist-p t) 1257 | (push marker buffer-markers) 1258 | marker))))) 1259 | (timestamp (car timestamp-and-type)) 1260 | (type (cadr timestamp-and-type)) 1261 | (marker (caddr timestamp-and-type)) 1262 | (start-ts (org-timeblock-timestamp-to-time 1263 | timestamp)) 1264 | (title (or (org-get-heading t nil t t) "no title"))) 1265 | (save-excursion 1266 | (org-back-to-heading-or-point-min t) 1267 | (push 1268 | (propertize 1269 | (concat 1270 | (org-timeblock--construct-prefix timestamp type) 1271 | title) 1272 | 'type type 1273 | 'timestamp timestamp 1274 | 'marker marker 1275 | 'tags tags 1276 | 'id (org-timeblock-construct-id marker) 1277 | 'title title) 1278 | entries))))))) 1279 | (when update-markers-alist-p 1280 | (setf 1281 | (alist-get buffer 1282 | org-timeblock-markers nil nil #'equal) 1283 | buffer-markers)) 1284 | entries)) 1285 | 1286 | (defun org-timeblock-get-entries (from to &optional timeblocks) 1287 | "Return scheduled tasks or events in [FROM;TO] timerange. 1288 | FROM and TO are decoded-time values. 1289 | 1290 | When TIMEBLOCKS is non-nil, exclude entries with daterange or 1291 | without time." 1292 | (org-timeblock-update-cache) 1293 | (seq-filter 1294 | (lambda (x) 1295 | (when-let 1296 | ((timestamp (org-timeblock-get-ts-prop x)) 1297 | ((or (not timeblocks) 1298 | (and 1299 | (not (org-timeblock--daterangep timestamp)) 1300 | (org-element-property :hour-start timestamp)))) 1301 | (start-ts (org-timeblock-timestamp-to-time 1302 | timestamp))) 1303 | (or 1304 | (and 1305 | (org-element-property 1306 | :repeater-type timestamp) 1307 | (org-timeblock-date<= start-ts from)) 1308 | (and 1309 | (org-timeblock-date<= from start-ts) 1310 | (org-timeblock-date<= start-ts to)) 1311 | (let ((end-ts 1312 | (org-timeblock-timestamp-to-time 1313 | timestamp t))) 1314 | (and 1315 | end-ts 1316 | (org-timeblock-date<= from end-ts) 1317 | (org-timeblock-date<= end-ts to)))))) 1318 | org-timeblock-cache)) 1319 | 1320 | (defun org-timeblock-update-cache () 1321 | "Update org-timeblock-cache. 1322 | Return nil if buffers are up-to-date." 1323 | (when-let 1324 | ((buffers-to-update 1325 | (mapcar 1326 | #'find-file-noselect 1327 | ;; This code is partially borrowed from `org-ql--select-cached' 1328 | ;; function which is part of org-ql project written by Adam Porter 1329 | (seq-filter 1330 | (lambda (file) 1331 | (let* ((buffer (find-file-noselect file)) 1332 | (modified-tick 1333 | (alist-get file org-timeblock-buffers nil nil #'equal)) 1334 | (new-modified-tick (buffer-chars-modified-tick buffer))) 1335 | (and (not (eq new-modified-tick modified-tick)) 1336 | (setf 1337 | (alist-get file org-timeblock-buffers nil nil #'equal) 1338 | new-modified-tick)))) 1339 | (org-timeblock-files))))) 1340 | (setq org-timeblock-cache 1341 | (sort 1342 | (apply 1343 | #'append 1344 | (seq-remove 1345 | (lambda (x) 1346 | (member (marker-buffer (get-text-property 0 'marker x)) 1347 | buffers-to-update)) 1348 | org-timeblock-cache) 1349 | (mapcar 1350 | #'org-timeblock-get-buffer-entries-all 1351 | buffers-to-update)) 1352 | #'org-timeblock-timestamp<)) 1353 | t)) 1354 | 1355 | (defun org-timeblock-get-colors (tags) 1356 | "Return face for TAGS." 1357 | (catch 'found 1358 | (dolist (tag tags) 1359 | (when-let ((colors (cdr (seq-find (lambda (x) (string= (car x) tag)) 1360 | org-timeblock-tag-colors)))) 1361 | (throw 'found colors))))) 1362 | 1363 | (defun org-timeblock-timestamp-to-time (ts &optional end) 1364 | "Convert TS into an Emacs decoded time value. 1365 | If END is non-nil, use end part of the timestamp. 1366 | 1367 | TS is a org-element timestamp object." 1368 | (let ((year-start (org-element-property :year-start ts)) 1369 | (month-start (org-element-property :month-start ts)) 1370 | (day-start (org-element-property :day-start ts)) 1371 | (hour-start (org-element-property :hour-start ts)) 1372 | (minute-start (org-element-property :minute-start ts))) 1373 | (if end 1374 | (when-let ((year-end (org-element-property :year-end ts)) 1375 | (month-end (org-element-property :month-end ts)) 1376 | (day-end (org-element-property :day-end ts))) 1377 | (let ((hour-end (org-element-property :hour-end ts)) 1378 | (minute-end (org-element-property :minute-end ts))) 1379 | (when (or 1380 | (/= day-start day-end) 1381 | (/= month-start month-end) 1382 | (/= year-start year-end) 1383 | (and hour-end hour-start (/= hour-start hour-end)) 1384 | (and minute-end minute-start (/= minute-start minute-end))) 1385 | (make-decoded-time 1386 | :year year-end :month month-end :day day-end 1387 | :hour (or hour-end 0) :minute (or minute-end 0) :second 0)))) 1388 | (make-decoded-time 1389 | :year year-start :month month-start :day day-start 1390 | :hour (or hour-start 0) :minute (or minute-start 0) :second 0)))) 1391 | 1392 | (defun org-timeblock--schedule (start-ts &optional end-ts) 1393 | "Schedule org entry at point. 1394 | START-TS and END-TS are Emacs decoded time values. 1395 | 1396 | Return new org-element timestamp object." 1397 | (let* ((planning-func 1398 | (cond ((save-excursion 1399 | (re-search-backward 1400 | (concat org-deadline-regexp "[ \t]*\\=") 1401 | nil 1402 | t)) 1403 | #'org-deadline) 1404 | ((save-excursion 1405 | (re-search-backward 1406 | (concat org-scheduled-regexp "[ \t]*\\=") 1407 | nil 1408 | t)) 1409 | #'org-schedule))) 1410 | (regexp-with-ts 1411 | (if (eq planning-func #'org-schedule) 1412 | org-scheduled-time-regexp 1413 | org-deadline-time-regexp)) 1414 | (keyword-regexp 1415 | (concat 1416 | (if (eq planning-func #'org-schedule) 1417 | org-scheduled-regexp 1418 | org-deadline-regexp) 1419 | "[ \t]*"))) 1420 | (if planning-func 1421 | (save-excursion 1422 | (let* ((timestamp (org-element-timestamp-parser)) 1423 | (repeat-string (org-get-repeat 1424 | (org-element-property :raw-value timestamp))) 1425 | (warning-string 1426 | (concat 1427 | (pcase (org-element-property :warning-type timestamp) 1428 | (`first "--") (`all "-")) 1429 | (let ((val (org-element-property :warning-value timestamp))) 1430 | (and val (number-to-string val))) 1431 | (pcase (org-element-property :warning-unit timestamp) 1432 | (`hour "h") (`day "d") (`week "w") (`month "m") (`year "y")))) 1433 | (dates-equal-p (org-timeblock-date= start-ts end-ts))) 1434 | (cond 1435 | ((or (not end-ts) dates-equal-p) 1436 | (funcall-interactively 1437 | planning-func nil 1438 | (org-timeblock-ts-to-org-timerange start-ts end-ts))) 1439 | ((and end-ts (not dates-equal-p)) 1440 | (funcall-interactively 1441 | planning-func nil 1442 | (org-timeblock-ts-to-org-timerange start-ts)) 1443 | (when (re-search-forward 1444 | regexp-with-ts 1445 | (line-end-position) t) 1446 | (insert "--" 1447 | (org-timeblock-ts-to-org-timerange 1448 | end-ts 1449 | nil repeat-string warning-string))))) 1450 | (org-back-to-heading t) 1451 | (forward-line) 1452 | (re-search-forward keyword-regexp (line-end-position) t) 1453 | (org-element-timestamp-parser))) 1454 | (when (or (looking-at org-tr-regexp) 1455 | (looking-at org-ts-regexp)) 1456 | (replace-match 1457 | (org-timeblock-ts-to-org-timerange start-ts end-ts))) 1458 | (org-element-timestamp-parser)))) 1459 | 1460 | (defun org-timeblock-ts-to-org-timerange 1461 | (ts-start &optional ts-end repeat-string warning-string) 1462 | "Create an Org timestamp range string. 1463 | 1464 | TS-START and TS-END are decoded time values. 1465 | REPEAT-STRING is a repeater string. 1466 | WARNING-STRING is a warning string of the form \"-[0-9]+[hdwmy]\"" 1467 | (when-let ((start-date (org-timeblock-format-time "%Y-%m-%d %a" ts-start))) 1468 | (let ((start-time 1469 | (and (decoded-time-hour ts-start) 1470 | (decoded-time-minute ts-start) 1471 | (org-timeblock-format-time "%R" ts-start))) 1472 | (end-date (and ts-end (org-timeblock-format-time 1473 | "%Y-%m-%d %a" ts-end))) 1474 | (end-time (and ts-end 1475 | (and (decoded-time-hour ts-end) 1476 | (decoded-time-minute ts-end) 1477 | (org-timeblock-format-time "%R" ts-end)))) 1478 | (timestamp-end 1479 | (concat 1480 | (and (org-string-nw-p repeat-string) (concat " " repeat-string)) 1481 | (and (org-string-nw-p warning-string) (concat " " warning-string)) 1482 | ">"))) 1483 | (concat 1484 | "<" start-date (and start-time (concat " " start-time)) 1485 | (if (equal end-date start-date) 1486 | (and end-time (not (equal end-time start-time)) 1487 | (concat "-" end-time)) 1488 | (and 1489 | end-date 1490 | (concat 1491 | timestamp-end 1492 | "--<" end-date 1493 | (and end-time (concat " " end-time))))) 1494 | timestamp-end)))) 1495 | 1496 | (defun org-timeblock-read-duration () 1497 | "Read time duration and return minutes as an integer. 1498 | 1499 | Beep or flash the screen when an invalid character is typed. The 1500 | prompt shows currently valid characters for the next input 1501 | character. 1502 | 1503 | Valid duration formats: 1504 | 2h 1505 | 2h30m 1506 | 2h30 1507 | 45 1508 | 1d 1509 | 1w3h30m" 1510 | (let* ((dur "") 1511 | (all-multipliers (mapcar #'car org-timeblock-duration-multipliers)) 1512 | (valid-multipliers all-multipliers) 1513 | typed-multipliers) 1514 | (catch 'dur 1515 | (while-let ((multipliers 1516 | (apply #'propertize 1517 | (concat "[" valid-multipliers "]") 1518 | (and (or (length= dur 0) 1519 | (member (string-to-char (substring dur -1)) 1520 | all-multipliers)) 1521 | '(face org-agenda-dimmed-todo-face)))) 1522 | (ch (read-char-exclusive 1523 | (concat "DURATION ([0-9]+" multipliers "):" dur)))) 1524 | (cond 1525 | ((<= ?0 ch ?9) 1526 | (setq dur (format "%s%c" dur ch))) 1527 | ((or (and (eq ch ?\C-m) (length> dur 0)) 1528 | (and (member ch valid-multipliers) 1529 | (string-match-p "[0-9]+$" dur))) 1530 | (when-let (((member ch '(?m ?\C-m))) 1531 | (minutes 0) 1532 | (start 0)) 1533 | (setq dur (concat dur "m")) 1534 | (while (string-match 1535 | (concat "\\([0-9]+\\)\\([" typed-multipliers "m]\\)") 1536 | dur start) 1537 | (cl-incf minutes (* (cdr 1538 | (assq (string-to-char (match-string 2 dur)) 1539 | org-timeblock-duration-multipliers)) 1540 | (string-to-number (match-string 1 dur)))) 1541 | (setq start (match-end 0))) 1542 | (throw 'dur minutes)) 1543 | (setq dur (format "%s%c" dur ch) 1544 | valid-multipliers (cdr (member ch valid-multipliers))) 1545 | (push ch typed-multipliers)) 1546 | ((and (eq ?\C-? ch) (not (length= dur 0))) 1547 | (when (eq (string-to-char (substring dur -1)) (car typed-multipliers)) 1548 | (pop typed-multipliers) 1549 | (setq valid-multipliers 1550 | (let ((ms all-multipliers)) 1551 | (when typed-multipliers 1552 | (while (not (eq (pop ms) (car typed-multipliers))))) 1553 | ms))) 1554 | (setq dur (substring dur 0 -1))) 1555 | (t (ding))))))) 1556 | 1557 | (defun org-timeblock--duration (duration marker) 1558 | "Set SCHEDULED duration to DURATION for the org entry at MARKER. 1559 | Change SCHEDULED timestamp duration of the org entry at MARKER. 1560 | Return the changed org-element timestamp object." 1561 | (unless (marker-buffer marker) 1562 | (user-error "Non-existent marker's buffer")) 1563 | (org-with-point-at marker 1564 | (org-timeblock-show-context) 1565 | (let ((timestamp (org-element-timestamp-parser))) 1566 | (unless (and (org-element-property :hour-start timestamp) 1567 | (org-element-property :minute-start timestamp)) 1568 | (user-error "The timestamp does not have time")) 1569 | (let* ((start-ts (org-timeblock-timestamp-to-time timestamp)) 1570 | (new-end-ts (org-timeblock-time-inc 1571 | 'minute duration start-ts))) 1572 | (org-timeblock--schedule start-ts new-end-ts))))) 1573 | 1574 | (defun org-timeblock-todo (&optional arg) 1575 | "Change the TODO state of an item in org-timeblock. 1576 | 1577 | Check `org-todo' for more information, including on the values of 1578 | ARG." 1579 | (interactive "P") 1580 | (when-let ((marker (pcase major-mode 1581 | (`org-timeblock-list-mode 1582 | (get-text-property (line-beginning-position) 'marker)) 1583 | (`org-timeblock-mode 1584 | (org-timeblock-selected-block-marker))))) 1585 | (org-with-point-at marker 1586 | (funcall-interactively #'org-todo arg)) 1587 | (org-timeblock-redraw-buffers))) 1588 | 1589 | ;;;; Main commands 1590 | 1591 | ;;;###autoload 1592 | (defun org-timeblock-list () 1593 | "Enter `org-timeblock-list-mode'." 1594 | (interactive) 1595 | (switch-to-buffer org-timeblock-list-buffer) 1596 | (setq org-timeblock-daterange 1597 | (cons (decode-time) 1598 | (org-timeblock-time-inc 'day (1- org-timeblock-span) 1599 | (decode-time)))) 1600 | (org-timeblock-redraw-buffers)) 1601 | 1602 | ;;;###autoload 1603 | (defun org-timeblock () 1604 | "Enter `org-timeblock-mode'." 1605 | (interactive) 1606 | (switch-to-buffer org-timeblock-buffer) 1607 | (org-timeblock-mode) 1608 | (org-timeblock-redraw-buffers)) 1609 | 1610 | ;;;; Planning commands 1611 | 1612 | (defun org-timeblock-clock-in (&optional select) 1613 | "Start the clock on the currently selected block. 1614 | See `org-clock-in' to read about what tasks selection options 1615 | SELECT prefix argument provides." 1616 | (interactive "P") 1617 | (if (equal select '(4)) 1618 | (org-clock-in select) 1619 | (when-let ((marker (org-timeblock-selected-block-marker))) 1620 | (org-with-point-at marker 1621 | (org-timeblock-show-context) 1622 | (org-clock-in select))))) 1623 | 1624 | (defun org-timeblock-list-clock-in (&optional select) 1625 | "Start the clock on the item at point. 1626 | See `org-clock-in' to read about what tasks selection options 1627 | SELECT prefix argument provides." 1628 | (interactive "P") 1629 | (if (equal select '(4)) 1630 | (org-clock-in select) 1631 | (when-let ((marker (get-text-property (line-beginning-position) 'marker))) 1632 | (org-with-point-at marker 1633 | (org-timeblock-show-context) 1634 | (org-clock-in select))))) 1635 | 1636 | (defun org-timeblock-list-get-current-date () 1637 | "Get date at point." 1638 | (save-excursion 1639 | (while (not (eq (get-text-property (point) 'face) 1640 | 'org-timeblock-list-header)) 1641 | (forward-line -1)) 1642 | (parse-time-string (buffer-substring 1643 | (line-beginning-position) (line-end-position))))) 1644 | 1645 | (cl-defun org-timeblock-new-task 1646 | (&optional (date (pcase major-mode 1647 | (`org-timeblock-mode 1648 | (nth (1- org-timeblock-column) 1649 | (org-timeblock-get-dates 1650 | (car org-timeblock-daterange) 1651 | (cdr org-timeblock-daterange)))) 1652 | (`org-timeblock-list-mode 1653 | (org-timeblock-list-get-current-date))))) 1654 | "Create a task scheduled to DATE. 1655 | If DATE is nil, use the date in the current view. 1656 | 1657 | The new task is created in `org-timeblock-inbox-file'" 1658 | (interactive) 1659 | (unless (member org-timeblock-inbox-file (org-timeblock-files)) 1660 | (user-error "`org-timeblock-inbox-file' must be present in `org-timeblock-files'")) 1661 | (let ((title "")) 1662 | (while (string-empty-p title) 1663 | (setq title (read-string "Heading: "))) 1664 | (with-current-buffer (find-file-noselect org-timeblock-inbox-file) 1665 | (goto-char (point-max)) 1666 | (insert "\n") 1667 | (org-insert-heading nil t t) 1668 | (insert "TODO " title " ") 1669 | (pcase org-timeblock-new-task-time 1670 | (`pick (funcall-interactively #'org-schedule nil)) 1671 | ((pred stringp) 1672 | (unless 1673 | (string-match-p "\\([01][0-9]\\|2[0-3]\\):[0-5][0-9]" 1674 | org-timeblock-new-task-time) 1675 | (user-error "Wrong time format specified in `org-timeblock-new-task-time'")) 1676 | (org-schedule nil (concat (org-timeblock-format-time "%Y-%m-%d " date) 1677 | org-timeblock-new-task-time))) 1678 | (`nil (org-schedule nil (org-timeblock-format-time "%Y-%m-%d" date))) 1679 | (_ (user-error "Invalid custom variable value"))) 1680 | (save-buffer))) 1681 | (org-timeblock-redraw-buffers)) 1682 | 1683 | (defun org-timeblock-time-inc (slot value time) 1684 | "Return a new time object based on TIME with its SLOT incremented by VALUE. 1685 | 1686 | SLOT should be specified as a plain symbol, not a keyword." 1687 | (let ((time (copy-sequence time))) 1688 | (decoded-time-add 1689 | time 1690 | (make-decoded-time (intern (format ":%s" slot)) value)))) 1691 | 1692 | (cl-defun org-timeblock-time-apply (time &key second minute hour 1693 | day month year) 1694 | "Return new timestamp based on TIME with new slot values from keys." 1695 | ;; This code is borrowed from `ts-apply' function which is part of ts.el 1696 | ;; project written by Adam Porter 1697 | (let ((time (copy-sequence time))) 1698 | (when second 1699 | (setf (decoded-time-second time) second)) 1700 | (when minute 1701 | (setf (decoded-time-minute time) minute)) 1702 | (when hour 1703 | (setf (decoded-time-hour time) hour)) 1704 | (when day 1705 | (setf (decoded-time-day time) day)) 1706 | (when month 1707 | (setf (decoded-time-month time) month)) 1708 | (when year 1709 | (setf (decoded-time-year time) year)) 1710 | time)) 1711 | 1712 | (defun org-timeblock-list-set-duration () 1713 | "Interactively change SCHEDULED duration for the task at point. 1714 | 1715 | Change SCHEDULED timestamp duration of the task at point in 1716 | `org-timeblock-list-mode'. 1717 | 1718 | Duration format: 1719 | 2h 1720 | 2h30m 1721 | 2h30 1722 | 45" 1723 | (interactive) 1724 | (when (org-timeblock--daterangep 1725 | (org-timeblock-get-ts-prop nil (line-beginning-position))) 1726 | (user-error "Can not reschedule entries with daterange timestamp")) 1727 | (when-let ((duration (org-timeblock-read-duration)) 1728 | (timestamp 1729 | (org-timeblock--duration 1730 | duration 1731 | (get-text-property (line-beginning-position) 'marker)))) 1732 | (org-timeblock-list-update-entry) 1733 | (when (get-buffer-window org-timeblock-buffer) 1734 | (org-timeblock-redraw-timeblocks)))) 1735 | 1736 | (defun org-timeblock-schedule () 1737 | "Change the timestamp for selected block or all marked blocks." 1738 | (interactive) 1739 | (if (> org-timeblock-mark-count 0) 1740 | (let* ((mark-data 1741 | (sort (dom-search 1742 | org-timeblock-svg 1743 | (lambda (node) (dom-attr node 'mark))) 1744 | (lambda (x y) 1745 | (cl-macrolet 1746 | ((get-ts (x) 1747 | `(org-with-point-at 1748 | (org-timeblock-get-marker-by-id 1749 | (car (split-string (dom-attr ,x 'id) "_"))) 1750 | (org-timeblock-timestamp-to-time 1751 | (org-element-timestamp-parser))))) 1752 | (or 1753 | (org-timeblock-decoded< (get-ts x) (get-ts y)) 1754 | (org-timeblock-decoded= (get-ts x) (get-ts y))))))) 1755 | (id (car (split-string (dom-attr (car mark-data) 'id) "_"))) 1756 | (marker (org-timeblock-get-marker-by-id id)) 1757 | (interval 1758 | (let* ((choices '(("side-by-side (0 mins between blocks)" ?s 0) 1759 | ("save time between blocks" ?b savetime) 1760 | ("enter your interval" ?i user-input))) 1761 | (answer 1762 | (read-char-from-minibuffer 1763 | (mapconcat 1764 | (lambda (x) 1765 | (concat 1766 | (propertize (char-to-string (cadr x)) 'face 'error) 1767 | " " (car x) "\n")) 1768 | choices) 1769 | (mapcar #'cadr choices)))) 1770 | (message "") 1771 | (pcase (caddr 1772 | (seq-find (lambda (x) (eq (cadr x) answer)) choices)) 1773 | (`user-input (read-number "Interval (minutes): ")) 1774 | ((and n _) n)))) 1775 | (prev-timestamp 1776 | (org-with-point-at marker 1777 | (org-element-timestamp-parser))) 1778 | (prev-end-or-start-ts 1779 | (or (org-timeblock-timestamp-to-time prev-timestamp t) 1780 | (org-timeblock-timestamp-to-time prev-timestamp))) 1781 | (timestamp (org-timeblock--schedule-time marker)) 1782 | (new-end-or-start-ts 1783 | (or (org-timeblock-timestamp-to-time timestamp t) 1784 | (org-timeblock-timestamp-to-time timestamp)))) 1785 | (pop mark-data) 1786 | (pcase interval 1787 | ((pred integerp) 1788 | (dolist (block mark-data) 1789 | (let* ((id (car (split-string (dom-attr block 'id) "_"))) 1790 | (marker (org-timeblock-get-marker-by-id id))) 1791 | (org-with-point-at marker 1792 | (let* ((timestamp (org-element-timestamp-parser)) 1793 | (start-ts 1794 | (org-timeblock-timestamp-to-time timestamp)) 1795 | (end-ts 1796 | (org-timeblock-timestamp-to-time timestamp t)) 1797 | (duration 1798 | (when (and start-ts end-ts) 1799 | (org-timeblock-time-diff end-ts start-ts))) 1800 | (new-start-ts 1801 | (org-timeblock-time-inc 1802 | 'minute 1803 | interval new-end-or-start-ts)) 1804 | (new-end-ts 1805 | (when duration 1806 | (org-timeblock-time-inc 1807 | 'minute duration new-start-ts)))) 1808 | (org-timeblock--schedule new-start-ts new-end-ts) 1809 | (setq new-end-or-start-ts 1810 | (or new-end-ts new-start-ts))))))) 1811 | (`savetime 1812 | (dolist (block mark-data) 1813 | (let* ((id (car (split-string (dom-attr block 'id) "_"))) 1814 | (marker (org-timeblock-get-marker-by-id id))) 1815 | (org-with-point-at marker 1816 | (let* ((timestamp (org-element-timestamp-parser)) 1817 | (start-ts (org-timeblock-timestamp-to-time 1818 | timestamp)) 1819 | (end-ts (org-timeblock-timestamp-to-time 1820 | timestamp t)) 1821 | (duration 1822 | (when (and start-ts end-ts) 1823 | (org-timeblock-time-diff end-ts start-ts))) 1824 | (int (org-timeblock-time-diff 1825 | start-ts prev-end-or-start-ts)) 1826 | (new-start-ts 1827 | (org-timeblock-time-inc 1828 | 'minute int new-end-or-start-ts)) 1829 | (new-end-ts 1830 | (when duration 1831 | (org-timeblock-time-inc 1832 | 'minute duration new-start-ts)))) 1833 | (org-timeblock--schedule new-start-ts new-end-ts) 1834 | (setq new-end-or-start-ts (or new-end-ts new-start-ts)) 1835 | (setq prev-end-or-start-ts (or end-ts start-ts))))))))) 1836 | (when-let ((block (org-timeblock-selected-block)) 1837 | (marker (org-timeblock-selected-block-marker))) 1838 | (org-timeblock--schedule-time marker))) 1839 | (org-timeblock-redraw-buffers)) 1840 | 1841 | (defun org-timeblock-set-duration () 1842 | "Interactively change SCHEDULED duration of the selected block. 1843 | 1844 | Change SCHEDULED timestamp duration of the task bound to the selected 1845 | block in `org-timeblock-mode'. 1846 | 1847 | Duration format: 1848 | 2h 1849 | 2h30m 1850 | 2h30 1851 | 45" 1852 | (interactive) 1853 | (when-let ((marker (org-timeblock-selected-block-marker)) 1854 | (block (org-timeblock-selected-block)) 1855 | (duration (org-timeblock-read-duration))) 1856 | (org-timeblock--duration duration marker) 1857 | (org-timeblock-redraw-buffers))) 1858 | 1859 | (defun org-timeblock-list-schedule () 1860 | "Reschedule the entry at point in *org-timeblock-list* buffer. 1861 | The org-element timestamp object may be from an event or from a 1862 | SCHEDULED property." 1863 | (interactive) 1864 | (when (org-timeblock--daterangep 1865 | (org-timeblock-get-ts-prop nil (line-beginning-position))) 1866 | (user-error "Can not reschedule entries with daterange timestamp")) 1867 | (when-let ((date (org-timeblock-list-get-current-date)) 1868 | (timestamp (org-timeblock--schedule-time 1869 | (get-text-property (line-beginning-position) 'marker)))) 1870 | (org-timeblock-list-update-entry) 1871 | (when (get-buffer-window org-timeblock-buffer) 1872 | (org-timeblock-redraw-timeblocks)))) 1873 | 1874 | (defun org-timeblock-list-update-entry () 1875 | "Update text and text properties for the entry at point in *org-timeblock-list*." 1876 | (let ((marker (get-text-property (line-beginning-position) 'marker))) 1877 | (unless (marker-buffer marker) 1878 | (user-error "Non-existent marker's buffer")) 1879 | (let* ((inhibit-read-only t) 1880 | (type (get-text-property (line-beginning-position) 'type)) 1881 | tags 1882 | (new-entry 1883 | (org-with-point-at marker 1884 | (let ((timestamp (org-element-timestamp-parser)) 1885 | (title (org-get-heading t nil t t))) 1886 | (setq tags (mapcar #'substring-no-properties (org-get-tags))) 1887 | (propertize 1888 | (concat (org-timeblock--construct-prefix timestamp type) 1889 | title) 1890 | 'timestamp timestamp 1891 | 'type type 1892 | 'marker marker 1893 | 'tags tags 1894 | 'id (org-timeblock-construct-id marker) 1895 | 'title title))))) 1896 | (delete-region (line-beginning-position) (1+ (line-end-position))) 1897 | (insert (propertize 1898 | (concat new-entry "\n") 1899 | 'face 1900 | (org-timeblock-get-colors tags)))))) 1901 | 1902 | ;;;; Navigation commands 1903 | 1904 | (defun org-timeblock-select-block-with-cursor () 1905 | "Select the block under current position of the cursor." 1906 | (interactive) 1907 | (when-let ((pos (org-timeblock-cursor-pos)) 1908 | (window (get-buffer-window org-timeblock-buffer)) 1909 | (window-width (window-body-width window t))) 1910 | (org-timeblock-unselect-block) 1911 | (when-let ((node 1912 | (car (dom-search 1913 | org-timeblock-svg 1914 | (lambda (node) 1915 | (let ((x (dom-attr node 'x)) 1916 | (y (dom-attr node 'y))) 1917 | (and (eq (dom-tag node) 'rect) 1918 | (> (car pos) x) 1919 | (<= (car pos) (+ x (dom-attr node 'width))) 1920 | (<= (cdr pos) (+ y (dom-attr node 'height))) 1921 | (> (cdr pos) y)))))))) 1922 | (unless (dom-attr node 'mark) 1923 | (dom-set-attribute node 'orig-fill (dom-attr node 'fill))) 1924 | (dom-set-attribute 1925 | node 'fill 1926 | (face-attribute 1927 | 'org-timeblock-select :background)) 1928 | (dom-set-attribute node 'select t)) 1929 | (setq org-timeblock-column 1930 | (1+ (/ (car pos) (/ window-width org-timeblock-span)))) 1931 | (org-timeblock-redisplay) 1932 | (org-timeblock-show-olp-maybe (org-timeblock-selected-block-marker)))) 1933 | 1934 | (defun org-timeblock-unselect-block () 1935 | "Unselect selected block. 1936 | Return the numerical order of the unselected block on success. 1937 | Otherwise, return nil." 1938 | (when-let ((node (car (dom-search 1939 | org-timeblock-svg 1940 | (lambda (node) 1941 | (dom-attr node 'select)))))) 1942 | (dom-set-attribute 1943 | node 1944 | 'fill (if (dom-attr node 'mark) 1945 | (face-attribute 1946 | 'org-timeblock-mark :background) 1947 | (or (dom-attr node 'orig-fill) "#ffffff"))) 1948 | (dom-remove-attribute node 'select) 1949 | (cons (dom-attr node 'order) 1950 | (dom-attr node 'column)))) 1951 | 1952 | (defun org-timeblock-list-next-line () 1953 | "Move cursor to the next line." 1954 | (interactive) 1955 | (funcall-interactively 'next-line) 1956 | (org-timeblock-select-block-for-current-entry) 1957 | (org-timeblock-show-olp-maybe 1958 | (get-text-property (line-beginning-position) 'marker))) 1959 | 1960 | (defun org-timeblock-list-previous-line () 1961 | "Move cursor to the previous line." 1962 | (interactive) 1963 | (funcall-interactively 'previous-line) 1964 | (org-timeblock-select-block-for-current-entry) 1965 | (org-timeblock-show-olp-maybe 1966 | (get-text-property (line-beginning-position) 'marker))) 1967 | 1968 | (defun org-timeblock-mark-block () 1969 | "Mark selected block." 1970 | (interactive) 1971 | (when-let ((node (org-timeblock-selected-block)) 1972 | ((not (dom-attr node 'mark)))) 1973 | (dom-set-attribute 1974 | node 'fill 1975 | (face-attribute 1976 | 'org-timeblock-mark :background)) 1977 | (dom-set-attribute node 'mark t) 1978 | (cl-incf org-timeblock-mark-count)) 1979 | (org-timeblock-forward-block)) 1980 | 1981 | (defun org-timeblock-mark-by-regexp (regexp) 1982 | "Mark blocks by REGEXP." 1983 | (interactive "sMark entries matching regexp: ") 1984 | (dolist (entry 1985 | (seq-filter 1986 | (lambda (x) (string-match regexp x)) 1987 | (org-timeblock-get-entries 1988 | (car org-timeblock-daterange) 1989 | (cdr org-timeblock-daterange) 1990 | t))) 1991 | (when-let ((id (get-text-property 0 'id entry)) 1992 | (node (car (dom-by-id org-timeblock-svg id)))) 1993 | (dom-set-attribute node 'orig-fill (dom-attr node 'fill)) 1994 | (dom-set-attribute 1995 | node 'fill 1996 | (face-attribute 1997 | 'org-timeblock-mark :background)) 1998 | (dom-set-attribute node 'mark t) 1999 | (cl-incf org-timeblock-mark-count))) 2000 | (org-timeblock-redisplay)) 2001 | 2002 | (defun org-timeblock-unmark-block () 2003 | "Unmark selected block." 2004 | (interactive) 2005 | (when-let ((node (org-timeblock-selected-block)) 2006 | ((dom-attr node 'mark))) 2007 | (dom-remove-attribute node 'mark) 2008 | (dom-set-attribute node 'fill (dom-attr node 'orig-fill)) 2009 | (cl-decf org-timeblock-mark-count)) 2010 | (org-timeblock-forward-block)) 2011 | 2012 | (defun org-timeblock-unmark-all-blocks () 2013 | "Unmark all marked blocks." 2014 | (interactive) 2015 | (when-let ((marked-blocks 2016 | (dom-search org-timeblock-svg 2017 | (lambda (node) 2018 | (dom-attr node 'mark))))) 2019 | (dolist (node marked-blocks) 2020 | (dom-remove-attribute node 'mark) 2021 | (unless (dom-attr node 'select) 2022 | (dom-set-attribute node 'fill (dom-attr node 'orig-fill)))) 2023 | (setq org-timeblock-mark-count 0) 2024 | (org-timeblock-redisplay))) 2025 | 2026 | (defun org-timeblock-forward-block () 2027 | "Select the next timeblock in *org-timeblock* buffer." 2028 | (interactive) 2029 | (when-let ((unsel-order (let ((unselected-info (org-timeblock-unselect-block))) 2030 | (or (and unselected-info 2031 | (= (cdr unselected-info) 2032 | org-timeblock-column) 2033 | (car unselected-info)) 2034 | -1))) 2035 | (node (car (or (dom-search org-timeblock-svg 2036 | (lambda (node) 2037 | (and 2038 | (dom-attr node 'order) 2039 | (= (dom-attr node 'column) 2040 | org-timeblock-column) 2041 | (= (dom-attr node 'order) 2042 | (1+ unsel-order))))) 2043 | (dom-search org-timeblock-svg 2044 | (lambda (node) 2045 | (and 2046 | (dom-attr node 'order) 2047 | (= (dom-attr node 'column) 2048 | org-timeblock-column) 2049 | (= (dom-attr node 'order) 0)))))))) 2050 | (unless (dom-attr node 'mark) 2051 | (dom-set-attribute node 'orig-fill (dom-attr node 'fill))) 2052 | (dom-set-attribute 2053 | node 'fill 2054 | (face-attribute 2055 | 'org-timeblock-select :background)) 2056 | (dom-set-attribute node 'select t) 2057 | (org-timeblock-show-olp-maybe (org-timeblock-selected-block-marker)) 2058 | (org-timeblock-redisplay) t)) 2059 | 2060 | (defun org-timeblock-forward-column () 2061 | "Select the next column in *org-timeblock* buffer." 2062 | (interactive) 2063 | (if (= org-timeblock-column org-timeblock-span) 2064 | (setq org-timeblock-column 1) 2065 | (cl-incf org-timeblock-column)) 2066 | (org-timeblock-forward-block) 2067 | (org-timeblock-redisplay)) 2068 | 2069 | (defun org-timeblock-backward-column () 2070 | "Select the next column in *org-timeblock* buffer." 2071 | (interactive) 2072 | (if (= org-timeblock-column 1) 2073 | (setq org-timeblock-column org-timeblock-span) 2074 | (cl-decf org-timeblock-column)) 2075 | (org-timeblock-forward-block) 2076 | (org-timeblock-redisplay)) 2077 | 2078 | (defun org-timeblock-show-olp-maybe (marker) 2079 | "Show outline path in echo area for the selected item. 2080 | If `org-timeblock-show-outline-path' is non-nil, display the path of the 2081 | heading at MARKER in the echo area." 2082 | (when (and org-timeblock-show-outline-path marker (marker-buffer marker) 2083 | (buffer-live-p (marker-buffer marker))) 2084 | (org-with-point-at marker (org-display-outline-path t t)))) 2085 | 2086 | (defun org-timeblock-backward-block () 2087 | "Select the previous timeblock in *org-timeblock* buffer. 2088 | Return t on success, otherwise - nil." 2089 | (interactive) 2090 | (when-let ((unsel-order 2091 | (let ((unselected-info (org-timeblock-unselect-block))) 2092 | (or (and unselected-info 2093 | (= (cdr unselected-info) 2094 | org-timeblock-column) 2095 | (car unselected-info)) 2096 | 0))) 2097 | (node (car (or 2098 | (dom-search org-timeblock-svg 2099 | (lambda (node) 2100 | (and 2101 | (dom-attr node 'order) 2102 | (= (dom-attr node 'column) 2103 | org-timeblock-column) 2104 | (= (dom-attr node 'order) 2105 | (1- unsel-order))))) 2106 | (let ((len (length 2107 | (seq-filter 2108 | (lambda (x) 2109 | (= (dom-attr x 'column) 2110 | org-timeblock-column)) 2111 | (dom-by-tag org-timeblock-svg 'rect))))) 2112 | (dom-search 2113 | org-timeblock-svg 2114 | (lambda (node) 2115 | (and 2116 | (dom-attr node 'order) 2117 | (= (dom-attr node 'column) 2118 | org-timeblock-column) 2119 | (= (dom-attr node 'order) (1- len)))))))))) 2120 | (unless (dom-attr node 'mark) 2121 | (dom-set-attribute node 'orig-fill (dom-attr node 'fill))) 2122 | (dom-set-attribute 2123 | node 'fill 2124 | (face-attribute 2125 | 'org-timeblock-select :background)) 2126 | (dom-set-attribute node 'select t) 2127 | (org-timeblock-show-olp-maybe (org-timeblock-selected-block-marker)) 2128 | (org-timeblock-redisplay) t)) 2129 | 2130 | (defun org-timeblock-day-later () 2131 | "Go forward in time by one day in `org-timeblock-mode'." 2132 | (interactive) 2133 | (setq org-timeblock-daterange 2134 | (cons (org-timeblock-time-inc 'day 1 (car org-timeblock-daterange)) 2135 | (and (cdr org-timeblock-daterange) 2136 | (org-timeblock-time-inc 2137 | 'day 1 (cdr org-timeblock-daterange))))) 2138 | (unless (= org-timeblock-column 1) 2139 | (org-timeblock-backward-column)) 2140 | (org-timeblock-redraw-buffers)) 2141 | 2142 | (defun org-timeblock-jump-to-day (date) 2143 | "Jump to DATE in *org-timeblock-list* or *org-timeblock* buffers. 2144 | 2145 | When called interactively, prompt for the date. 2146 | When called from Lisp, DATE should be a date as returned by 2147 | `org-read-date'" 2148 | (interactive (list (decode-time (org-read-date 2149 | nil t nil nil 2150 | (encode-time 2151 | (nth (1- org-timeblock-column) 2152 | (org-timeblock-get-dates 2153 | (car org-timeblock-daterange) 2154 | (cdr org-timeblock-daterange)))))))) 2155 | (when date 2156 | (setq org-timeblock-daterange 2157 | (cons date 2158 | (org-timeblock-time-inc 2159 | 'day (1- org-timeblock-span) date))) 2160 | (org-timeblock-redraw-buffers))) 2161 | 2162 | (defun org-timeblock-day-earlier () 2163 | "Go backward in time by one day in `org-timeblock-mode'." 2164 | (interactive) 2165 | (setq org-timeblock-daterange 2166 | (cons 2167 | (org-timeblock-time-inc 'day -1 (car org-timeblock-daterange)) 2168 | (and (cdr org-timeblock-daterange) 2169 | (org-timeblock-time-inc 'day -1 (cdr org-timeblock-daterange))))) 2170 | (unless (= org-timeblock-column org-timeblock-span) 2171 | (org-timeblock-forward-column)) 2172 | (org-timeblock-redraw-buffers)) 2173 | 2174 | ;;;; View commands 2175 | 2176 | (defun org-timeblock-list-goto-other-window () 2177 | "Jump to the org heading of the entry at point." 2178 | (interactive) 2179 | (unless (eq major-mode 'org-timeblock-list-mode) 2180 | (user-error "Not in *org-timeblock-list* buffer")) 2181 | (let ((marker (get-text-property (line-beginning-position) 'marker))) 2182 | (switch-to-buffer-other-window (marker-buffer marker)) 2183 | (goto-char (marker-position marker)) 2184 | (org-timeblock-show-context) 2185 | (recenter))) 2186 | 2187 | (defun org-timeblock-list-goto () 2188 | "Go to the heading of the entry at point in the same window." 2189 | (interactive) 2190 | (unless (eq major-mode 'org-timeblock-list-mode) 2191 | (user-error "Not in *org-timeblock-list* buffer")) 2192 | (when-let ((marker (get-text-property (line-beginning-position) 'marker)) 2193 | (buffer (marker-buffer marker)) 2194 | (pos (marker-position marker))) 2195 | (unless buffer (user-error "Trying to switch to non-existent buffer")) 2196 | (pop-to-buffer-same-window buffer) 2197 | (widen) 2198 | (goto-char pos) 2199 | (org-timeblock-show-context))) 2200 | 2201 | (defun org-timeblock-goto-other-window () 2202 | "Jump to the org heading of selected timeblock." 2203 | (interactive) 2204 | (unless (eq major-mode 'org-timeblock-mode) 2205 | (user-error "Not in *org-timeblock* buffer")) 2206 | (when-let ((marker (org-timeblock-selected-block-marker))) 2207 | (unless (marker-buffer marker) 2208 | (user-error "Non-existent marker's buffer")) 2209 | (switch-to-buffer-other-window (marker-buffer marker)) 2210 | (goto-char (marker-position marker)) 2211 | (org-timeblock-show-context) 2212 | (recenter))) 2213 | 2214 | (defun org-timeblock-goto () 2215 | "Go to the heading of the selected block in the same window." 2216 | (interactive) 2217 | (unless (eq major-mode 'org-timeblock-mode) 2218 | (user-error "Not in *org-timeblock* buffer")) 2219 | (when-let ((marker (org-timeblock-selected-block-marker)) 2220 | (buffer (marker-buffer marker)) 2221 | (pos (marker-position marker))) 2222 | (unless buffer (user-error "Trying to switch to non-existent buffer")) 2223 | (pop-to-buffer-same-window buffer) 2224 | (widen) 2225 | (goto-char pos) 2226 | (org-timeblock-show-context))) 2227 | 2228 | (defun org-timeblock-read-number-in-range (min max) 2229 | "Read a number in [MIN; MAX] and return it." 2230 | (cl-loop as n = (read-number 2231 | (format "Number [%d; %d]: " min max)) 2232 | until (<= min n max) 2233 | finally return n)) 2234 | 2235 | (defun org-timeblock-switch-scaling () 2236 | "Switch between different scaling modes in `org-timeblock-mode'. 2237 | 2238 | Available view options: 2239 | 1. Do not hide anything. All 24 hours will be displayed. 2240 | 2. Hide hours in the past (if there are no timeblocks). 2241 | 3. Hide all free hours before the first timeblock." 2242 | (interactive) 2243 | (let* ((choices 2244 | '(("Hide hours in the past (if there are no timeblocks)." ?c t) 2245 | ("Do not hide anything. All 24 hours will be displayed." ?a nil) 2246 | ("Hide all free hours before the first timeblock." ?h hide-all) 2247 | ("Display specified range of hours [earliest; latest]." ?v user))) 2248 | (answer 2249 | (read-char-from-minibuffer 2250 | (mapconcat 2251 | (lambda (x) 2252 | (concat (propertize (char-to-string (cadr x)) 'face 'error) 2253 | " " (car x) "\n")) 2254 | choices) 2255 | (mapcar #'cadr choices)))) 2256 | (message "") 2257 | (setq org-timeblock-scale-options 2258 | (pcase (caddr (seq-find (lambda (x) (eq (cadr x) answer)) choices)) 2259 | (`user (let* ((min-hour 2260 | (org-timeblock-read-number-in-range 0 23)) 2261 | (max-hour 2262 | (org-timeblock-read-number-in-range min-hour 24))) 2263 | (cons min-hour max-hour))) 2264 | ((and n _) n))) 2265 | (org-timeblock-redraw-timeblocks))) 2266 | 2267 | (defun org-timeblock-change-span () 2268 | "Change view span." 2269 | (interactive) 2270 | (let ((cur-date (nth (1- org-timeblock-column) 2271 | (org-timeblock-get-dates 2272 | (car org-timeblock-daterange) 2273 | (cdr org-timeblock-daterange)))) 2274 | (span (- (read-char-from-minibuffer 2275 | "Span span [1-7]: " '(?1 ?2 ?3 ?4 ?5 ?6 ?7)) 2276 | 48))) 2277 | (setq org-timeblock-daterange 2278 | (cons cur-date (org-timeblock-time-inc 'day (1- span) cur-date)) 2279 | org-timeblock-span span 2280 | org-timeblock-column 1)) 2281 | (org-timeblock-redraw-buffers)) 2282 | 2283 | (defun org-timeblock-list-toggle-timeblock () 2284 | "Toggle the display of the window with `org-timeblock-mode'." 2285 | (interactive) 2286 | (if-let ((window (get-buffer-window org-timeblock-buffer))) 2287 | (delete-window window) 2288 | (org-timeblock-show-timeblocks) 2289 | (org-timeblock-redraw-timeblocks))) 2290 | 2291 | (defun org-timeblock-toggle-timeblock-list () 2292 | "Toggle the display of the window with `org-timeblock-list-mode'." 2293 | (interactive) 2294 | (if-let ((window (get-buffer-window org-timeblock-list-buffer))) 2295 | (delete-window window) 2296 | (org-timeblock-show-timeblock-list)) 2297 | (org-timeblock-redraw-buffers)) 2298 | 2299 | (defun org-timeblock-redraw-buffers () 2300 | "Redraw `org-timeblock-list-mode' and `org-timeblock-timeline-mode' buffers." 2301 | ;; org-timeblock-list-mode and org-timeblock-mode 2302 | (interactive) 2303 | (with-current-buffer (get-buffer-create org-timeblock-list-buffer) 2304 | (let ((inhibit-read-only t) 2305 | (entries (org-timeblock-get-entries 2306 | (car org-timeblock-daterange) 2307 | (cdr org-timeblock-daterange))) 2308 | (dates (org-timeblock-get-dates 2309 | (car org-timeblock-daterange) 2310 | (cdr org-timeblock-daterange)))) 2311 | (erase-buffer) 2312 | (org-timeblock-list-mode) 2313 | (dolist (date dates) 2314 | (let ((entries 2315 | (seq-filter 2316 | (lambda (x) 2317 | (org-timeblock--timestamp-relevant-p 2318 | (org-timeblock-get-ts-prop x) date)) 2319 | entries))) 2320 | (insert 2321 | (propertize 2322 | (concat 2323 | (org-timeblock-format-time "[%Y-%m-%d %a]" date) 2324 | (and (org-timeblock-date= date (decode-time)) " Today")) 2325 | 'face 'org-timeblock-list-header)) 2326 | (insert "\n") 2327 | (dolist (entry entries) 2328 | (insert (propertize 2329 | (concat entry "\n") 2330 | 'face 2331 | (org-timeblock-get-colors 2332 | (get-text-property 0 'tags entry))))) 2333 | (goto-char (point-max)))) 2334 | (goto-char (point-min)) 2335 | (when (get-buffer-window org-timeblock-buffer) 2336 | (org-timeblock-redraw-timeblocks))))) 2337 | 2338 | (defun org-timeblock-write (file) 2339 | "Write the current *org-timeblock* buffer to FILE. 2340 | 2341 | Depending on the extension of the file name, PNG image (.png), 2342 | SVG image (.svg), PDF (.pdf) is produced." 2343 | (interactive "FWrite timeblocks to [PDF|SVG|PNG] file : \n") 2344 | (unless (eq major-mode 'org-timeblock-mode) 2345 | (user-error "Not in org-timeblock buffer")) 2346 | (if (or (not (file-writable-p file)) 2347 | (and (file-exists-p file) 2348 | (if (called-interactively-p 'any) 2349 | (not (y-or-n-p 2350 | (format "Overwrite existing file %s? " file)))))) 2351 | (user-error "Cannot write agenda to file %s" file)) 2352 | (org-timeblock-unselect-block) 2353 | (let ((file (expand-file-name file)) 2354 | (svg (copy-sequence org-timeblock-svg))) 2355 | ;; delete marker to not trigger `svg-possibly-update-image' 2356 | (dom-remove-attribute svg :image) 2357 | (with-temp-buffer 2358 | (let* ((dates (org-timeblock-get-dates 2359 | (car org-timeblock-daterange) 2360 | (cdr org-timeblock-daterange))) 2361 | (max-length (/ (+ (/ org-timeblock-svg-width (default-font-width))) 2362 | (length dates))) 2363 | (date-format 2364 | (pcase max-length 2365 | ((pred (< 15)) "[%Y-%m-%d %a]") 2366 | ((pred (< 11)) "[%Y-%m-%d]") 2367 | ((pred (< 6)) "[%m-%d]") 2368 | ((pred (< 3)) "[%d]")))) 2369 | (dom-add-child-before 2370 | svg 2371 | (dom-node 2372 | 'rect 2373 | (list 2374 | (cons 'x 0) 2375 | (cons 'y 0) 2376 | (cons 'width org-timeblock-svg-width) 2377 | (cons 'height org-timeblock-svg-height) 2378 | (cons 'fill (face-attribute 'default :background))))) 2379 | (dotimes (iter (length dates)) 2380 | (svg-text 2381 | svg (org-timeblock-format-time date-format (nth iter dates)) 2382 | :y org-timeblock-svg-height 2383 | :x (+ 5 (* (/ org-timeblock-svg-width (length dates)) iter)) 2384 | :fill (face-attribute 'default :foreground))) 2385 | (svg-print svg)) 2386 | (pcase (file-name-extension file) 2387 | ((or "pdf" "png") 2388 | (unless (executable-find "inkscape") 2389 | (user-error "Inkscape executable not found")) 2390 | (call-process-region (point-min) (point-max) 2391 | "inkscape" nil nil nil "--pipe" 2392 | (concat "--export-filename=" file))) 2393 | ((or "svg" `nil) (write-region nil nil file))) 2394 | (org-timeblock-redraw-timeblocks)))) 2395 | 2396 | ;;;; Footer 2397 | 2398 | (provide 'org-timeblock) 2399 | 2400 | ;; Local Variables: 2401 | ;; outline-regexp: "\\(;\\{3,\\} \\)" 2402 | ;; End: 2403 | 2404 | ;;; org-timeblock.el ends here 2405 | -------------------------------------------------------------------------------- /screenshots/multi-day-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ichernyshovvv/org-timeblock/e61e5734b49f933ed178029f804a0499f3308e1e/screenshots/multi-day-view.png -------------------------------------------------------------------------------- /screenshots/org-timeblock-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ichernyshovvv/org-timeblock/e61e5734b49f933ed178029f804a0499f3308e1e/screenshots/org-timeblock-mode.png -------------------------------------------------------------------------------- /screenshots/org-timeblock-with-list-mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ichernyshovvv/org-timeblock/e61e5734b49f933ed178029f804a0499f3308e1e/screenshots/org-timeblock-with-list-mode.png -------------------------------------------------------------------------------- /test/org-timeblock-test.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | (add-to-list 'load-path (expand-file-name ".")) 3 | (require 'org-timeblock) 4 | (require 'ert) 5 | 6 | ;; The code is borrowed from `org-test-with-temp-text' which is a macro from 7 | ;; org-test.el 8 | (defmacro org-timeblock-test-with-temp-text (text &rest body) 9 | "Run body in a temporary buffer with Org mode as the active 10 | mode holding TEXT. If the string \"\" appears in TEXT 11 | then remove it and place the point there before running BODY, 12 | otherwise place the point at the beginning of the inserted text." 13 | (declare (indent 1) (debug t)) 14 | `(let ((inside-text (if (stringp ,text) ,text (eval ,text))) 15 | (org-mode-hook nil)) 16 | (with-temp-buffer 17 | (org-mode) 18 | (let ((point (string-match "" inside-text))) 19 | (if point 20 | (progn 21 | (insert (replace-match "" nil nil inside-text)) 22 | (goto-char (1+ (match-beginning 0)))) 23 | (insert inside-text) 24 | (goto-char (point-min)))) 25 | (font-lock-ensure (point-min) (point-max)) 26 | ,@body))) 27 | 28 | (defmacro org-timeblock-with-temp-org-file (&rest body) 29 | "Move to buffer and point of point-or-marker POM for the duration of BODY." 30 | `(let ((org-property-format "%s %s") 31 | (org-tags-column 0) 32 | (org-file (make-temp-file "org-timeblock-" nil ".org"))) 33 | (with-current-buffer (find-file-noselect org-file) 34 | ,@body 35 | (save-buffer)) 36 | (prog1 37 | (with-temp-buffer 38 | (insert-file-contents-literally org-file) 39 | (buffer-substring-no-properties (point-min) (point-max))) 40 | (delete-file org-file) 41 | (and (get-file-buffer org-file) 42 | (kill-buffer (get-file-buffer org-file)))))) 43 | 44 | (dolist (file (directory-files "test" t "^test-")) 45 | (load file)) 46 | -------------------------------------------------------------------------------- /test/test-date.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | 3 | (ert-deftest test-org-timeblock-date= () 4 | "org-timeblock-date=" 5 | (should 6 | (org-timeblock-date= nil nil)) 7 | (should-not 8 | (org-timeblock-date= 9 | (org-parse-time-string "2023-10-10") 10 | nil)) 11 | (should-not 12 | (org-timeblock-date= 13 | nil 14 | (org-parse-time-string "2023-10-10"))) 15 | (should 16 | (org-timeblock-date= 17 | (org-parse-time-string "2023-10-10") 18 | (org-parse-time-string "2023-10-10"))) 19 | (should 20 | (org-timeblock-date= 21 | (org-parse-time-string "2023-10-10") 22 | (org-parse-time-string "2023-10-10 12:00"))) 23 | (should-not 24 | (org-timeblock-date= 25 | (org-parse-time-string "2023-10-10") 26 | (org-parse-time-string "2023-10-15")))) 27 | 28 | (ert-deftest test-org-timeblock-date< () 29 | "org-timeblock-date<" 30 | (should-not 31 | (org-timeblock-date< 32 | (org-parse-time-string "2023-10-10") nil)) 33 | (should 34 | (org-timeblock-date< nil (org-parse-time-string "2023-10-10"))) 35 | (should-not 36 | (org-timeblock-date< 37 | (org-parse-time-string "2023-10-10") 38 | (org-parse-time-string "2023-10-10"))) 39 | (should 40 | (org-timeblock-date< 41 | (org-parse-time-string "2023-10-10") 42 | (org-parse-time-string "2023-10-15"))) 43 | (should 44 | (org-timeblock-date< 45 | (org-parse-time-string "2023-07-31") 46 | (org-parse-time-string "2023-08-01"))) 47 | (should-not 48 | (org-timeblock-date< 49 | (org-parse-time-string "2023-10-15") 50 | (org-parse-time-string "2023-10-10")))) 51 | -------------------------------------------------------------------------------- /test/test-daterangep.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | 3 | (ert-deftest test-org-timeblock--daterangep () 4 | "org-timeblock--daterangep" 5 | (should-not 6 | (org-timeblock--daterangep 7 | (org-timeblock-test-with-temp-text 8 | "<2023-07-02 Sun>" 9 | (org-element-timestamp-parser)))) 10 | 11 | (should-not 12 | (org-timeblock--daterangep 13 | (org-timeblock-test-with-temp-text 14 | "<2023-07-02 Sun>--<2023-07-02 Sun>" 15 | (org-element-timestamp-parser)))) 16 | 17 | (should-not 18 | (org-timeblock--daterangep 19 | (org-timeblock-test-with-temp-text "<2023-07-02 Sun 12:00>" 20 | (org-element-timestamp-parser)))) 21 | 22 | (should-not 23 | (org-timeblock--daterangep 24 | (org-timeblock-test-with-temp-text 25 | "<2023-07-02 Sun 12:00>--<2023-07-03 Mon>" 26 | (org-element-timestamp-parser)))) 27 | 28 | (should-not 29 | (org-timeblock--daterangep 30 | (org-timeblock-test-with-temp-text 31 | "<2023-07-02 Sun 12:00>--<2023-07-03 Mon 13:00>" 32 | (org-element-timestamp-parser)))) 33 | 34 | (should 35 | (org-timeblock--daterangep 36 | (org-timeblock-test-with-temp-text 37 | "<2023-07-02 Sun>--<2023-07-03 Mon>" 38 | (org-element-timestamp-parser))))) 39 | -------------------------------------------------------------------------------- /test/test-intersectp.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | 3 | (defun org-timeblock-check-intersection (y1 height1 y2 height2) 4 | (let ((entry1 (propertize "entry text" 'y y1 'block-height height1)) 5 | (entry2 (propertize "entry text" 'y y2 'block-height height2))) 6 | (org-timeblock-intersect-p entry1 entry2))) 7 | 8 | (ert-deftest test-org-timeblock-intersect-p () 9 | "org-timeblock-intersect-p" 10 | (should-not 11 | (org-timeblock-check-intersection 0 30 30 45)) 12 | 13 | (should-not 14 | (org-timeblock-check-intersection 0 30 30 45)) 15 | 16 | (should 17 | (org-timeblock-check-intersection 0 35 30 45)) 18 | 19 | (should 20 | (org-timeblock-check-intersection 0 100 30 45))) 21 | -------------------------------------------------------------------------------- /test/test-schedule.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | 3 | (ert-deftest test-org-timeblock-schedule () 4 | ;; Rescheduling 5 | (should 6 | (string= 7 | (org-timeblock-with-temp-org-file 8 | (insert "* test :tag1:\nSCHEDULED: <2022-10-16 Sun>") 9 | (search-backward "<") 10 | (org-timeblock--schedule 11 | (make-decoded-time :year 2022 :month 10 :day 15))) 12 | (string-join 13 | '("* test :tag1:" 14 | "SCHEDULED: <2022-10-15 Sat>" 15 | "") 16 | "\n"))) 17 | ;; Rescheduling an entry that is scheduled to a timestamp with a repeater 18 | (should 19 | (string= 20 | (org-timeblock-with-temp-org-file 21 | (insert "* test :tag1:\nSCHEDULED: <2022-10-16 Sun +1d>") 22 | (search-backward "<") 23 | (org-timeblock--schedule 24 | (make-decoded-time :year 2022 :month 10 :day 15))) 25 | (string-join 26 | '("* test :tag1:" 27 | "SCHEDULED: <2022-10-15 Sat +1d>" 28 | "") 29 | "\n"))) 30 | ;; Rescheduling an entry that is scheduled to a timerange with a repeater 31 | (should 32 | (string= 33 | (org-timeblock-with-temp-org-file 34 | (insert "* test :tag1:\nSCHEDULED: <2022-10-16 Sun 12:00-13:00 +1d>") 35 | (search-backward "<") 36 | (org-timeblock--schedule 37 | (make-decoded-time :year 2022 :month 10 :day 15))) 38 | (string-join 39 | '("* test :tag1:" 40 | "SCHEDULED: <2022-10-15 Sat +1d>" 41 | "") 42 | "\n"))) 43 | ;; Rescheduling an entry that is scheduled to a daterange with a repeater 44 | (should 45 | (string= 46 | (org-timeblock-with-temp-org-file 47 | (insert "* test :tag1:\nSCHEDULED: <2022-10-14 Fri 12:00 +1d>--<2022-10-15 Sat 13:00 +1d>") 48 | (search-backward "<") 49 | (search-backward "<") 50 | (org-timeblock--schedule 51 | (make-decoded-time :year 2022 :month 10 :day 15))) 52 | (string-join 53 | '("* test :tag1:" 54 | "SCHEDULED: <2022-10-15 Sat +1d>" 55 | "") 56 | "\n"))) 57 | ;; Rescheduling to a daterange with a repeater 58 | (should 59 | (string= 60 | (org-timeblock-with-temp-org-file 61 | (insert "* test :tag1:\nSCHEDULED: <2022-10-15 Sat +1d>") 62 | (search-backward "<") 63 | (org-timeblock--schedule 64 | (org-parse-time-string "2022-10-14 12:00") 65 | (org-parse-time-string "2022-10-15 13:00"))) 66 | (string-join 67 | '("* test :tag1:" 68 | "SCHEDULED: <2022-10-14 Fri 12:00 +1d>--<2022-10-15 Sat 13:00 +1d>" 69 | "") 70 | "\n"))) 71 | ;; Rescheduling to a timerange with a repeater 72 | (should 73 | (string= 74 | (org-timeblock-with-temp-org-file 75 | (insert "* test :tag1:\nSCHEDULED: <2022-10-15 Sat +1d>") 76 | (search-backward "<") 77 | (org-timeblock--schedule 78 | (org-parse-time-string "2022-10-14 12:00") 79 | (org-parse-time-string "2022-10-14 13:00"))) 80 | (string-join 81 | '("* test :tag1:" 82 | "SCHEDULED: <2022-10-14 Fri 12:00-13:00 +1d>" 83 | "") 84 | "\n")))) 85 | -------------------------------------------------------------------------------- /test/test-ts-to-org-timerange.el: -------------------------------------------------------------------------------- 1 | ;; -*- lexical-binding: t; -*- 2 | 3 | (ert-deftest test-org-timeblock-ts-to-org-timerange () 4 | "org-timeblock-ts-to-org-timerange" 5 | (should 6 | (string= 7 | (org-timeblock-ts-to-org-timerange 8 | (make-decoded-time :year 2022 :month 10 :day 15)) 9 | "<2022-10-15 Sat>")) 10 | 11 | (should 12 | (string= 13 | (org-timeblock-ts-to-org-timerange 14 | (make-decoded-time :year 2022 :month 10 :day 15) 15 | (make-decoded-time :year 2022 :month 10 :day 15)) 16 | "<2022-10-15 Sat>")) 17 | 18 | (should 19 | (string= 20 | (org-timeblock-ts-to-org-timerange 21 | (make-decoded-time :year 2022 :month 10 :day 15) 22 | (make-decoded-time :year 2022 :month 10 :day 16)) 23 | "<2022-10-15 Sat>--<2022-10-16 Sun>")) 24 | 25 | (should 26 | (string= 27 | (org-timeblock-ts-to-org-timerange 28 | (org-parse-time-string "2022-10-15 20:15")) 29 | "<2022-10-15 Sat 20:15>")) 30 | 31 | (should 32 | (string= 33 | (org-timeblock-ts-to-org-timerange 34 | (org-parse-time-string "2022-10-15 20:15") 35 | (org-parse-time-string "2022-10-15 23:15")) 36 | "<2022-10-15 Sat 20:15-23:15>")) 37 | 38 | (should 39 | (string= 40 | (org-timeblock-ts-to-org-timerange 41 | (org-parse-time-string "2022-10-15 20:15") 42 | (make-decoded-time :year 2022 :month 10 :day 16)) 43 | "<2022-10-15 Sat 20:15>--<2022-10-16 Sun>")) 44 | 45 | (should 46 | (string= 47 | (org-timeblock-ts-to-org-timerange 48 | (org-parse-time-string "2022-10-15 23:30") 49 | (org-parse-time-string "2022-10-16")) 50 | "<2022-10-15 Sat 23:30>--<2022-10-16 Sun 00:00>")) 51 | 52 | (should 53 | (string= 54 | (org-timeblock-ts-to-org-timerange 55 | (org-parse-time-string "2022-10-15 23:30") 56 | (org-parse-time-string "2022-10-15 24:00")) 57 | "<2022-10-15 Sat 23:30>--<2022-10-16 Sun 00:00>")) 58 | 59 | (should 60 | (string= 61 | (org-timeblock-ts-to-org-timerange 62 | (org-parse-time-string "2022-10-15 23:45") 63 | (org-parse-time-string "2022-10-16 00:15")) 64 | "<2022-10-15 Sat 23:45>--<2022-10-16 Sun 00:15>"))) 65 | --------------------------------------------------------------------------------