├── .dir-locals.el ├── .gitignore ├── LICENSE ├── README.org └── denote-zettel-interface.el /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ;;; Directory Local Variables -*- no-byte-compile: t -*- 2 | ;;; For more information see (info "(emacs) Directory Variables") 3 | 4 | ((emacs-lisp-mode . ((sentence-end-double-space . t))) 5 | (org-mode . ((org-footnote-section . "Footnotes") 6 | (org-footnote-define-inline . nil)))) 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled 2 | *.elc 3 | 4 | # Packaging 5 | .cask 6 | 7 | # Backup files 8 | *~ 9 | 10 | # Undo-tree save-files 11 | *.~undo-tree 12 | -------------------------------------------------------------------------------- /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 | # -*- eval: (add-hook 'before-save-hook 'org-make-toc); -*- 2 | #+title: denote-zettel-interface 3 | 4 | # LocalWords: folgezettel numberings PRs 5 | 6 | This project was initially devised by the author to replicate a [[https://zettelkasten.de/folgezettel/][Zettelkasten workflow implementing Folgezettel]] using [[https://protesilaos.com/emacs/denote][denote.el]]. It is intended to sit atop one's usage of =denote.el=. The only assumption is that [[https://protesilaos.com/emacs/denote#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][note signatures]] be used as folgezettel index numberings in subdirectories within the user's Zettelkasten[fn:1]. 7 | 8 | The vision of this package is to represent the folgezettel index in a list format (~tabulated-list-mode~) and be able to navigate the index according to the numbering of notes, filter the shown notes arbitrarily (including by parents and siblings of a folgezettel index numbering), and automatically set the index numbering of a new note by the user's selection of the parent folgezettel note[fn:2]. In a way, this is an attempt at reducing the gap in navigating a digital versus analog/physical Zettelkasten. 9 | 10 | The current iteration of this package is somewhat clunky at places: bindings could be improved and the UX can be improved. However, I personally used this project as the sole entry-point to my Zettelkasten for months and at the very least /it was enough/. 11 | 12 | If you have any questions, requests, or curiosities, please create an issue on [[https://github.com/krisbalintona/denote-zettel-interface][the project's GitHub page]] or email the author at [[mailto:krisbalintona@gmail.com][krisbalintona@gmail.com]]. 13 | 14 | * Table of Contents 15 | :PROPERTIES: 16 | :TOC: :include all :force (nothing) :ignore (this) :local (nothing) 17 | :END: 18 | 19 | :CONTENTS: 20 | - [[#about-this-package-and-its-author][About this package and its author]] 21 | - [[#features][Features]] 22 | - [[#motivation][Motivation]] 23 | - [[#status-of-this-project-future-development-and-org-roam-folgezettel][Status of this project, future development, and org-roam-folgezettel]] 24 | - [[#installation][Installation]] 25 | - [[#usage][Usage]] 26 | - [[#sample-configuration][Sample configuration]] 27 | - [[#sample-workflow][Sample workflow]] 28 | - [[#commands][Commands]] 29 | - [[#index-numbering][Index numbering]] 30 | - [[#footnotes][Footnotes]] 31 | :END: 32 | 33 | * About this package and its author 34 | :PROPERTIES: 35 | :CUSTOM_ID: about-this-package-and-its-author 36 | :END: 37 | 38 | ** Features 39 | :PROPERTIES: 40 | :CUSTOM_ID: features 41 | :END: 42 | 43 | + List notes in ~tabulated-list-mode~ buffer 44 | + Implements a basic cache to speed of displaying and sorting-by-index-number of notes 45 | + Filter by subdirectory 46 | + Filtering any column by arbitrary string using ~tablist.el~ 47 | + Sorting by folgezettel index numbering 48 | + Navigation by index numbering 49 | + Commands to conveniently set index number of note by selecting "parent" folgezettel note 50 | 51 | ** Motivation 52 | :PROPERTIES: 53 | :CUSTOM_ID: motivation 54 | :END: 55 | 56 | I initially used [[https://github.com/namilus/denote-menu][denote-menu]] to navigate my denote notes, but found that if I used folgezettel, I needed a much more specialized package for navigating the index and setting new index numberings. Thus, this project was born. 57 | 58 | ** Status of this project, future development, and =org-roam-folgezettel= 59 | :PROPERTIES: 60 | :CUSTOM_ID: status-of-this-project-future-development-and-org-roam-folgezettel 61 | :END: 62 | 63 | The author of this project has migrated to org-roam. Consequently, /no new major features are planned for this project/. Consequently, users are encouraged to either: 64 | 1. fork this project and copy its code for their own purposes, or 65 | 2. take inspiration from the functionality herein to further their own Zettelkasten workflow or develop their own project that improves upon those concepts. 66 | I am, however, open to making minor improvements to the existing functionality per the request of interested users. Issues, PRs, and feedback are still welcome. 67 | 68 | To those interested, the author has moved to creating a similar package for org-roam that is meant to achieve the same purpose of =denote-zettel-interface= to an even greater degree: [[https://github.com/krisbalintona/org-roam-folgezettel][krisbalintona/org-roam-folgezettel]]. Org-roam offers headline-level nodes/notes which, in my view, offers unique benefits to Zettelkasten navigation over file-level-only notes. Additionally, I may consider in the future the possibility of merging these two projects if I can find a way to incorporate denote notes and org-roam nodes into the same core functions. 69 | 70 | * Installation 71 | :PROPERTIES: 72 | :CUSTOM_ID: installation 73 | :END: 74 | 75 | Currently, this project is not available in a package repository. As such, users will need to manually download the files (e.g. =git clone https://github.com/krisbalintona/denote-zettel-interface.git=) and ensure its dependencies are installed. Currently, these are the only third-party dependencies: 76 | 1. [[https://github.com/protesilaos/denote][Denote.el]] 77 | 2. [[https://github.com/emacsorphanage/tablist][Tablist.el]] (used for filtering =tabulated-list-mode= entries) 78 | Users can either evaluate something like this to install: 79 | #+begin_src emacs-lisp 80 | (use-package tablist 81 | :ensure t) 82 | 83 | (use-package denote-zettel-interface 84 | :load-path "/home/USER/PATH/TO/LOCAL/REPOSITORY") 85 | #+end_src 86 | Or, if using Emacs-30 or newer: 87 | #+begin_src emacs-lisp 88 | (use-package denote-zettel-interface 89 | :ensure t 90 | :vc ( :url "https://github.com/krisbalintona/denote-zettel-interface.git" 91 | :rev :newest)) 92 | #+end_src 93 | 94 | * Usage 95 | :PROPERTIES: 96 | :CUSTOM_ID: usage 97 | :END: 98 | 99 | ** Sample configuration 100 | :PROPERTIES: 101 | :CUSTOM_ID: sample-configuration 102 | :END: 103 | 104 | Here is a variant of the author's use-package configuration: 105 | #+begin_src emacs-lisp 106 | (use-package denote-zettel-interface 107 | :after denote 108 | :vc ( :url "https://github.com/krisbalintona/denote-zettel-interface.git" 109 | :rev :newest) 110 | :autoload denote-zettel-interface--signature-lessp 111 | :bind (("C-c n m" . denote-zettel-interface-list) 112 | ("C-c n r" . denote-zettel-interface-set-signature-list) 113 | ("C-c n R" . denote-zettel-interface-set-signature-minibuffer)) 114 | :custom 115 | (denote-zettel-interface-signature-column-width 116 | (+ 6 (cl-loop for file in (denote-directory-files) 117 | maximize (length (denote-retrieve-filename-signature file))))) 118 | (denote-zettel-interface-title-column-width 120) 119 | (denote-zettel-interface-starting-filter-presets 120 | ;; I have a "zettels" subdirectory that contains all my "main notes." I also 121 | ;; have a "bib" subdirectory that contains my org files pertaining to books, 122 | ;; videos, papers, articles, and so on. 123 | '("zettels/[^z-a]*" "bib/[^z-a]*")) 124 | (denote-zettel-interface-starting-filter "zettels/[^z-a]*") 125 | :init 126 | (with-eval-after-load 'denote 127 | (setopt denote-sort-signature-comparison-function #'denote-zettel-interface--signature-lessp))) 128 | #+end_src 129 | 130 | ** Sample workflow 131 | :PROPERTIES: 132 | :CUSTOM_ID: sample-workflow 133 | :END: 134 | 135 | 1. Call =M-x denote-zettel-interface-list= to list Denote notes. 136 | 2. Press =/ d= (or ~M-x denote-zettel-interface-edit-filter~) to filter your notes by regexp on denote file names. 137 | 3. Use =M-N, =M-P=, =M-n=, =M-p=, =M-d=, and =M-u= to navigate notes shown by way of their index numbering. 138 | 4. Create a new note. 139 | 5. In that note's buffer, call =M-x denote-zettel-interface-set-signature-list=[fn:3] or =M-x denote-zettel-interface-set-signature-minibuffer=[fn:4] to interactively select a folgezettel parent for that note. 140 | 6. That note is now a child of the chosen parent note, with an index numbering that is automatically set to the next available index numbering for children of the parent note. 141 | 142 | ** Commands 143 | :PROPERTIES: 144 | :CUSTOM_ID: commands 145 | :END: 146 | 147 | Below are a list of useful commands for those viewing the package for the first time. You can also find these commands and more via ~M-x apropos-command denote-zettel-interface RET~. 148 | + ~denote-zettel-interface-list~ 149 | Display list of Denote files in variable ~denote-directory~. 150 | + ~denote-zettel-interface-display-note~ 151 | Just display the current note in another window. 152 | + ~denote-zettel-interface-edit-filter~ 153 | Edit the currently existing filter. 154 | + ~denote-zettel-interface-filter-backward~ 155 | Filter the buffer to the next set of notes of the same level. 156 | + ~denote-zettel-interface-filter-forward~ 157 | Filter the buffer to the next set of notes of the same level. 158 | + ~denote-zettel-interface-filter-down~ 159 | Filter the buffer to the children of the current note. 160 | + ~denote-zettel-interface-filter-up~ 161 | Filter the buffer to the parent of the current note and its children. 162 | + ~denote-zettel-interface-filter-top-level-next~ 163 | Filter the buffer to the next index top-level notes. 164 | + ~denote-zettel-interface-filter-top-level-previous~ 165 | Filter the buffer to the next index top-level notes. 166 | + ~denote-zettel-interface-goto-note~ 167 | Jump to the note corresponding to the entry at point. 168 | + ~denote-zettel-interface-goto-note-other-window~ 169 | Open in another window the note corresponding to the entry at point. 170 | + ~denote-zettel-interface-set-signature~ 171 | Set the note at point's (in `denote-zettel-interface' buffer) signature. 172 | + ~denote-zettel-interface-set-signature-list~ 173 | Set the note at point's signature by selecting another note. 174 | + ~denote-zettel-interface-set-signature-minibuffer~ 175 | Set the note at point's signature by selecting another note. 176 | + ~denote-zettel-interface-store-link~ 177 | Call `org-store-link' on the entry at point if an org file. 178 | 179 | * Index numbering 180 | :PROPERTIES: 181 | :CUSTOM_ID: index-numbering 182 | :END: 183 | 184 | This project assumes the following folgezettel index numbering schema: 185 | + Denote [[https://protesilaos.com/emacs/denote#h:4e9c7512-84dc-4dfb-9fa9-e15d51178e5d][note signatures]] contain just the index numbering for that note. 186 | + They are in a format like "1=3a12c1". That is: 187 | - The beginning of the index numbering begins with a positive integer. 188 | - At any point, a "=" demarcates a new section of the index numbering.[fn:5] 189 | - In portions of the index numbering which are not demarcated into sections by "=" are demarcated by alternating between numbers in digits.[fn:6] 190 | + In a ~denote-zettel-interface-mode~ buffer, the "=" in these index numberings are rendered as periods. So: "1=3a12c1" becomes "1.3a12c1". 191 | 192 | * Footnotes 193 | :PROPERTIES: 194 | :CUSTOM_ID: footnotes 195 | :END: 196 | 197 | [fn:1] In fact, users can treat separate subdirectories as different Zettelkastens, each having their own index numbering. 198 | 199 | [fn:2] That is, if I have a new note and set its parent to a note whose index is "1=3a", then it will automatically be numbered as "1=3a2" if "1=3a1" is taken. 200 | 201 | [fn:3] This command produces a special ~denote-zettel-interface-mode~ buffer where =RET= will specially select the note at point as the folgezettel parent. 202 | 203 | [fn:4] This command creates a minibuffer prompt for selecting the folgezettel parent. The minibuffer prompt is grouped by top-level index numbering (i.e. all notes whose numbering begins with "1=..." are grouped together), so users of [[https://github.com/minad/vertico][vertico.el]] can use ~vertico-next-group~ and ~vertico-previous-group~ for quick navigation of the index. 204 | 205 | [fn:5] So equivalent to "1=3a12c1" is "1=3=a=12=c=1" and "1=3a12c=1" and so on. 206 | 207 | [fn:6] So "1=3a12c1" has sections "1", "3", "a", "12", "c", and "1". 208 | -------------------------------------------------------------------------------- /denote-zettel-interface.el: -------------------------------------------------------------------------------- 1 | ;;; denote-zettel-interface.el --- Zettelkasten interfaces for Denote.el -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2024 Kristoffer Balintona 4 | 5 | ;; Author: Kristoffer Balintona 6 | ;; Homepage: https://github.com/krisbalintona/denote-zettel-interface 7 | ;; Version: 0.2.2 8 | ;; Package-Requires: ((emacs "29.1") (org "9.3")) 9 | ;; Keywords: tools, extensions, convenience 10 | 11 | ;; This program is free software; you can redistribute it and/or modify 12 | ;; it under the terms of the GNU General Public License as published by 13 | ;; the Free Software Foundation, either version 3 of the License, or 14 | ;; (at your option) any later version. 15 | 16 | ;; This program is distributed in the hope that it will be useful, 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | ;; GNU General Public License for more details. 20 | 21 | ;; You should have received a copy of the GNU General Public License 22 | ;; along with this program. If not, see . 23 | 24 | ;;; Commentary: 25 | 26 | ;; Useful interfaces for those who use Denote.el as a Zettelkasten, especially 27 | ;; in a similar manner as an analog Zettelkasten. 28 | 29 | ;;; Code: 30 | (require 'tablist) 31 | (require 'denote) 32 | (require 's) 33 | (require 'subr-x) 34 | (require 'ol) 35 | 36 | ;;;; Variables 37 | ;;;;; Customizable 38 | (defgroup denote-zettel-interface () 39 | "Interfaces for denote files." 40 | :group 'files) 41 | 42 | (defcustom denote-zettel-interface-starting-filter "." 43 | "Default regexp filter for notes." 44 | :type 'sexp 45 | :group 'denote-zettel-interface) 46 | 47 | (defcustom denote-zettel-interface-starting-filter-presets "==" 48 | "The common `denote-zettel-interface-starting-filter' filters." 49 | :type 'regexp 50 | :group 'denote-zettel-interface) 51 | 52 | (defcustom denote-zettel-interface-signature-column-width 10 53 | "Width for signature column." 54 | :type 'natnum 55 | :group 'denote-zettel-interface) 56 | 57 | (defcustom denote-zettel-interface-title-column-width 85 58 | "Width for title column." 59 | :type 'natnum 60 | :group 'denote-zettel-interface) 61 | 62 | (defcustom denote-zettel-interface-keyword-column-width 30 63 | "Width for keywords column." 64 | :type 'natnum 65 | :group 'denote-zettel-interface) 66 | 67 | (defcustom denote-zettel-interface-unsorted-signature "000" 68 | "Special signature denoting \"unsorted\" note." 69 | :type 'string 70 | :group 'denote-zettel-interface) 71 | 72 | ;;;;; Internal 73 | (defvar denote-zettel-interface--id-to-path-cache nil 74 | "Signature cache for `denote-zettel-interface--get-entry-path'.") 75 | 76 | (defvar denote-zettel-interface--signature-propertize-cache nil 77 | "Signature cache for `denote-zettel-interface--signature-propertize'.") 78 | 79 | ;; REVIEW 2024-09-08: Reevaluate whether this is needed or not with our new 80 | ;; implementation of `denote-zettel-interface--signature-lessp'. I anticipate the 81 | ;; current implementation to be performant enough. 82 | (defvar denote-zettel-interface--signature-sort-cache nil 83 | "Signature cache for sorting via `denote-zettel-interface--signature-lessp'.") 84 | 85 | (defvar denote-zettel-interface--signature-relations 86 | '("Sibling" "Child" "Top-level") 87 | "List of possible note relations based on signatures. 88 | See `denote-zettel-interface--determine-new-signature' docstring for more 89 | information.") 90 | 91 | ;;;; Functions 92 | ;;;;; Signatures 93 | ;;;;;; Parsing 94 | (defun denote-zettel-interface--signature-normalize (sig) 95 | "Normalized SIG into a signature whose parts are separated by \"=\". 96 | 97 | This means that every transition from number to letter or letter to 98 | number warrants the insertion of a \"=\" to delimit it. 99 | 100 | Code supplied by Protesilaos Stavrou in 101 | https://protesilaos.com/codelog/2024-08-01-emacs-denote-luhmann-signature-sort/." 102 | (replace-regexp-in-string 103 | "\\([a-zA-Z]+?\\)\\([0-9]\\)" "\\1=\\2" 104 | (replace-regexp-in-string 105 | "\\([0-9]+?\\)\\([a-zA-Z]\\)" "\\1=\\2" 106 | (or sig "")))) ; Consider when there is no signature 107 | 108 | ;; TODO 2024-09-07: Perhaps have the "standardized format" be a customizable 109 | ;; variable? I would have to review all of the code because I started with the 110 | ;; assumption that my format would have to be adhered to, but with Protesilaos's 111 | ;; versatile way splitting of signatures, it might be possible to support 112 | ;; multiple signature formats. 113 | (defun denote-zettel-interface--signature-unnormalize (sig) 114 | "Convert a normalized SIG to our standardized format. 115 | A normalized signature's components are separated by \"=\". However, our 116 | standardized format only separates the first two components with a 117 | \"=\"." 118 | (save-match-data 119 | (if (string-match "=" sig) 120 | (concat (substring sig 0 (match-end 0)) 121 | (replace-regexp-in-string "=" "" sig nil nil nil (match-end 0))) 122 | sig))) ; For top-level signatures 123 | 124 | (defun denote-zettel-interface--signature-split (sig) 125 | "Split SIG into Luhmann-style parts. 126 | Returns a list of strings wherein each string is a part as described by 127 | the docstring of `denote-zettel-interface--signature-normalize'." 128 | (string-split (denote-zettel-interface--signature-normalize sig) "=" t)) 129 | 130 | (defun denote-zettel-interface--signature-padded-parts (sig) 131 | "Add padded spaces for all parts of SIG. 132 | For example, \"3=1b23d\" becomes \" 3= 1= b= 23= d\". 133 | This is useful for operations such as 134 | `denote-zettel-interface--signature-lessp' which string comparators. 135 | 136 | Modified code from Protesilaos Stavrou in 137 | https://protesilaos.com/codelog/2024-08-01-emacs-denote-luhmann-signature-sort/." 138 | (combine-and-quote-strings 139 | (mapcar (lambda (x) 140 | (string-pad x 5 32 t)) 141 | (denote-zettel-interface--signature-split sig)) 142 | "=")) 143 | 144 | ;;;;;; Calculating signatures based on relation 145 | (defun denote-zettel-interface--first-child-signature (sig) 146 | "Return the first child signature of SIG. 147 | For example, when SIG is \"13b3c,\" the returned signature is \"13b3c1.\"" 148 | (concat sig (if (s-numeric-p (substring sig (1- (length sig)))) "a" "1"))) 149 | 150 | (defun denote-zettel-interface--next-sibling-signature (sig &optional previous) 151 | "Return the next sibling signature of SIG. 152 | For example, the next sibling signature for \"a\" is \"b\", for \"9\" is 153 | \"10\", for \"z\" is \"A\", and for \"Z\" \"aa\". 154 | 155 | If PREVIOUS is non-nil, then the previous sibling's signature will be 156 | calculated instead." 157 | (let* ((parts (denote-zettel-interface--signature-split sig)) 158 | tail char next) 159 | (setq tail (car (last parts)) 160 | char (string-to-char tail) 161 | next (cond ((s-numeric-p tail) ; A number 162 | (number-to-string 163 | (+ (if previous -1 1) (string-to-number tail)))) 164 | ((and (>= char 97) (< char 122)) ; Between "a" and "z" 165 | (char-to-string (+ (if previous -1 1) char))) 166 | ((and (>= char 65) (< char 90)) ; Between "A" and "Z" 167 | (char-to-string (+ (if previous -1 1) char))) 168 | ((= 122 char) "A") ; Is "z" 169 | ;; REVIEW 2024-03-03: Presently, we choose to go into 170 | ;; double-letters when we go above Z 171 | ((= 90 char) "aa"))) ; Is "Z" 172 | (concat (string-remove-suffix tail sig) next))) 173 | 174 | (defun denote-zettel-interface--parent-signature (sig) 175 | "Return the parent signature of SIG." 176 | (denote-zettel-interface--signature-unnormalize 177 | (string-join (butlast (denote-zettel-interface--signature-split sig)) "="))) 178 | 179 | (defun denote-zettel-interface--determine-new-signature (sig relation &optional dir) 180 | "Return the next available signature relative to SIG. 181 | The new signature depends on RELATION, a string in 182 | `denote-zettel-interface--signature-relations'. If RELATION is \"child\", then 183 | return the next signature available for a new child note. If it is 184 | \"sibling\", then the new note will be the next available signature at 185 | the same hierarchical level as SIG. If it is \"top-level\", then the 186 | next available top-level signature will be returned. If RELATION is nil, 187 | then it defaults to a value of \"child\". 188 | 189 | If DIR is provided, check for the existence of signatures in that 190 | directory rather than the entirety of variable `denote-directory'. DIR 191 | can also be a file. If it is, the parent directory of that file will be 192 | used as the directory." 193 | (let* ((relation (or (downcase relation) "child")) 194 | (dir 195 | (file-name-directory 196 | (file-relative-name (or dir default-directory) denote-directory))) 197 | (next-sig (pcase relation 198 | ("child" 199 | (denote-zettel-interface--first-child-signature sig)) 200 | ("sibling" 201 | (denote-zettel-interface--next-sibling-signature sig)) 202 | ("top-level" 203 | (let ((top-level-index 1)) 204 | (while (denote-directory-files 205 | (rx (literal dir) 206 | (1+ anychar) 207 | "==" 208 | (literal (number-to-string top-level-index)) "=1")) 209 | (setq top-level-index (1+ top-level-index))) 210 | (concat (number-to-string top-level-index) "=1")))))) 211 | (while (member next-sig 212 | (cl-loop for f in (denote-directory-files dir) 213 | collect (denote-retrieve-filename-signature f))) 214 | (setq next-sig (denote-zettel-interface--next-sibling-signature next-sig))) 215 | next-sig)) 216 | 217 | ;;;;;; Propertize 218 | (defun denote-zettel-interface--signature-propertize (sig) 219 | "Return propertized SIG for hierarchical visibility." 220 | (or (and (not sig) "") 221 | (cdr (assoc-string sig denote-zettel-interface--signature-propertize-cache)) 222 | (let* ((parts (denote-zettel-interface--signature-split sig)) 223 | (level (1- (length parts))) 224 | (face 225 | (cond 226 | ((string= sig denote-zettel-interface-unsorted-signature) 227 | 'shadow) 228 | ((= 0 (+ 1 (% (1- level) 8))) 229 | 'denote-faces-signature) 230 | (t 231 | (intern (format "outline-%s" (+ 1 (% (1- level) 8))))))) 232 | (propertized-sig 233 | (replace-regexp-in-string "=" (propertize "." 'face 'shadow) 234 | (propertize sig 'face face)))) 235 | propertized-sig))) 236 | 237 | (defun denote-zettel-interface--file-signature-propertize (path) 238 | "Return propertized file signature from denote PATH identifier." 239 | (let ((sig (denote-retrieve-filename-signature path))) 240 | (denote-zettel-interface--signature-propertize sig))) 241 | 242 | ;;;;;; Caching 243 | (defun denote-zettel-interface--generate-caches () 244 | "Generate caches relevant to signatures. 245 | Speeds up `denote-zettel-interface' expensive operations. Populates the 246 | following internal variables: 247 | - `denote-zettel-interface--id-to-path-cache' 248 | - `denote-zettel-interface--signature-propertize-cache' 249 | - `denote-zettel-interface--signature-sort-cache' 250 | 251 | Call this function for its side effects." 252 | (let* ((files (denote-directory-files)) 253 | (sigs (cl-remove-duplicates 254 | (mapcar (lambda (f) (denote-retrieve-filename-signature f)) files) 255 | :test #'string-equal))) 256 | (setq denote-zettel-interface--id-to-path-cache 257 | (cl-loop for file in files 258 | collect (cons (denote-retrieve-filename-identifier file) file)) 259 | denote-zettel-interface--signature-sort-cache 260 | (sort sigs #'denote-zettel-interface--signature-lessp) 261 | denote-zettel-interface--signature-propertize-cache 262 | (cl-loop for sig in sigs 263 | collect (cons sig (denote-zettel-interface--signature-propertize sig))))) 264 | t) 265 | 266 | ;;;;; Titles 267 | (defun denote-zettel-interface--file-title-propertize (path) 268 | "Return propertized title of PATH. 269 | If the denote file PATH has no title, return the string \"(No 270 | Title)\". Otherwise return PATH's title. 271 | 272 | Determine whether a denote file has a title based on the 273 | following rule derived from the file naming scheme: 274 | 275 | 1. If the path does not have a \"--\", it has no title." 276 | (let* ((titlep (string-match-p "--" path)) 277 | (sig (denote-retrieve-filename-signature path)) 278 | (file-type (denote-filetype-heuristics path)) 279 | (title (denote-retrieve-front-matter-title-value path file-type)) 280 | (face 281 | (cond 282 | ;; When SIG is the unsorted signature 283 | ((string= sig denote-zettel-interface-unsorted-signature) 284 | 'denote-faces-title) 285 | ;; When PATH is a "indicator note" (i.e. a note strictly for 286 | ;; indicator subdivisions among the numbered indexes) 287 | ((and sig (not (cdr (denote-zettel-interface--signature-split sig)))) 288 | 'denote-faces-signature) 289 | ;; Otherwise 290 | (t 'denote-faces-title)))) 291 | (if titlep 292 | (propertize title 'face face) 293 | (propertize "(No Title)" 'face 'shadow)))) 294 | 295 | ;;;;; Keywords 296 | (defun denote-zettel-interface--file-keywords-propertize (path) 297 | "Return propertized keywords of PATH." 298 | (string-join 299 | (mapcar (lambda (s) (propertize s 'face 'denote-faces-keywords)) 300 | (denote-extract-keywords-from-path path)) 301 | (propertize ", " 'face 'shadow))) 302 | 303 | ;;;;; Entries 304 | (defun denote-zettel-interface--get-entry-path (&optional id) 305 | "Get the file path of the entry at point. 306 | ID is the ID of the `tabulated-list' entry." 307 | (or (cdr (assoc-string id denote-zettel-interface--id-to-path-cache)) 308 | (let* ((id (or id (tabulated-list-get-id))) 309 | (path (denote-get-path-by-id id))) 310 | (setf (alist-get id denote-zettel-interface--id-to-path-cache) path) 311 | path))) 312 | 313 | (defun denote-zettel-interface--entries-to-paths () 314 | "Return list of file paths present in the `denote-zettel-interface' buffer." 315 | (mapcar (lambda (entry) 316 | (denote-zettel-interface--get-entry-path (car entry))) 317 | (funcall tabulated-list-entries))) 318 | 319 | (defun denote-zettel-interface--path-to-entry (path) 320 | "Convert PATH to an entry in the form of `tabulated-list-entries'." 321 | ;; Sometimes PATH will not exist, mostly because the file has been renamed. 322 | ;; The following corrects PATH. This method relies on the persistence of the 323 | ;; identifier; if the identifier of the file has changed, then the function 324 | ;; will return nil (the file will not be shown in the denote-zettel-interface 325 | ;; buffer). 326 | (unless (file-regular-p path) 327 | (setq path 328 | (car (denote-directory-files (denote-retrieve-filename-identifier path))))) 329 | (when path 330 | `(,(denote-retrieve-filename-identifier path) 331 | [,(denote-zettel-interface--file-signature-propertize path) 332 | ,(denote-zettel-interface--file-title-propertize path) 333 | ,(denote-zettel-interface--file-keywords-propertize path)]))) 334 | 335 | ;;;;; Sorters 336 | (defun denote-zettel-interface--signature-lessp (sig1 sig2) 337 | "Compare two strings based on my signature sorting rules. 338 | Returns t if SIG1 should be sorted before SIG2, nil otherwise. Uses 339 | `string<' to compare strings. 340 | 341 | Special exception is given to the `denote-zettel-interface-unsorted-signature' 342 | signature. If SIG1 or SIG2 match `denote-zettel-interface-unsorted-signature', 343 | it will be sorted such that `denote-zettel-interface-unsorted-signature' is 344 | always less, which allows those notes to precede all other notes." 345 | (let ((cache denote-zettel-interface--signature-sort-cache)) 346 | (cond 347 | ((string= denote-zettel-interface-unsorted-signature sig1) t) 348 | ((string= denote-zettel-interface-unsorted-signature sig2) nil) 349 | ((and (member sig1 cache) (member sig2 cache)) 350 | (< (cl-position sig1 cache :test #'equal) 351 | (cl-position sig2 cache :test #'equal))) 352 | (t (string< (denote-zettel-interface--signature-padded-parts sig1) 353 | (denote-zettel-interface--signature-padded-parts sig2)))))) 354 | 355 | (defun denote-zettel-interface--signature-sorter (a b) 356 | "Tabulated-list sorter for entries A and B. 357 | Note that this function needs to be performant, otherwise 358 | `denote-zettel-interface' loading time suffers greatly." 359 | (let* ((sig1 (aref (cadr a) 0)) 360 | (sig2 (aref (cadr b) 0))) 361 | ;; FIXME 2024-03-04: I have to replace "."s with "=" because in 362 | ;; `denote-zettel-interface--path-to-entry' I do the reverse. This is quite 363 | ;; fragile, so try to find a more robust alternative 364 | (setq sig1 (replace-regexp-in-string "\\." "=" sig1) 365 | sig2 (replace-regexp-in-string "\\." "=" sig2)) 366 | (denote-zettel-interface--signature-lessp sig1 sig2))) 367 | 368 | ;;;; Major-modes and keymaps 369 | (defvar-keymap denote-zettel-interface-mode-map 370 | :doc "Mode map for `denote-zettel-interface-mode'." 371 | :parent tablist-mode-map 372 | "/ d" #'denote-zettel-interface-edit-filter 373 | "/ D" #'denote-zettel-interface-edit-filter-presets 374 | "RET" #'denote-zettel-interface-goto-note 375 | "o" #'denote-zettel-interface-goto-note-other-window 376 | "C-o" #'denote-zettel-interface-display-note 377 | "r" #'denote-zettel-interface-set-signature-list 378 | "R" #'denote-zettel-interface-set-signature-minibuffer 379 | "w" #'denote-zettel-interface-store-link 380 | "M-N" #'denote-zettel-interface-filter-forward 381 | "M-P" #'denote-zettel-interface-filter-backward 382 | "M-n" #'denote-zettel-interface-filter-top-level-next 383 | "M-p" #'denote-zettel-interface-filter-top-level-previous 384 | "M-u" #'denote-zettel-interface-filter-up 385 | "M-d" #'denote-zettel-interface-filter-down) 386 | 387 | (define-derived-mode denote-zettel-interface-mode tablist-mode "Denote Interface" 388 | "Major mode for interfacing with Denote files." 389 | :interactive nil 390 | :group 'denote-zettel-interface 391 | :after-hook (set (make-local-variable 'mode-line-misc-info) 392 | (append 393 | (list 394 | (list 'denote-zettel-interface-starting-filter 395 | '(:eval (format " [%s]" denote-zettel-interface-starting-filter)))))) 396 | (unless (and denote-zettel-interface--id-to-path-cache 397 | denote-zettel-interface--signature-sort-cache 398 | denote-zettel-interface--signature-propertize-cache) 399 | (denote-zettel-interface--generate-caches)) 400 | (setq tabulated-list-format 401 | `[("Signature" ,denote-zettel-interface-signature-column-width denote-zettel-interface--signature-sorter) 402 | ("Title" ,denote-zettel-interface-title-column-width t) 403 | ("Keywords" ,denote-zettel-interface-title-column-width nil)] 404 | tabulated-list-entries 405 | (lambda () (mapcar #'denote-zettel-interface--path-to-entry 406 | (denote-directory-files denote-zettel-interface-starting-filter))) 407 | tabulated-list-sort-key '("Signature" . nil)) 408 | (use-local-map denote-zettel-interface-mode-map) 409 | (tabulated-list-init-header) 410 | (tabulated-list-print)) 411 | 412 | (defun denote-zettel-interface-list (&optional name) 413 | "Display list of Denote files in variable `denote-directory'. 414 | If NAME is supplied, that will be the name of the buffer." 415 | (interactive nil) 416 | (let ((buf-name (cond 417 | ((stringp name) name) 418 | (current-prefix-arg 419 | (format "*Denote notes: %s*" (read-from-minibuffer "Name for new buffer: "))) 420 | (t 421 | (format "*Denote notes in %s*" 422 | (abbreviate-file-name (buffer-local-value 'denote-directory (current-buffer)))))))) 423 | ;; TODO 2024-03-28: Haven't figured out how to adhere to the current 424 | ;; denote-silo convention of setting `denote-directory' in .dir-locals 425 | (unless (get-buffer buf-name) 426 | (with-current-buffer (get-buffer-create buf-name) 427 | (setq buffer-file-coding-system 'utf-8) 428 | (denote-zettel-interface-mode))) 429 | (display-buffer buf-name))) 430 | 431 | ;;;; Commands 432 | ;;;;; Filtering 433 | ;;;###autoload 434 | (defun denote-zettel-interface-edit-filter () 435 | "Edit the currently existing filter." 436 | (interactive) 437 | (setq denote-zettel-interface-starting-filter 438 | (read-from-minibuffer "Filter regex: " denote-zettel-interface-starting-filter)) 439 | (revert-buffer)) 440 | 441 | ;;;###autoload 442 | (defun denote-zettel-interface-edit-filter-presets () 443 | "Edit the currently existing filter." 444 | (interactive) 445 | (setq denote-zettel-interface-starting-filter 446 | (completing-read "Filter preset: " 447 | (remove denote-zettel-interface-starting-filter denote-zettel-interface-starting-filter-presets))) 448 | (revert-buffer)) 449 | 450 | ;;;;; Viewing 451 | ;;;###autoload 452 | (defun denote-zettel-interface-goto-note () 453 | "Jump to the note corresponding to the entry at point." 454 | (interactive) 455 | (find-file (denote-zettel-interface--get-entry-path))) 456 | 457 | ;;;###autoload 458 | (defun denote-zettel-interface-goto-note-other-window () 459 | "Open in another window the note corresponding to the entry at point." 460 | (interactive) 461 | (find-file-other-window (denote-zettel-interface--get-entry-path))) 462 | 463 | ;;;###autoload 464 | (defun denote-zettel-interface-display-note () 465 | "Just display the current note in another window." 466 | (interactive) 467 | (display-buffer (find-file-noselect (denote-zettel-interface--get-entry-path)) t)) 468 | 469 | ;;;;; Signatures 470 | ;;;###autoload 471 | (defun denote-zettel-interface-set-signature (path new-sig) 472 | "Set the note at point's (in `denote-zettel-interface' buffer) signature. 473 | Can be called interactively from a denote note or a `denote-zettel-interface' 474 | entry. If called non-interactively, set the signature of PATH to 475 | NEW-SIG." 476 | (interactive (list (cond ((derived-mode-p 'denote-zettel-interface-mode) 477 | (denote-zettel-interface--get-entry-path)) 478 | ((denote-file-is-note-p (buffer-file-name)) 479 | (buffer-file-name)) 480 | (t 481 | (user-error "Must use in `denote-zettel-interface' or a Denote note!"))) 482 | nil)) 483 | (let* ((path (or path (denote-zettel-interface--get-entry-path))) 484 | (file-type (denote-filetype-heuristics path)) 485 | (title (denote-retrieve-title-value path file-type)) 486 | (initial-sig (denote-retrieve-filename-signature path)) 487 | (new-sig (or new-sig 488 | (denote-signature-prompt 489 | (unless (string= initial-sig denote-zettel-interface-unsorted-signature) 490 | initial-sig) 491 | "Choose new signature"))) 492 | (keywords 493 | (denote-retrieve-front-matter-keywords-value path file-type)) 494 | (date (denote-retrieve-filename-identifier path))) 495 | (denote-rename-file path title keywords new-sig date))) 496 | 497 | (defun denote-zettel-interface--group-text-property (text sig) 498 | "Set the `denote-zettel-interface-sig' text property in TEXT. 499 | The value the `denote-zettel-interface-sig' property will be set to will be the 500 | leading component of SIG. For example, the leading component for \"3=b\" 501 | is \"3\". This function only produces side effects." 502 | (add-text-properties 0 503 | (length text) 504 | (list 'denote-zettel-interface-sig (if sig 505 | (car (denote-zettel-interface--signature-split sig)) 506 | "No signature")) 507 | text)) 508 | 509 | ;;;###autoload 510 | (defun denote-zettel-interface-set-signature-minibuffer (files) 511 | "Set the note at point's signature by selecting another note. 512 | Select another note and choose whether to be its the sibling or child. 513 | 514 | Also accepts FILES, which are the list of file paths which are 515 | considered. 516 | 517 | If nil or called interactively, then defaults `denote-directory-files' 518 | constrained to notes with signatures (i.e. \"==\") and are in the 519 | current subdirectory (this is my bespoke desired behavior), as well as 520 | the :omit-current non-nil. Otherwise,when called interactively in 521 | `denote-zettel-interface', it will be the value of 522 | `denote-zettel-interface--entries-to-paths'." 523 | (interactive (list (if (eq major-mode 'denote-zettel-interface-mode) 524 | (denote-zettel-interface--entries-to-paths) 525 | (denote-directory-files 526 | (rx (literal (car (last (butlast (file-name-split (buffer-file-name)) 1)))) 527 | "/" (* alnum) "==") 528 | :omit-current)))) 529 | (let* ((file-at-point (cond ((derived-mode-p 'denote-zettel-interface-mode) 530 | (denote-zettel-interface--get-entry-path)) 531 | ((denote-file-is-note-p (buffer-file-name)) 532 | (buffer-file-name)) 533 | (t 534 | (user-error "Must use in `denote-zettel-interface' or a Denote note!")))) 535 | (files (remove file-at-point 536 | (or files (denote-directory-files 537 | (rx (literal (car (last (butlast (file-name-split (buffer-file-name)) 1)))) 538 | "/" (* alnum) "==") 539 | :omit-current)))) 540 | (files 541 | (cl-loop for file in files collect 542 | (let ((sig (denote-retrieve-filename-signature file))) 543 | (denote-zettel-interface--group-text-property file sig) 544 | file))) 545 | (largest-sig-length 546 | (cl-loop for file in files 547 | maximize (length (denote-retrieve-filename-signature file)))) 548 | (display-sort-function 549 | (lambda (completions) 550 | (cl-sort completions 551 | 'denote-zettel-interface--signature-lessp 552 | :key (lambda (c) (denote-retrieve-filename-signature c))))) 553 | (group-function 554 | (lambda (title transform) 555 | (if transform 556 | title 557 | (get-text-property 0 'denote-zettel-interface-sig title)))) 558 | (affixation-function 559 | (lambda (files) 560 | (cl-loop for file in files collect 561 | (let* ((propertized-title (denote-zettel-interface--file-title-propertize file)) 562 | (sig (denote-retrieve-filename-signature file)) 563 | (propertized-sig (denote-zettel-interface--file-signature-propertize file))) 564 | (denote-zettel-interface--group-text-property propertized-title sig) 565 | (list propertized-title 566 | (string-pad propertized-sig (+ largest-sig-length 3)) 567 | nil))))) 568 | (selection 569 | (completing-read "Choose a note: " 570 | (lambda (str pred action) 571 | (if (eq action 'metadata) 572 | `(metadata 573 | (display-sort-function . ,display-sort-function) 574 | (group-function . ,group-function) 575 | (affixation-function . ,affixation-function)) 576 | (complete-with-action action files str pred))) 577 | nil t)) 578 | (note-relation 579 | (downcase (completing-read "Choose relation: " denote-zettel-interface--signature-relations))) 580 | (new-sig (denote-zettel-interface--determine-new-signature 581 | (denote-retrieve-filename-signature selection) 582 | note-relation 583 | selection))) 584 | (denote-zettel-interface-set-signature file-at-point new-sig))) 585 | 586 | ;;;###autoload 587 | (defun denote-zettel-interface-set-signature-list (files) 588 | "Set the note at point's signature by selecting another note. 589 | Like `denote-zettel-interface-set-signature-minibuffer' but uses 590 | `denote-zettel-interface-selection-mode' instead of minibuffer. 591 | 592 | FILES are the list of files shown, defaulting to all denote files. When 593 | \"RET\" or \"q\" is called on a note, the new signature of the file to 594 | be modified will be set relative to that note. See 595 | `denote-zettel-interface--determine-new-signature' for more details." 596 | (interactive (list (if (eq major-mode 'denote-zettel-interface-mode) 597 | (progn 598 | (revert-buffer) ; Ensure entries align with changes to files 599 | (cl-remove 600 | ;; Ensure the note whose signature is being modified 601 | ;; is not in the resultant list of files 602 | (denote-zettel-interface--get-entry-path) 603 | (denote-zettel-interface--entries-to-paths) 604 | :test #'string-equal)) 605 | (denote-directory-files 606 | (rx (literal (concat (car (last (butlast (file-name-split (buffer-file-name)) 1))) 607 | "/")) 608 | (* alnum) "==") 609 | :omit-current)))) 610 | (let* ((file-at-point (cond ((derived-mode-p 'denote-zettel-interface-mode) 611 | (denote-zettel-interface--get-entry-path)) 612 | ((denote-file-is-note-p (buffer-file-name)) 613 | (buffer-file-name)) 614 | (t 615 | (user-error "Must use in `denote-zettel-interface' or a Denote note!")))) 616 | (files (remove file-at-point 617 | (or files (denote-directory-files 618 | (rx (literal (car (last (butlast (file-name-split (buffer-file-name)) 1)))) 619 | "/" (* alnum) "==") 620 | :omit-current)))) 621 | (file-type (denote-filetype-heuristics file-at-point)) 622 | (buf-name (format "*Modify the signature of %s %s*" 623 | (denote-retrieve-filename-signature file-at-point) 624 | (denote-retrieve-front-matter-title-value file-at-point file-type))) 625 | (select-func 626 | `(lambda () 627 | "Change desired note's signature relate to the chosen note." 628 | (interactive) 629 | (let* ((selection (denote-zettel-interface--get-entry-path)) 630 | (note-relation 631 | (downcase (completing-read "Choose relation: " 632 | denote-zettel-interface--signature-relations))) 633 | (new-sig (denote-zettel-interface--determine-new-signature 634 | (denote-retrieve-filename-signature selection) 635 | note-relation 636 | selection))) 637 | (denote-zettel-interface-set-signature ,file-at-point new-sig) 638 | (kill-buffer ,buf-name)))) 639 | (confirm-quit-func 640 | `(lambda () 641 | "Kill buffer with confirmation" 642 | (interactive) 643 | (when (y-or-n-p (format "Leave before modifying signature of %s?" 644 | ,(denote-retrieve-front-matter-title-value file-at-point file-type))) 645 | (kill-buffer ,buf-name)))) 646 | (keymap (make-sparse-keymap))) 647 | (denote-zettel-interface-list buf-name) 648 | (with-current-buffer buf-name 649 | (setq tabulated-list-entries 650 | (lambda () (mapcar #'denote-zettel-interface--path-to-entry files))) 651 | (revert-buffer) 652 | (set-keymap-parent keymap denote-zettel-interface-mode-map) 653 | (define-key keymap (kbd "RET") select-func) 654 | (define-key keymap (kbd "q") confirm-quit-func) 655 | (use-local-map keymap)))) 656 | 657 | ;;;;; Navigation 658 | (defun denote-zettel-interface--validate-signature-cycling (sig &optional backward) 659 | "Ensure that SIG cycles if such a file does not exist. 660 | If a file with SIG does not exist (given the value of 661 | `denote-zettel-interface-starting-filter'), then this function will return the 662 | next signature of an existing file according to BACKWARD. That is, in 663 | the cases that SIG does not have an existing note, if BACKWARD is nil 664 | then the lowest signature will be returned, but if BACKWARD is non-nil 665 | then the highest signature will be returned." 666 | (if (denote-directory-files 667 | (rx (regexp denote-zettel-interface-starting-filter) "==" (literal sig))) 668 | sig 669 | (let* ((parts (denote-zettel-interface--signature-split sig)) 670 | (all-but-last-part (butlast (denote-zettel-interface--signature-split sig))) 671 | (last-part (car (last parts))) 672 | (last-part-num-p (string-match-p "^[0-9]+$" last-part))) 673 | (if backward 674 | (car 675 | (last 676 | (cl-remove-if-not 677 | (lambda (s) 678 | (= (length parts) (length (denote-zettel-interface--signature-split s)))) 679 | (cl-sort 680 | (mapcar 681 | (lambda (f) (denote-retrieve-filename-signature f)) 682 | (denote-directory-files 683 | (rx (regexp denote-zettel-interface-starting-filter) 684 | "==" 685 | (literal (denote-zettel-interface--parent-signature sig))))) 686 | 'denote-zettel-interface--signature-lessp)))) 687 | (denote-zettel-interface--signature-unnormalize 688 | (string-join 689 | (append all-but-last-part 690 | (list (if last-part-num-p "1" "a"))) 691 | "=")))))) 692 | 693 | ;;;###autoload 694 | (defun denote-zettel-interface-filter-top-level-next (N) 695 | "Filter the buffer to the next index top-level notes. 696 | Go forward N top-levels. 697 | 698 | Uses `tablist' filters." 699 | (interactive (list (or (and (numberp current-prefix-arg) 700 | current-prefix-arg) 701 | 1))) 702 | (let* ((files (denote-directory-files denote-zettel-interface-starting-filter)) 703 | (signature-heads (mapcar (lambda (f) 704 | (car 705 | (denote-zettel-interface--signature-split 706 | (denote-retrieve-filename-signature f)))) 707 | files)) 708 | (min-top-level 709 | (cl-loop for s in signature-heads minimize (string-to-number (or s "")))) 710 | (max-top-level 711 | (cl-loop for s in signature-heads maximize (string-to-number (or s "")))) 712 | (path (denote-zettel-interface--get-entry-path)) 713 | (sig (denote-retrieve-filename-signature path)) 714 | (sig-top-level 715 | (string-to-number (car (denote-zettel-interface--signature-split sig)))) 716 | (next-top-level (+ N sig-top-level)) 717 | (next-top-level 718 | (cond 719 | ((and (<= min-top-level next-top-level) (<= next-top-level max-top-level)) 720 | next-top-level) 721 | ((< next-top-level min-top-level) 722 | (+ max-top-level sig-top-level)) 723 | ((< max-top-level next-top-level) 724 | (- sig-top-level max-top-level)))) 725 | (regexp 726 | (if (= next-top-level (string-to-number denote-zettel-interface-unsorted-signature)) 727 | (rx bol (literal denote-zettel-interface-unsorted-signature)) 728 | (rx bol (literal (number-to-string next-top-level)) (or eol (not digit)))))) 729 | ;; OPTIMIZE 2024-03-17: Right now this assumes that the head of the filters 730 | ;; is a previous filter made by this command. 731 | (tablist-pop-filter 1) 732 | (tablist-push-regexp-filter "Signature" regexp))) 733 | 734 | ;;;###autoload 735 | (defun denote-zettel-interface-filter-top-level-previous (N) 736 | "Filter the buffer to the next index top-level notes. 737 | Go backward N top-levels. 738 | 739 | Uses `tablist' filters." 740 | (interactive (list (or (and (numberp current-prefix-arg) 741 | (- current-prefix-arg)) 742 | -1))) 743 | (denote-zettel-interface-filter-top-level-next N)) 744 | 745 | ;;;###autoload 746 | (defun denote-zettel-interface-filter-forward (N) 747 | "Filter the buffer to the next set of notes of the same level. 748 | Go forward N levels, defaulting to 1. 749 | 750 | Uses `tablist' filters." 751 | (interactive (list (or (and (numberp current-prefix-arg) 752 | current-prefix-arg) 753 | 1))) 754 | (let* ((path (denote-zettel-interface--get-entry-path)) 755 | (sig (denote-retrieve-filename-signature path)) 756 | (sibling-sig sig) 757 | regexp) 758 | (dotimes (_ (abs N)) 759 | (setq sibling-sig 760 | (denote-zettel-interface--validate-signature-cycling 761 | (denote-zettel-interface--next-sibling-signature sibling-sig (< N 0)) 762 | (< N 0)))) 763 | ;; If there are only numbers in the final sibling-sig, then that means it is 764 | ;; an indexical (e.g. "1" or "15" as opposed to "1=1", etc.). In those 765 | ;; cases, to avoid too broad a regexp (e.g. "^2"), we need to apply a 766 | ;; special regexp. 767 | (setq regexp 768 | (if (string-match-p "\\`[0-9]+\\'" sibling-sig) 769 | (rx bol (literal sibling-sig) (or eol (not digit))) 770 | ;; FIXME 2024-09-07: I have to replace "."s with "=" because in 771 | ;; `denote-zettel-interface--path-to-entry' I do the reverse. This is quite 772 | ;; fragile, so try to find a more robust alternative 773 | (rx bol (literal (replace-regexp-in-string "=" "." sibling-sig))))) 774 | ;; OPTIMIZE 2024-03-17: Right now this assumes that the head of the filters 775 | ;; is a previous filter made by this command. 776 | (tablist-pop-filter 1) 777 | (tablist-push-regexp-filter "Signature" regexp))) 778 | 779 | ;;;###autoload 780 | (defun denote-zettel-interface-filter-backward (N) 781 | "Filter the buffer to the next set of notes of the same level. 782 | Go backward N levels, defaulting to 1. 783 | 784 | Uses `tablist' filters." 785 | (interactive (list (or (and (numberp current-prefix-arg) 786 | (- current-prefix-arg)) 787 | -1))) 788 | (denote-zettel-interface-filter-forward N)) 789 | 790 | ;;;###autoload 791 | (defun denote-zettel-interface-filter-down () 792 | "Filter the buffer to the children of the current note. 793 | Uses `tablist' filters." 794 | (interactive) 795 | (let* ((path (denote-zettel-interface--get-entry-path)) 796 | (sig (denote-retrieve-filename-signature path)) 797 | (child-sig 798 | (if (string-match "=" sig) 799 | (denote-zettel-interface--first-child-signature sig) 800 | (concat sig "=1"))) ; Don't use "." yet since it breaks the following regexp search 801 | (regexp 802 | (if (denote-directory-files 803 | (rx (regexp denote-zettel-interface-starting-filter) "==" (literal child-sig))) 804 | ;; FIXME 2024-09-07: I have to replace "."s with "=" because in 805 | ;; `denote-zettel-interface--path-to-entry' I do the reverse. This is 806 | ;; quite fragile, so try to find a more robust alternative 807 | (rx bol (literal (replace-regexp-in-string "=" "." child-sig))) 808 | (rx bol (literal (replace-regexp-in-string "=" "." sig)))))) 809 | ;; OPTIMIZE 2024-03-17: Right now this assumes that the head of the filters 810 | ;; is a previous filter made by this command. 811 | (tablist-pop-filter 1) 812 | (tablist-push-regexp-filter "Signature" regexp))) 813 | 814 | ;;;###autoload 815 | (defun denote-zettel-interface-filter-up () 816 | "Filter the buffer to the parent of the current note and its children. 817 | Uses `tablist' filters." 818 | (interactive) 819 | (let* ((path (denote-zettel-interface--get-entry-path)) 820 | (sig (denote-retrieve-filename-signature path)) 821 | (parent-sig (denote-zettel-interface--parent-signature sig)) 822 | (regexp 823 | (cond 824 | ((string-empty-p parent-sig) nil) 825 | ((not (string-match-p "=" parent-sig)) 826 | (rx bol (literal parent-sig) (or eol (not digit)))) 827 | ((not (string-empty-p parent-sig)) 828 | ;; FIXME 2024-09-07: I have to replace "."s with "=" because in 829 | ;; `denote-zettel-interface--path-to-entry' I do the reverse. This is quite 830 | ;; fragile, so try to find a more robust alternative 831 | (rx bol (literal (replace-regexp-in-string "=" "." parent-sig))))))) 832 | ;; OPTIMIZE 2024-03-17: Right now this assumes that the head of the filters 833 | ;; is a previous filter made by this command. 834 | (tablist-pop-filter 1) 835 | (when regexp 836 | (tablist-push-regexp-filter "Signature" regexp) 837 | (goto-char (point-min)) 838 | (tablist-skip-invisible-entries) 839 | (goto-char (1+ (point)))))) 840 | 841 | ;;;;; Storing 842 | ;;;###autoload 843 | (defun denote-zettel-interface-store-link () 844 | "Call `org-store-link' on the entry at point if an org file." 845 | (interactive) 846 | (when-let* ((file (denote-zettel-interface--get-entry-path)) 847 | (file-id (denote-retrieve-filename-identifier file)) 848 | (description (denote-get-link-description file)) 849 | (orgp (string= "org" (file-name-extension file)))) 850 | ;; Populate `org-store-link-plist'. Inspired by `denote-link-ol-store' 851 | (org-link-store-props 852 | :type "denote" 853 | :description description 854 | :link (concat "denote:" file-id)) 855 | ;; Then add to `org-stored-links' 856 | (push (list (plist-get org-store-link-plist :link) 857 | (plist-get org-store-link-plist :description)) 858 | org-stored-links) 859 | (message "Stored %s!" (file-relative-name file denote-directory)))) 860 | 861 | ;;; [End] 862 | (provide 'denote-zettel-interface) 863 | ;;; denote-zettel-interface.el ends here 864 | --------------------------------------------------------------------------------