[
  {
    "path": ".gitignore",
    "content": "*.elc\n*-autoloads.el\n*-pkg.el\n.dir-locals.el\ndir\ntutorial/\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<https://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<https://www.gnu.org/licenses/why-not-lgpl.html>.\n"
  },
  {
    "path": "Makefile",
    "content": ".POSIX:\nPROG\t\t= binder\nLISP_FILE\t= ${PROG}.el\nDEPS\t\t= seq package-lint\nNEWS_FILE\t= NEWS\nVERS\t\t= ${shell grep -oE -m1 'Version:[ 0-9.]+' ${LISP_FILE} | tr -d :}\nTAG\t\t= ${shell echo ${VERS} | sed -E 's/Version:? ([0-9.]+)/v\\1/'}\nINIT\t\t= (progn \\\n  (require (quote package)) \\\n  (push (cons \"melpa\" \"https://melpa.org/packages/\") package-archives) \\\n  (package-initialize) \\\n  (mapc (lambda (pkg) \\\n          (unless (package-installed-p pkg) \\\n            (unless (assoc pkg package-archive-contents) \\\n              (package-refresh-contents)) \\\n            (package-install pkg))) \\\n        (quote (${DEPS}))))\n\nhelp:\n\t@echo check\n\t@echo compile\n\t@echo all: clean check compile\n\t@echo tag-release: check compile\n\t@echo clean\n\nall: clean check compile\n\ncheck:\n\temacs -Q --eval '${INIT}' --batch -f package-lint-batch-and-exit ${LISP_FILE}\n\ncompile:\n\temacs -Q --eval '${INIT}' -L . --batch -f batch-byte-compile ${LISP_FILE}\n\ntag-release: check compile\n\tsed -i~ '1 s/.*/* ${VERS}/' ${NEWS_FILE}\n\tgit commit -m 'Add ${VERS} to ${NEWS_FILE}' ${NEWS_FILE}\n\tawk '/^* Version/ { v ++1 } v == 1' ${NEWS_FILE} | sed 's/^* //' | git tag -F - ${TAG}\n\nclean:\n\trm -f ${PROG}.elc\n"
  },
  {
    "path": "NEWS",
    "content": "* current\n\n- Use buttons in sidebar, allowing mouse interaction\n- Remove \"include\" and \"concat\" feature, this is better served with tags\n  and other tools\n- Change Binder-Format-Version to 3, providing automatic upgrade to\n  convert \"(include . t)\" properties to #include tags\n- Add binder-sidebar-copy-filepath command on c key\n- Do not force bold header-line-format\n- Print existing filepath when calling binder-sidebar-relocate\n- Ensure indent-tabs-mode is nil in sidebar, preventing misalignment of\n  tags\n- Append faces in sidebar to allow multiple faces, e.g. button +\n  binder-sidebar-highlight\n\n* Version 0.4.4\n\n- Add binder-sidebar-clear-filters (|) and remove clear-filters arg from\n  binder-sidebar-refresh\n- Set project file to use lisp-data-mode\n- Revert change of sidebar selection face\n- Use a single-line prompt when switching project directory\n- Remove unnecessary autoloads\n- History is now tracked in a fancy NEWS file\n- Update email, URL\n\n* Version 0.4.3\n\n- Use file-relative-name for binder-file-relative-to-root -- this will\n  set a fileid outside of the project directory as a relative path\n  instead of absolute\n- Add faces binder-sidebar and binder-notes with face remap to default\n- Quit and kill binder side windows in all frames on quit\n- Remove call to hack-local-variables from binder-sidebar-refresh, as\n  this can cause a segfault\n- Make safer use of set-transient-map\n- Add hints for clearing sidebar tag filters (g key)\n- Add binder-theme.el to contrib/\n- Small imporvements to tutorial\n- Track known issues with FIXME comments in source\n- Stipulate acknowledgement of Scrivener in redistribution terms\n- Update email, and upstream URL to https://git.skeletons.cc/binder\n- Update repository for portability (add a screenshot, no more relying\n  on GitHub stuff)\n\n* Version 0.4.2\n\n- Give notes window same display alist as sidebar window\n- Fix byte-compile issue with lisp-mnt (just don't use it)\n\n* Version 0.4.1\n\n- Correct spelling of option binder-default-file-extension\n\n* Version 0.4.0\n\n- Implement binder-tutorial as separate library\n- Don't call binder-mode from binder-reveal-in-sidebar\n\n* Version 0.3.1\n\nThis release marks Binder as no longer in alpha status.\n\n- Ensure notes window keeps track of fileid\n\n    - No longer set pop-up-windows as buffer-local in sidebar, set it\n      lexically.\n    - binder-get-buffer-fileid returns binder--notes-fileid when in\n      notes window.\n    - binder-show-notes now takes FILEID and SELECT to make tracking\n      notes fileid easier, no longer needing to find it from sidebar.\n\n- Hack local variables when refreshing sidebar\n- Implement item shifting when filtered by tag\n- Prefer elt to nth\n\n* Version 0.3.0\n\nChanges\n\n- Change project file format to version 2 (adds binder-upgrade subr)\n- Implement binder-init-project command\n- Implement binder-sidebar-toggle-hide-tags command\n- Add binder-filter function\n- Rename binder-concat-find-original-file -> binder-concat-find-original\n- Change binder-concat-find-original key binding to C-c RET\n- Revert key binding for binder-sidebar-change-directory (P -> C)\n- Save project and clear cache on quit\n- Always write project data to file on delete item\n- Lower Emacs version requirement to 24.4\n- Prefer \"project\" to \"binder\" in var names and docs\n- Update tutorial\n\nFixes\n\n- Rewrite binder-read\n- Fix binder-concat-mode-map var name\n- Clear tags filter on binder-cd\n- Remove binder-sidebar-set-status command (use binder-sidebar-add-tag)\n- Call binder-cd when initializing a project\n- Only find project file within binder-project-directory\n- Fix for calling binder-next when in sidebar\n- Set pop-up-windows as buffer-local in binder-sidebar-mode\n- Fix binder-sidebar-find-file pop window with ARG\n\n* Version 0.2.0\n\n- Rewrite to use global dynamic variable binder-project-file\n- Replace status with tags\n\n    Instead of setting a single status per item, now you can set multple\n    tags. Items displayed in the sidebar can be filtered interactively with\n    binder-narrow-by-tag and binder-exclude-by-tag comamnds.\n\n- binder-get-tags now takes arg CURRENT\n\n    CURRENT will get structure accounting for binder-narrow-tags and\n    binder-exclude-tags\n\n- Improve aesthetics when tags overwrite item display name\n- Add tutorial project\n- Ensure binder-root returns directory or nil\n- Add binder-get-buffer-fileid for buffers\n- Add/rename binder-sidebar|notes-persistent-window options\n- Make binder-sidebar-select-window default nil\n- Change binder-staple-* -> binder-concat-*\n\n* Version 0.1.0\n\nFirst public release\n"
  },
  {
    "path": "README.md",
    "content": "## Binder has moved to https://codeberg.org/divyaranjan/binder/\n\nBinder\n======\n\n[![MELPA Stable](https://stable.melpa.org/packages/binder-badge.svg)][1]\n[![MELPA](https://melpa.org/packages/binder-badge.svg)][2]\n\n![screenshot](screenshots/01.png)\n\nBinder is global minor mode to facilitate working on a writing project\nin multiple files. It is heavily inspired by the binder feature in the\n[macOS writing app Scrivener][3].\n\nThe rationale behind working this way is to split a large writing\nproject into smaller pieces.\n\n\nFeatures\n--------\n\nPrimarily, Binder provides a global minor mode `binder-mode`. This\nallows working with files in the current `binder-project-directory`.\nData concerning these files is saved in a `.binder.el` file in the\nproject directory.\n\nA project can be thought of an ordered list of files with associated\nnotes and tags.\n\n\nNavigation\n----------\n\nAt the most basic level, you can navigate back and forth through the\nfiles in a project:\n\n - `binder-next (C-c ])` visits the next file in the project\n - `binder-previous (C-c [)` visits the previous\n\nCalling these commands activates a transient map so that each command\ncan be repeated without the prefix key.\n\n\nSidebar\n-------\n\nYou'll mostly interact with the project structure via the sidebar.\n\n - `binder-toggle-sidebar (C-c ')` toggles the visibility of the binder\n   sidebar\n - `binder-reveal-in-sidebar (C-c ;)` finds the current file in the\n   sidebar\n\nEach project item is a file reference relative to the project directory.\n\nProject items are displayed in a linear ordered list. Calling\n`binder-sidebar-find-file (RET)` or `binder-sidebar-find-file-other-window (o)`\nwill visit the corresponding file.\n\nEach item in the sidebar displays the following information:\n\n 1. `*` denotes that this item has some notes (see **Notes** below),\n    or...\n 2. `?` denotes that the item's corresponding file cannot be found\n 3. either the file relative to the project directory, or an arbitrary\n    display name\n 4. `#tag1 #tag2 ...` arbitrary item tags (see **Tags** below)\n\nAn item's display name can be changed with `binder-sidebar-rename (r)`.\nIf a file cannot be found, relocate with `binder-sidebar-relocate (R)`.\n\nCalling `binder-sidebar-find-file (RET)` will visit the corresponding\nfile.\n\nTo add an existing file, call `binder-sidebar-add-file (a)` or add all\nfiles in directory with `binder-sidebar-add-all-files (A)`.\n\nAdd a new file with `binder-sidebar-new-file (M-RET)`. This prompts for a\nfile-name and adds this (possibly non-existent) file to the project\nafter the current file's index. If no file-name extension is provided,\nuse `binder-default-file-extension`.\n\n > Hint: you can use an alternate default file extension for different\n > projects by setting a directory local variable.\n\nFiles can also be added to a project from outside the sidebar with\n`binder-add-file (C-c :)`.\n\nItems can be reordered with `binder-sidebar-shift-up (M-p | M-up)` and\n`binder-sidebar-shift-down (M-n | M-down)`.\n\nRemove items with `binder-sidebar-remove (d)` -- this *does not delete\nthe files*, only removes them from the project, but it *does* delete the\ncorresponding notes and tags.\n\nHide item file extensions by setting the `binder-sidebar-hide-file-extensions`\noption. This can be toggled with `binder-sidebar-toggle-file-extensions (E)`.\n\nThe sidebar can be resized with `binder-sidebar-shrink-window ({)` and\n`binder-sidebar-enlarge-window (})`. The window size is changed by the\nnumber of columns specified in option `binder-sidebar-resize-window-step`.\n\nYou can customize how the sidebar window is displayed by setting\n`binder-sidebar-display-alist` option.\n\n\nNotes\n-----\n\nTo open the notes buffer from the sidebar, call either\n`binder-sidebar-open-notes (z)` to open and select the notes window, or\n`binder-sidebar-toggle-notes (i)` to toggle the window.\n\nTo open a project file's notes from outside the sidebar, call\n`binder-toggle-notes (C-c \")`.\n\nYou need to call either `binder-notes-save (C-x C-s)` or\n`binder-notes-save-and-quit-window (C-c C-c)` to save notes to the\nproject file.\n\nCalling `quit-window (C-c C-q | C-c C-k)` or `binder-toggle-sidebar`\ndoes not save notes.\n\nYou can embiggen the notes window, to pop it out from the sidebar and\nedit like a regular buffer window, with `binder-notes-expand-window (C-c\nC-l)`.\n\nYou can customize how the notes window is displayed by setting\n`binder-notes-display-alist` option.\n\n\nTags\n----\n\nTags can help organize a project. An item can have any number of tags.\n\nAdd a tag to an item with `binder-sidebar-add-tag (t)`. Remove a tag\nfrom an item with `binder-sidebar-remove-tag (T)`. You can tag/untag\nmultiple items at once by using marks (see **Marking** below).\n\nItems in the sidebar can be narrowed to only show items with a certain\ntag with `binder-sidebar-narrow-by-tag (/)` and/or only show items\nwithout a certain tag with `binder-sidebar-exclude-by-tag (\\)`. Each of\nthese commands can be called multiple times with additional tags.\n\nClear the sidebar filters with `binder-sidebar-clear-filters (|)`.\n\n\nMarking\n-------\n\nMultiple items can be marked to add tags, toggle include state or\ndelete. Call `binder-sidebar-mark (m)` to mark an item or\n`binder-sidebar-unmark (u)` to unmark an item.\n\nTo unmark all sidebar items, call `binder-sidebar-unmark-all (U)`.\n\n\nRequirements\n------------\n\n - Emacs 24.4\n - seq 2.20 (part of Emacs 25 and later)\n\n\nInstallation\n------------\n\nThe latest stable release of Binder is available via [MELPA-stable][1].\nFirst, add MELPA-stable to your package archives:\n\n    M-x customize-option RET package-archives RET\n    \nInsert an entry named `melpa-stable` with URL:\nhttps://stable.melpa.org/packages/\n\nYou can then find the latest stable version of `binder` in the list\nreturned by:\n\n    M-x list-packages RET\n\nIf you prefer the latest but perhaps unstable version, do the above\nusing [MELPA][2].\n\n\nAdvanced Installation\n---------------------\n\nDownload the latest tagged release, move this file into your `load-path`\nand add to your `init.el` file:\n\n    (require 'binder)\n    (require 'binder-tutorial)  ;; optional\n\nIf you wish to contribute to or alter Binder's code, clone the\nrepository into your load-path and require as above:\n\n    git clone https://github.com/rnkn/binder.git\n\n\nBugs and Feature Requests\n-------------------------\n\nSend me an email (address in the package header). For bugs, please\nensure you can reproduce with:\n\n    $ emacs -Q -l binder.el\n\nKnown issues are tracked with `FIXME` comments in the source.\n\n\nTutorial\n--------\n\nBinder comes with a tutorial. Calling `M-x binder-tutorial` will prompt\nfor an empty directory in which to generate the tutorial files.\n\n\n[1]: https://stable.melpa.org/#/binder\n[2]: https://melpa.org/#/binder\n[3]: https://www.literatureandlatte.com/scrivener/\n"
  },
  {
    "path": "binder-tutorial.el",
    "content": ";;; binder-tutorial.el --- Tutorial for Binder projects  -*- lexical-binding: t; -*-\n\n;; Copyright (c) 2020-2024  Paul W. Rankin\n\n;; Author: Paul W. Rankin <rnkn@rnkn.xyz>\n;; Keywords: help, wp, convenience\n\n;; This program is free software; you can redistribute it and/or modify\n;; it under the terms of the GNU General Public License as published by\n;; the Free Software Foundation, either version 3 of the License, or\n;; (at your option) any later version.\n\n;; This program is distributed in the hope that it will be useful,\n;; but WITHOUT ANY WARRANTY; without even the implied warranty of\n;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n;; GNU General Public License for more details.\n\n;; You should have received a copy of the GNU General Public License\n;; along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\n;;; Commentary:\n\n;; This file contains code to generate a Binder project tutorial. It is\n;; loaded upon calling `binder-tutorial'.\n\n\f\n;;; Code:\n\n(require 'binder)\n\n(defconst binder-tutorial-items\n  (list\n   (cons \".binder.el\"\n         (concat binder-file-header \"\\\n((\\\"projects.txt\\\"\n  (tags \\\"start-here\\\"))\n (\\\"sidebar.txt\\\"\n  (tags \\\"foo\\\" \\\"bar\\\"))\n (\\\"navigation.txt\\\")\n (\\\"marks.txt\\\")\n (\\\"notes.txt\\\"\n  (notes . \\\"Some notes about notes.\\n\\nNullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta vulputate tellus. Nunc rutrum turpis sed pede. Sed bibendum. Aliquam posuere. Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio.\\\"))\n (\\\"tags.txt\\\"\n  (tags \\\"foo\\\"))\n (\\\"errors.txt\\\"))\"))\n   (cons \"projects.txt\" \"\\\nA project in Binder is a linear list of files in with associated\ninformation (i.e. their order, notes, and tags). This information\nis stored in a .binder.el file in the top-level directory of the\nproject.\n\nYou can only work on one project at a time in one Emacs session.\n\nWhen locating the current project file, Binder looks in the current\ndirectory then each parent directory, with the first found taking\nprecedence. Consider the following file layout:\n\n    ├── .binder.el      <-- project A\n    ├── foo.txt\n    ├── dir1\n    │   └── bar.txt\n    └── dir2\n        ├── .binder.el  <-- project B\n        └── baz.txt\n\nHere project A could reference files foo.txt, bar.txt and baz.txt.\nHowever when visiting file baz.txt, project B would take precedence.\n\nMost management of a project will happen via the sidebar. Type C-c ] to\ngo to sidebar.txt.\")\n   (cons \"sidebar.txt\" \"\\\nBy default items in the sidebar will show:\n\n    * name        #tag1 #tag2\n\nThese things mean:\n\n    *       the item has project notes\n    name    either the item file name, or a custom item display name\n    #tag    arbitrary item tag/s\n\nYou can move about in the sidebar by typing n and p, < and > and visit a\nfile by simply typing RET. Jump to the current item with j. You can\nquickly resize the sidebar with { and }.\n\nYou can rearrange items with M-n and M-p. You can toggle file extensions\nwith E.\n\nType C-c ' to toggle the sidebar on/off. When visiting a project file,\ntype C-c ; to reveal it in the sidebar.\n\nTry changing this item's display name with r. You can revert this by\ndoing the same and entering nothing.\n\nBinder will automatically write its current project file after a certain\nnumber of changes, but you can manually save a project by typing s.\n\nType C-c ] to go to the next file.\")\n   (cons \"navigation.txt\" \"\\\nYou can navigate through project items forward and backward with C-c ]\nand C-c [, which means Emacs will visit each file in the project list in\nsuccession.\n\nTry typing C-c [ to go back to a previous file. You don't need to prefix\nC-c each time, so you can type e.g. C-c [ [ ] ] ] to repeatedly navigate\nbackward/forward.\n\nThe highlight in the sidebar lets you know where you are so you don't\nget lost.\n\nType C-c ] to go to the next file.\")\n   (cons \"marks.txt\" \"\\\nYou can mark multiple project items in the sidebar by typing m. Unmark\nan item with u or unmark all items with U.\n\nMarking items allows you to perform actions on multiple items at once.\n\nType C-c ] to go to the next file.\")\n   (cons \"notes.txt\" \"\\\nEach item can have notes, which are stored in the project file. In the\nsidebar, type z to open this item's notes.\n\nAdd or change the notes and type C-c C-c (save notes and close window)\nor C-x C-s (save notes without closing window). To quit the notes window\nwithout saving the notes, type either C-c C-q or C-c C-k.\n\nYou can toggle the notes window without selecting it by typing i.\n\nTo really mix things up, open the notes window and, with it selected,\ntype C-c C-l. This pops the window out to be a regular window (instead\nof a side-window). This command works as a toggle.\n\nA file's notes can be edited without opening the sidebar with C-c \\\".\n\nType C-c ] to go to the next file.\")\n   (cons \"tags.txt\" \"\\\nEach project item can have any number of arbitrary tags, which are\nprefixed with # by default.\n\nTo add a tag to an item, type t and enter the tag. To remove a tag, type\nT and enter the tag. These commands work either with the item at point,\nor all marked items.\n\nSome tags are already added to play with. Type / then \\\"foo\\\" to narrow\nthe sidebar to only items tagged \\\"foo\\\". Now type \\\\ then \\\"bar\\\" to exclude\nsidebar items tagged \\\"bar\\\".\n\nYou should have a sidebar with only this item showing.\n\nFiltering the sidebar using tags allows a lot of flexibility with which\nproject files you want to work with in the sidebar.\n\nWhen the sidebar items are filtered, navigating backward/forward only\nconsiders those items.\n\nType | to clear the sidebar filters, then C-c ] to go to the next file.\")\n   (cons \"errors.txt\" \"\\\nBinder caches project information to avoid contious reading and writing\nto disk. However this means errors may occur if a project is moved on\ndisk while project information is cached. If you plan on moving a\nprojects on disk it's best to deactivate binder-mode first.\")))\n\n;;;###autoload\n(defun binder-tutorial (directory)\n  \"Generate the Binder tutorial project in empty DIRECTORY.\"\n  (interactive \"DGenerate tutorial project in directory: \")\n  (let ((default-directory directory))\n    (mapc (lambda (item)\n            (let ((old-buffer (get-buffer (car item))))\n              (when (buffer-live-p old-buffer) (kill-buffer old-buffer)))\n            (with-temp-buffer\n              (let ((require-final-newline t))\n                (insert (cdr item))\n                (write-file (car item)))))\n          binder-tutorial-items)\n    (binder-mode 1)\n    (binder-sidebar-create-window)\n    (select-window (get-buffer-window binder-sidebar-buffer))))\n\n\f\n\n(provide 'binder-tutorial)\n;;; binder-tutorial.el ends here\n\n;; Local Variables:\n;; coding: utf-8\n;; fill-column: 80\n;; indent-tabs-mode: nil\n;; require-final-newline: t\n;; sentence-end-double-space: nil\n;; End:\n"
  },
  {
    "path": "binder.el",
    "content": ";;; binder.el --- Global minor mode to facilitate multi-file writing projects  -*- lexical-binding: t; -*-\n\n;; Copyright (c) 2020-2024  Paul W. Rankin\n;;               2024       Divya Ranjan\n\n;; Maintainer: Divya Ranjan <divya@subvertising.org>\n;; Author: Paul W. Rankin <rnkn@rnkn.xyz>\n;; Keywords: files, outlines, wp, text\n;; Version: 0.5.0\n;; Package-Requires: ((emacs \"24.4\") (seq \"2.20\"))\n;; URL: https://codeberg.org/divyaranjan/binder/\n\n;; This file is not part of GNU Emacs.\n\n;; This program is free software; you can redistribute it and/or modify it under\n;; the terms of the GNU General Public License as published by the Free Software\n;; Foundation, either version 3 of the License, or (at your option) any later\n;; version.\n\n;; This program is distributed in the hope that it will be useful, but WITHOUT\n;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n;; details.\n\n;; You should have received a copy of the GNU General Public License along with\n;; this program. If not, see <https://www.gnu.org/licenses/>.\n\n;; In addition to conditions of the GNU General Public License, this program may\n;; not be redistributed without the following acknowledgement:\n\n;; This program takes influence from the macOS writing application Scrivener,\n;; created by Literature and Latte <https://www.literatureandlatte.com/scrivener/>.\n\n;;; Commentary:\n\n;; Binder\n;; ======\n\n;; Binder is global minor mode to facilitate working on a writing project\n;; in multiple files. It is heavily inspired by the binder feature in the\n;; [macOS writing app Scrivener][3].\n\n;; The rationale behind working this way is to split a large writing\n;; project into smaller pieces.\n\n\n;; Features\n;; --------\n\n;; Primarily, Binder provides a global minor mode binder-mode. This\n;; allows working with files in the current binder-project-directory.\n;; Data concerning these files is saved in a .binder.el file in the\n;; project directory.\n\n;; A project can be thought of an ordered list of files with associated\n;; notes and tags.\n\n\n;; Navigation\n;; ----------\n\n;; At the most basic level, you can navigate back and forth through the\n;; files in a project:\n\n;;  - binder-next (C-c ]) visits the next file in the project\n;;  - binder-previous (C-c [) visits the previous\n\n;; Calling these commands activates a transient map so that each command\n;; can be repeated without the prefix key.\n\n\n;; Sidebar\n;; -------\n\n;; You'll mostly interact with the project structure via the sidebar.\n\n;;  - binder-toggle-sidebar (C-c ') toggles the visibility of the binder\n;;    sidebar\n;;  - binder-reveal-in-sidebar (C-c ;) finds the current file in the\n;;    sidebar\n\n;; Each project item is a file reference relative to the project directory.\n\n;; Project items are displayed in a linear ordered list. Calling\n;; binder-sidebar-find-file (RET) or binder-sidebar-find-file-other-window (o)\n;; will visit the corresponding file.\n\n;; Each item in the sidebar displays the following information:\n\n;;  1. * denotes that this item has some notes (see **Notes** below),\n;;     or...\n;;  2. ? denotes that the item's corresponding file cannot be found\n;;  3. either the file relative to the project directory, or an arbitrary\n;;     display name\n;;  4. #tag1 #tag2 ... arbitrary item tags (see **Tags** below)\n\n;; An item's display name can be changed with binder-sidebar-rename (r).\n;; If a file cannot be found, relocate with binder-sidebar-relocate (R).\n\n;; Calling binder-sidebar-find-file (RET) will visit the corresponding\n;; file.\n\n;; To add an existing file, call binder-sidebar-add-file (a) or add all\n;; files in directory with binder-sidebar-add-all-files (A).\n\n;; Add a new file with binder-sidebar-new-file (M-RET). This prompts for a\n;; file-name and adds this (possibly non-existent) file to the project\n;; after the current file's index. If no file-name extension is provided,\n;; use binder-default-file-extension.\n\n;;  > Hint: you can use an alternate default file extension for different\n;;  > projects by setting a directory local variable.\n\n;; Files can also be added to a project from outside the sidebar with\n;; binder-add-file (C-c :).\n\n;; Items can be reordered with binder-sidebar-shift-up (M-p | M-up) and\n;; binder-sidebar-shift-down (M-n | M-down).\n\n;; Remove items with binder-sidebar-remove (d) -- this *does not delete\n;; the files*, only removes them from the project, but it *does* delete the\n;; corresponding notes and tags.\n\n;; Hide item file extensions by setting the binder-sidebar-hide-file-extensions\n;; option. This can be toggled with binder-sidebar-toggle-file-extensions (E).\n\n;; The sidebar can be resized with binder-sidebar-shrink-window ({) and\n;; binder-sidebar-enlarge-window (}). The window size is changed by the\n;; number of columns specified in option binder-sidebar-resize-window-step.\n\n;; You can customize how the sidebar window is displayed by setting\n;; binder-sidebar-display-alist option.\n\n\n;; Notes\n;; -----\n\n;; To open the notes buffer from the sidebar, call either\n;; binder-sidebar-open-notes (z) to open and select the notes window, or\n;; binder-sidebar-toggle-notes (i) to toggle the window.\n\n;; To open a project file's notes from outside the sidebar, call\n;; binder-toggle-notes (C-c \").\n\n;; You need to call either binder-notes-save (C-x C-s) or\n;; binder-notes-save-and-quit-window (C-c C-c) to save notes to the\n;; project file.\n\n;; Calling quit-window (C-c C-q | C-c C-k) or binder-toggle-sidebar\n;; does not save notes.\n\n;; You can embiggen the notes window, to pop it out from the sidebar and\n;; edit like a regular buffer window, with binder-notes-expand-window (C-c\n;; C-l).\n\n;; You can customize how the notes window is displayed by setting\n;; binder-notes-display-alist option.\n\n\n;; Tags\n;; ----\n\n;; Tags can help organize a project. An item can have any number of tags.\n\n;; Add a tag to an item with binder-sidebar-add-tag (t). Remove a tag\n;; from an item with binder-sidebar-remove-tag (T). You can tag/untag\n;; multiple items at once by using marks (see **Marking** below).\n\n;; Items in the sidebar can be narrowed to only show items with a certain\n;; tag with binder-sidebar-narrow-by-tag (/) and/or only show items\n;; without a certain tag with binder-sidebar-exclude-by-tag (\\). Each of\n;; these commands can be called multiple times with additional tags.\n\n;; Clear the sidebar filters with binder-sidebar-clear-filters (|).\n\n\n;; Marking\n;; -------\n\n;; Multiple items can be marked to add tags, toggle include state or\n;; delete. Call binder-sidebar-mark (m) to mark an item or\n;; binder-sidebar-unmark (u) to unmark an item.\n\n;; To unmark all sidebar items, call binder-sidebar-unmark-all (U).\n\n\n;; Requirements\n;; ------------\n\n;;  - Emacs 24.4\n;;  - seq 2.20 (part of Emacs 25 and later)\n\n\n;; Installation\n;; ------------\n\n;; The latest stable release of Binder is available via [MELPA-stable][1].\n;; First, add MELPA-stable to your package archives:\n\n;;     M-x customize-option RET package-archives RET\n\n;; Insert an entry named melpa-stable with URL:\n;; https://stable.melpa.org/packages/\n\n;; You can then find the latest stable version of binder in the list\n;; returned by:\n\n;;     M-x list-packages RET\n\n;; If you prefer the latest but perhaps unstable version, do the above\n;; using [MELPA][2].\n\n\n;; Advanced Installation\n;; ---------------------\n\n;; Download the latest tagged release, move this file into your load-path\n;; and add to your init.el file:\n\n;;     (require 'binder)\n;;     (require 'binder-tutorial)  ;; optional\n\n;; If you wish to contribute to or alter Binder's code, clone the\n;; repository into your load-path and require as above:\n\n;;     git clone https://github.com/rnkn/binder.git\n\n\n;; Bugs and Feature Requests\n;; -------------------------\n\n;; Send me an email (address in the package header). For bugs, please\n;; ensure you can reproduce with:\n\n;;     $ emacs -Q -l binder.el\n\n;; Known issues are tracked with FIXME comments in the source.\n\n\n;; Tutorial\n;; --------\n\n;; Binder comes with a tutorial. Calling M-x binder-tutorial will prompt\n;; for an empty directory in which to generate the tutorial files.\n\n\n;; [1]: https://stable.melpa.org/#/binder\n;; [2]: https://melpa.org/#/binder\n;; [3]: https://www.literatureandlatte.com/scrivener/\n\n\f\n;;; Code:\n\n(eval-when-compile (require 'cl-lib))\n(eval-when-compile (require 'subr-x))\n(require 'lisp-mnt)\n(require 'seq)\n\n(defgroup binder ()\n  \"Work with a structured project of files.\"\n  :group 'files)\n\n\f\n;;; Core Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defvar binder-format-version 3)\n(defvar binder-file-header\n  (format \"\\\n;; -*- mode: lisp-data; coding: utf-8 -*-\n;; Binder-Format-Version: %s\n;; This is a Binder project file. It is meant to be human-readable, but you\n;; probably shouldn't edit it.\\n\\n\" binder-format-version)\n  \"Header information for project file.\")\n\n(defvar binder--cache nil)\n(defvar binder--modification-time nil)\n(defvar binder--modification-count 0)\n(defvar binder--current-fileid nil)\n(defvar binder--sidebar-marked nil)\n(defvar binder--notes-fileid nil)\n(defvar binder--notes-display nil)\n(defvar binder-narrow-tags nil)\n(defvar binder-exclude-tags nil)\n(defvar binder-status-filter-in nil)\n(defvar binder-status-filter-out nil)\n\n\f\n;;; Options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defcustom binder-mode-lighter\n  \" B/\"\n  \"Mode-line indicator for `binder-mode'.\"\n  :type '(choice (const :tag \"No lighter\" \"\") string)\n  :safe 'stringp\n  :group 'binder)\n\n(defcustom binder-default-file\n  \".binder.el\"\n  \"Default file in which to store Binder project data.\"\n  :type 'string\n  :safe 'stringp\n  :group 'binder)\n\n(defcustom binder-project-directory\n  nil\n  \"Directory containing current `binder-default-file' or nil.\n\nThe value set here will be used as default, but may be changed at\nany time with `binder-change-directory'.\"\n  :type '(choice (const nil) directory)\n  :safe 'stringp\n  :group 'binder)\n\n(defcustom binder-default-file-extension\n  \"txt\"\n  \"Default extension for new binder files.\"\n  :type 'string\n  :safe 'stringp\n  :group 'binder)\n\n(defcustom binder-save-threshold\n  20\n  \"Integer of changes before binder file is automatically saved.\"\n  :type 'integer\n  :safe 'integerp\n  :group 'binder)\n\n\f\n;;; Faces ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defgroup binder-sidebar-faces ()\n  \"Default faces for `binder-sidebar-mode'.\"\n  :group 'binder-sidebar)\n\n(defface binder-sidebar-marked\n  '((t (:inherit (warning))))\n  \"Default face marked items.\"\n  :group 'binder-sidebar-faces)\n\n(defface binder-sidebar-highlight\n  '((t (:extend t :inherit (secondary-selection))))\n  \"Default face for highlighted items.\"\n  :group 'binder-sidebar-faces)\n\n(defface binder-sidebar-missing\n  '((t (:inherit (trailing-whitespace))))\n  \"Default face for missing items.\"\n  :group 'binder-sidebar-faces)\n\n(defface binder-sidebar-tags\n  '((t (:inherit (font-lock-variable-name-face))))\n  \"Default face for tags.\"\n  :group 'binder-sidebar-faces)\n\n\f\n;;; Core Non-interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defun binder-root ()\n  \"Return the root directory with a project file, or nil.\"\n  (locate-dominating-file default-directory binder-default-file))\n\n(defun binder-set-modified ()\n  \"Set the project data as modified.\"\n  (cl-incf binder--modification-count)\n  (setq binder--modification-time (current-time)))\n\n(defun binder-set-unmodified ()\n  \"Set the project data as unmodified.\"\n  (setq binder--modification-count 0\n        binder--modification-time (current-time)))\n\n(defun binder-cd (directory)\n  \"Set `binder-project-directory' to DIRECTORY and erase cache.\"\n  (customize-set-variable 'binder-project-directory directory)\n  (setq binder-narrow-tags nil\n        binder-exclude-tags nil\n        binder--notes-fileid nil\n        binder--cache nil)\n  (binder-set-unmodified))\n\n(defun binder-init ()\n  \"Initialize an empty project file in `binder-project-directory'.\"\n  (with-temp-buffer\n    (insert binder-file-header\n            (pp-to-string nil))\n    (write-file (expand-file-name binder-default-file binder-project-directory))))\n\n(defun binder-locate-project-file ()\n  \"Find or initialize current project file.\"\n  (let ((binder-file\n         (expand-file-name binder-default-file binder-project-directory)))\n    (unless (file-exists-p binder-file) (binder-init))\n    binder-file))\n\n(defun binder-write ()\n  \"Write project data to file.\"\n  (let ((binder-file (binder-locate-project-file)))\n    (with-temp-buffer\n      (insert binder-file-header\n              (pp-to-string binder--cache))\n      (write-file binder-file)))\n  (binder-set-unmodified))\n\n(defun binder-write-maybe ()\n  \"Call `binder-write' if modified threshold has been reached.\nOtherwise call `binder-set-modified'.\"\n  (if (<= binder-save-threshold binder--modification-count)\n      (binder-write)\n    (binder-set-modified)))\n\n(defun binder-filter (data)\n  \"Filter project DATA by tags.\nIncluded `binder-narrow-tags' and excluded `binder-exclude-tags'.\"\n  (seq-filter\n   (lambda (item)\n     (and (seq-every-p\n           (lambda (tag)\n             (member tag (cdr (assq 'tags item))))\n           binder-narrow-tags)\n          (seq-every-p\n           (lambda (tag)\n             (not (member tag (cdr (assq 'tags item)))))\n           binder-exclude-tags)))\n   data))\n\n(defun binder-upgrade (data version)\n  \"Upgrade project DATA in VERSION to `binder-format-version'.\"\n  (cond ((not (stringp version))\n         (binder-upgrade (cdr (assq 'structure data)) \"2\"))\n        ((= (string-to-number version) 2)\n         (mapcar\n          (lambda (item)\n            (when (cdr (assq 'include item))\n              (let ((tags (assq 'tags item)))\n                (if tags\n                    (cl-pushnew \"include\" (cdr tags))\n                  (push (list 'tags \"include\") (cdr item)))))\n            (assq-delete-all 'include item))\n          data))\n        (t data)))\n\n(defun binder-read (&optional filter)\n  \"Read current project data.\nReads from `binder--cache' if valid, or from project file if not.\nWith optional argument FILTER, call `binder-filter' on data.\"\n  (let ((binder-file (binder-locate-project-file))\n        version)\n    (when binder--cache\n      (cond\n       ;; If there's no project file found, signal an error.\n       ((null binder-file)\n        (user-error \"No binder file found\"))\n       ;; If the cache doesn't refer to the project directory, set the cache to\n       ;; nil.\n       ((and (binder-root)\n             (not (file-equal-p binder-project-directory (binder-root))))\n        (setq binder--cache nil))\n       ;; If the project file is newer than the cache, offer to revert from disk\n       ;; (and write binder data), regardless, set the cache to nil.\n       ((time-less-p binder--modification-time\n                     (elt (file-attributes binder-file) 5))\n        (unless (y-or-n-p \"Project file changed on disk; revert from disk? \")\n          (binder-write))\n        (setq binder--cache nil))))\n    ;; If the cache survived all that, it's valid, otherwise, read from the\n    ;; project file.\n    (unless binder--cache\n      (with-temp-buffer\n        (insert-file-contents binder-file)\n        ;; Read Binder-Format-Version header\n        (setq version (lm-header \"binder-format-version\"))\n        (goto-char (point-min))\n        (setq binder--cache\n              (binder-upgrade (read (current-buffer)) version)))\n      (binder-set-unmodified)))\n  ;; Finally, return the cache.\n  (if filter (binder-filter binder--cache) binder--cache))\n\n(defun binder-ensure-in-project ()\n  \"Ensure the current file or directory is in the project.\"\n  (let ((root (binder-root)))\n    (cond\n     ;; The project directory matches root, we're all good.\n     ((and (stringp binder-project-directory)\n           (stringp root)\n           (file-equal-p binder-project-directory root))\n      t)\n     ;; The project directory does not match project root; offer to change it to\n     ;; current project root.\n     ((and (stringp binder-project-directory)\n           (stringp root))\n      (when (y-or-n-p (format \"Change project directory to %s? \"\n                              root))\n        (binder-cd root)))\n     ;; The project directory is set but we're not in a project; this is fine.\n     ((stringp binder-project-directory)\n      t)\n     ;; The project directory is not set, but we're in a project; offer to set\n     ;; it to current project root.\n     ((stringp root)\n      (binder-cd root)\n      (message \"Set binder directory to %s\" root))\n     ;; A fresh project; offer to set project directory to default-directory.\n     (t\n      (when (y-or-n-p (format \"Set binder directory to %s? \"\n                              (abbreviate-file-name default-directory)))\n        (binder-cd default-directory)\n        (binder-init))))))\n\n(defun binder-file-relative-to-root (filepath)\n  \"Return FILEPATH relative to `binder-project-directory'.\"\n  (file-relative-name (or filepath default-directory)\n                      binder-project-directory))\n\n(defun binder-get-item (fileid)\n  \"Return project item association list for FILEID.\"\n  (assoc-string fileid (binder-read t)))\n\n(defun binder-get-item-prop (fileid prop)\n  \"Return value of PROP for project item with FILEID.\"\n  (cdr (assq prop (cdr (binder-get-item fileid)))))\n\n(defun binder-set-item-prop (fileid prop value)\n  \"Set VALUE of PROP for project item with FILEID.\"\n  (let ((item (binder-get-item fileid)))\n    (if (or (null value) (and (stringp value) (string-empty-p value)))\n        (setf item (assq-delete-all prop item))\n      (let ((prop-elt (assq prop item)))\n        (if prop-elt\n            (setcdr prop-elt value)\n          (push (cons prop value) (cdr item)))))))\n\n(defun binder-add-to-item-prop (fileid prop value)\n  \"Add VALUE to PROP for project item with FILEID.\"\n  (let ((prop-elt (binder-get-item-prop fileid prop)))\n    (unless (member value prop-elt)\n      (binder-set-item-prop fileid prop (push value prop-elt)))))\n\n(defun binder-remove-from-item-prop (fileid prop value)\n  \"Remove VALUE from PROP for project item with FILEID.\"\n  (let ((prop-elt (binder-get-item-prop fileid prop)))\n    (when (member value (binder-get-item-prop fileid 'tags))\n      (binder-set-item-prop fileid prop (remove value prop-elt)))))\n\n(defun binder-get-item-index (fileid &optional filter)\n  \"Return index position for project item for FILEID.\nWith option argument FILTER, return index when items are\nfiltered.\"\n  (seq-position (binder-read filter) (binder-get-item fileid)))\n\n(defun binder-insert-item (item index)\n  \"Insert project ITEM at position INDEX.\"\n  (unless (listp item) (setq item (list item)))\n  (setq binder--cache\n       (let ((structure (binder-read)))\n         (append (seq-take structure index)\n                 (cons item (seq-drop structure index))))))\n\n(defun binder-delete-item (fileid)\n  \"Delete project item with FILEID.\"\n  (setq binder--cache\n        (remove (binder-get-item fileid) (binder-read))))\n\n(defun binder-get-prop-list (prop)\n  \"Return list of values for PROP.\"\n  (delq nil\n        (mapcar\n         (lambda (item)\n           (let ((value (cdr (assq prop item))))\n             (when (and (stringp value) (< 0 (string-width value)))\n               value)))\n         (binder-read))))\n\n(defun binder-get-tags (&optional filter)\n  \"Return current project tags.\nOptionally pass FILTER to `binder-read'.\"\n(let (tags)\n    (mapc\n     (lambda (item)\n       (mapc\n        (lambda (tag)\n          (push tag tags))\n        (cdr (assq 'tags item))))\n     (binder-read filter))\n    (seq-uniq tags 'string-equal)))\n\n(defun binder-get-buffer-fileid ()\n  \"Return buffer binder fileid.\"\n  (cl-case major-mode\n    (binder-sidebar-mode binder--current-fileid)\n    (binder-notes-mode binder--notes-fileid)\n    (t (binder-file-relative-to-root (buffer-file-name)))))\n\n\f\n;;; Global Minor Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defun binder-init-project (directory)\n  \"Initialize empty project in DIRECTORY.\"\n  (interactive \"DInitialize empty project in directory: \")\n  (binder-cd directory)\n  (binder-init))\n\n(defun binder-save (&optional prompt)\n  \"Save project data (with prompt when PROMPT is non-nil).\"\n  (interactive)\n  (cond ((= 0 binder--modification-count)\n         (message \"(No changes need to be saved)\"))\n        ((and prompt\n              (y-or-n-p (format \"Save binder project %s? \"\n                                (abbreviate-file-name binder-project-directory))))\n         (binder-write))\n        (t\n         (binder-write))))\n\n(defun binder-exit-hook ()\n  \"Ensure project data is saved on exit.\"\n  (when binder-mode (binder-save 'prompt)))\n\n(defun binder-change-directory (directory)\n  \"Change to binder project directory DIRECTORY.\"\n  (interactive \"DDirectory: \")\n  (binder-save 'prompt)\n  (binder-cd directory)\n  (binder-sidebar-refresh-window)\n  (binder-notes-refresh-window))\n\n(defun binder-next (&optional n)\n  \"Visit Nth next file in binder.\nOr visit Nth previous file if N is negative.\"\n  (interactive \"p\")\n  (when (binder-ensure-in-project)\n    ;; Find the current file/directory fileid, if one.\n    (let ((this-fileid (binder-get-buffer-fileid))\n          (structure (binder-read t))\n          index next-index)\n      ;; If current file has an INDEX, get the NEXT-INDEX.\n      (setq index (or (binder-get-item-index this-fileid t) 0)\n            next-index (+ index n))\n      ;; If NEXT-INDEX is within the filtered structure length, find the\n      ;; Nth next/previous file.\n      (if (not (<= 0 next-index (1- (length structure))))\n          (message \"End of binder\")\n        (find-file-existing\n         (expand-file-name (car (elt structure next-index))\n                           binder-project-directory))\n        (binder-sidebar-refresh-window))\n      ;; Setup the overriding keymap.\n      (unless overriding-terminal-local-map\n        (let ((prefix-keys (substring (this-single-command-keys) 0 -1))\n              (map (cdr binder-navigation-map)))\n          (when (< 0 (length prefix-keys))\n            (mapc (lambda (k) (setq map (assq k map))) prefix-keys)\n            (setq map (cdr-safe map))\n            (when (keymapp map) (set-transient-map map t))))))))\n\n(defun binder-previous (&optional n)\n  \"Visit Nth previous file in binder.\nOr visit Nth next file if N is negative.\"\n  (interactive \"p\")\n  (binder-next (- n)))\n\n(defun binder-add-file (fileid &optional index string)\n  \"Add a (possibly non-existent) FILEID at INDEX containing STRING.\nIf the current file is in the project, add at index after that\none, otherwise insert at end.\"\n  (interactive \"FAdd file (extension optional): \")\n  (binder-ensure-in-project)\n  (setq fileid (binder-file-relative-to-root fileid))\n  (unless (< 0 (string-width fileid))\n    (user-error \"No file name supplied\"))\n  ;; If FILEID is not a directory and no file extension was provided,\n  ;; add the binder's default file extensions.\n  (unless (or (file-directory-p fileid)\n              (and (string-match \"\\\\.[^.]+\\\\'\" fileid)\n                   (not (= 0 (match-beginning 0)))))\n    (setq fileid\n          (concat fileid \".\" binder-default-file-extension)))\n  ;; If the file/directory does not exist, create it.\n  (let ((filepath (expand-file-name fileid binder-project-directory)))\n    (unless (file-exists-p filepath)\n      (if (file-directory-p filepath)\n          (make-directory filepath t)\n        (with-current-buffer (find-file-noselect filepath)\n          (when (stringp string) (insert string))\n          (write-file filepath))))\n    ;; Insert FILEID into binder at INDEX, or after current file.\n    (unless (binder-get-item fileid)\n      (unless index\n        (let ((this-file-index\n               (binder-get-item-index (binder-get-buffer-fileid) t)))\n          (setq index (if this-file-index\n                          (1+ this-file-index)\n                        (length (binder-read))))))\n      (binder-insert-item fileid index))\n    (binder-write-maybe)\n    ;; When binder sidebar is active, refresh it.\n    (binder-sidebar-refresh-window)\n    ;; Finally, visit the file FILEPATH.\n    (let ((pop-up-windows binder-sidebar-pop-up-windows))\n      (find-file filepath))))\n\n(defun binder-extract-region-to-new-file (beg end fileid)\n  \"Extract region between BEG and END into new project file FILEID.\"\n  (interactive \"r\\nFNew file name (extension optional): \")\n  (binder-ensure-in-project)\n  (let ((string (delete-and-extract-region beg end)))\n    (binder-add-file fileid nil string)))\n\n(defvar binder-navigation-map\n  (let ((map (make-sparse-keymap)))\n    (define-key map (kbd \"C-c ]\") #'binder-next)\n    (define-key map (kbd \"C-c [\") #'binder-previous)\n    map)\n  \"Navigational mode map for `binder-mode'.\")\n\n(defvar binder-mode-map\n  (let ((map (make-sparse-keymap)))\n    (define-key map (kbd \"C-c ;\") #'binder-reveal-in-sidebar)\n    (define-key map (kbd \"C-c '\") #'binder-toggle-sidebar)\n    (define-key map (kbd \"C-c \\\"\") #'binder-toggle-notes)\n    (define-key map (kbd \"C-c :\") #'binder-add-file)\n    map)\n  \"Main mode map for `binder-mode'.\")\n\n(set-keymap-parent binder-mode-map binder-navigation-map)\n\n;;;###autoload\n(define-minor-mode binder-mode\n  \"Globally interact with `binder'.\"\n  :init-value nil\n  :lighter binder-mode-lighter\n  :global t\n  (if binder-mode\n      (unless noninteractive\n        (add-hook 'kill-emacs-hook #'binder-exit-hook)\n        (add-hook 'window-configuration-change-hook #'binder-highlight-in-sidebar))\n    (binder-save 'prompt)\n    (remove-hook 'window-configuration-change-hook #'binder-highlight-in-sidebar)\n    (when (window-live-p (get-buffer-window binder-sidebar-buffer t))\n      (with-selected-window (get-buffer-window binder-sidebar-buffer t)\n        (quit-window t)))\n    (when (window-live-p (get-buffer-window binder-notes-buffer t))\n      (with-selected-window (get-buffer-window binder-notes-buffer t)\n        (quit-window t)))\n    (setq binder--cache nil)))\n\n\f\n;;; Sidebar Major Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defgroup binder-sidebar ()\n  \"Options for `binder-sidebar-mode'.\"\n  :group 'binder)\n\n(defface binder-sidebar\n  '((t nil))\n  \"Default base-level face for `binder-sidebar-mode' buffers.\")\n\n(defcustom binder-sidebar-buffer \"*Binder Sidebar*\"\n  \"Default buffer name for binder sidebar.\"\n  :type 'string\n  :safe 'stringp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-display-alist\n  '((side . left)\n    (window-width . 40)\n    (slot . -1))\n  \"Association list used to display binder sidebar buffer.\n\nSee `display-buffer-in-side-window' for example options.\"\n  :type 'alist\n  :safe (lambda (value)\n          (and (listp value)\n               (seq-every-p 'consp value)))\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-hide-file-extensions\n  nil\n  \"When non-nil, list items without file extension.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-hide-tags\n  nil\n  \"When non-nil, list items without tags.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-pop-up-windows\n  nil\n  \"Non-nil means displaying a new buffer should make a new window.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-tags-column\n  25\n  \"Integer for column to align tags.\"\n  :type 'integer\n  :safe 'integerp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-include-char\n  ?x\n  \"Character to display on items including in joining.\"\n  :type 'character\n  :safe 'characterp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-notes-char\n  ?*\n  \"Character to display on items with notes.\"\n  :type 'character\n  :safe 'characterp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-tags-char\n  ?#\n  \"Character to prefix to item tags.\"\n  :type 'character\n  :safe 'characterp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-missing-char\n  ??\n  \"Character to display on items with missing files.\"\n  :type 'character\n  :safe 'characterp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-select-window\n  nil\n  \"If non-nil, switch to sidebar upon displaying it.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-persistent-window\n  t\n  \"When non-nil, sidebar will persist when calling `delete-other-windows'.\n\nThis marks `no-delete-other-windows' window parameter as non-nil.\n\nUse `binder-toggle-sidebar' or `quit-window' to close the sidebar.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-sidebar-resize-window-step\n  4\n  \"Integer of columns by which to resize window.\nUsed by `binder-sidebar-shrink-window' and `binder-sidebar-enlarge-window'.\"\n  :type 'integer\n  :safe 'integerp\n  :group 'binder-sidebar)\n\n(defun binder-sidebar-refresh ()\n  \"Redraw binder sidebar, reading from cache.\"\n  (interactive)\n  (with-silent-modifications\n    (setq default-directory binder-project-directory)\n    (setq header-line-format (abbreviate-file-name binder-project-directory))\n    (let ((x (point)))\n      (erase-buffer)\n      (mapc\n       (lambda (item)\n         (let ((fileid   (car item))\n               (display  (cdr (assq 'display item)))\n               (notes    (cdr (assq 'notes item)))\n               (tags     (cdr (assq 'tags item)))\n               marked missing tags-overwrite)\n           ;; Set whether FILEID is MARKED and MISSING.\n           (when (member fileid binder--sidebar-marked) (setq marked t))\n           (when (not (file-exists-p fileid))           (setq missing t))\n          ;; Insert the item line elements.\n          (insert (if marked \">\" \" \")\n                  (cond (missing binder-sidebar-missing-char)\n                        ((and notes (not (string-empty-p notes)))\n                         binder-sidebar-notes-char)\n                        (t \" \"))\n                  \" \")\n          ;; Use either DISPLAY, or if directory ensure a trailing slash, and\n          ;; finally if we're hiding file extensions, do that, otherwise just\n          ;; the FILEID is fine.\n          (insert-text-button\n           (or display (if (file-directory-p fileid)\n                           (replace-regexp-in-string \"/*$\" \"/\" fileid)\n                         (if binder-sidebar-hide-file-extensions\n                             (replace-regexp-in-string \".+\\\\(\\\\..+\\\\)\" \"\"\n                                                       fileid nil nil 1)\n                           fileid)))\n           'binder-fileid fileid\n           'face 'button\n           'action #'binder-sidebar-button-action\n           'help-echo \"mouse-1, RET: visit this file\"\n           'follow-link t)\n          ;; Add the face properties. Make them front-sticky since we\n          ;; were previously editing the buffer text (but not anymore).\n          (put-text-property (line-beginning-position) (line-end-position)\n                             'binder-fileid fileid)\n          (put-text-property (line-beginning-position) (line-end-position)\n                             'front-sticky '(binder-fileid))\n          (when missing\n            (add-face-text-property (line-beginning-position) (line-end-position)\n                                    'binder-sidebar-missing))\n          (when marked\n            (add-face-text-property (line-beginning-position) (line-end-position)\n                                    'binder-sidebar-marked))\n          ;; Add the item TAGS with a hashtag, because hashtags are cool, right?\n          (when (and (not binder-sidebar-hide-tags) tags)\n            (move-to-column (1- binder-sidebar-tags-column))\n            (unless (eolp) (setq tags-overwrite t))\n            (move-to-column binder-sidebar-tags-column)\n            (indent-to-column binder-sidebar-tags-column)\n            (let ((tags-col  (point))\n                  (tags-char (char-to-string binder-sidebar-tags-char)))\n              (delete-region (1- tags-col) (line-end-position))\n              (insert (if tags-overwrite \"~\" \" \")\n                      tags-char\n                      (string-join tags (concat \" \" tags-char)))\n              (add-face-text-property tags-col (line-end-position)\n                                      'binder-sidebar-tags)))\n          (insert \"\\n\")\n          (when (string= fileid binder--current-fileid)\n            (add-face-text-property (line-beginning-position 0)\n                                    (line-beginning-position)\n                                    'binder-sidebar-highlight))))\n       (binder-read t))\n      (goto-char x))))\n\n(defun binder-sidebar-button-ensure ()\n  \"Ensure point is at button.\"\n  (or (button-at (point))\n      (and (eolp) (forward-button -1 nil nil t))\n      (forward-button 1 nil nil t)))\n\n(defun binder-sidebar-button-action (button &optional pop-up-window)\n  (interactive)\n  (let ((pop-up-windows (or pop-up-window binder-sidebar-pop-up-windows))\n        (fileid (button-get button 'binder-fileid))\n        filepath)\n    (setq filepath (expand-file-name fileid))\n    (when (file-exists-p filepath)\n      (setq binder--current-fileid fileid)\n      (binder-sidebar-refresh)\n      (find-file filepath))))\n\n(defun binder-sidebar-refresh-window ()\n  \"Call `binder-sidebar-refresh' if sidebar window is live.\"\n  (when (window-live-p (get-buffer-window binder-sidebar-buffer))\n    (with-current-buffer binder-sidebar-buffer\n      (binder-sidebar-refresh))))\n\n(defalias 'binder-sidebar-change-directory #'binder-change-directory)\n\n(defun binder-sidebar-create-buffer ()\n  \"Return binder sidebar buffer for DIRECTORY.\"\n  (binder-ensure-in-project)\n  (with-current-buffer (get-buffer-create binder-sidebar-buffer)\n    (binder-sidebar-mode)\n    (binder-sidebar-refresh)\n    (current-buffer)))\n\n(defun binder-sidebar-create-window ()\n  \"Return binder sidebar window for DIRECTORY.\nDefaults to current directory.\"\n  (let ((display-buffer-mark-dedicated t))\n    (display-buffer-in-side-window\n     (binder-sidebar-create-buffer)\n     (append binder-sidebar-display-alist\n             (when binder-sidebar-persistent-window\n               (list '(window-parameters (no-delete-other-windows . t))))))))\n\n(defun binder-sidebar-get-fileid ()\n  \"Return fileid for item at point.\"\n  (save-excursion\n    (if (eobp) (forward-line -1) (beginning-of-line))\n    (get-text-property (point) 'binder-fileid)))\n\n(defun binder-sidebar-goto-item (fileid)\n  \"Move point to project item with FILEID.\"\n  (goto-char (point-min))\n  ;; It would be nice to use find-next-text-property but that isn't\n  ;; available until Emacs 27.\n  (let (found)\n    (while (not (or (eobp) found))\n      (if (string= (binder-sidebar-get-fileid) fileid)\n          (setq found t)\n        (forward-line 1)))))\n\n(defun binder-sidebar-find-file (arg)\n  \"Visit project file at point.\nWhen ARG is non-nil, visit in new window.\"\n  (interactive \"P\")\n  (when (binder-sidebar-button-ensure)\n    (binder-sidebar-button-action (button-at (point)) arg)))\n\n(defun binder-sidebar-find-file-other-window ()\n  \"Visit project file at point in other window.\"\n  (interactive)\n  (binder-sidebar-find-file t))\n\n;; FIXME: FEATURE - `binder-sidebar-search' to search for strings within\n;; project. Could be implemented simply as a dynamic command passed to `lgrep'.\n\n(defalias 'binder-sidebar-save #'binder-save)\n\n(defun binder-sidebar-get-index ()\n  \"Return binder index position at point.\"\n  (if (eobp)\n      (1- (length (binder-read)))\n    (binder-get-item-index (binder-sidebar-get-fileid) t)))\n\n(defun binder-sidebar-mark ()\n  \"Mark the project item at point.\"\n  (interactive)\n  (cl-pushnew (binder-sidebar-get-fileid) binder--sidebar-marked)\n  (forward-line 1)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-unmark ()\n  \"Unmark the project item at point.\"\n  (interactive)\n  (setq binder--sidebar-marked\n        (remove (binder-sidebar-get-fileid) binder--sidebar-marked))\n  (forward-line 1)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-unmark-all ()\n  \"Unmark all project items.\"\n  (interactive)\n  (setq binder--sidebar-marked nil)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-add-file (fileid)\n  \"Add (possibly non-existent) file to binder as FILEID.\"\n  (interactive \"FAdd file: \")\n  (setq fileid (binder-file-relative-to-root fileid))\n  (unless (binder-get-item fileid)\n    (binder-insert-item fileid (1+ (binder-sidebar-get-index))))\n  (binder-write-maybe)\n  (binder-sidebar-refresh)\n  (binder-sidebar-goto-item fileid))\n\n(defun binder-sidebar-add-all-files ()\n  \"Add all files in current directory to binder.\"\n  (interactive)\n  (when (y-or-n-p (format \"Add all files in %s? \"\n                          (abbreviate-file-name default-directory)))\n    (dolist (file (directory-files default-directory nil \"^[^.]\"))\n      (binder-sidebar-add-file file))))\n\n(defun binder-sidebar-new-file (fileid)\n  \"Add a new file to binder as FILEID and visit it.\"\n  (interactive \"FAdd file (extension optional): \")\n  (unless (eq major-mode 'binder-sidebar-mode)\n    (user-error \"Not in %S\" 'binder-sidebar-mode))\n  (binder-add-file fileid (1+ (binder-sidebar-get-index)))\n  (binder-sidebar-goto-item fileid))\n\n(defun binder-sidebar-remove (arg)\n  \"Remove marked items or item at point.\nWhen ARG is non-nil, do not prompt for confirmation.\"\n  (interactive \"P\")\n  (let ((fileid-list (or binder--sidebar-marked\n                      (list (binder-sidebar-get-fileid)))))\n    (when (or arg (y-or-n-p (format \"Really remove %s? \"\n                                    (string-join fileid-list \", \"))))\n      (mapc #'binder-delete-item fileid-list)\n      (setq binder--sidebar-marked nil)))\n  (binder-write)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-rename ()\n  \"Change display name of project item at point.\"\n  (interactive)\n  (let ((fileid (binder-sidebar-get-fileid))\n        name)\n    (setq name\n          (read-string \"New name: \"\n                       (or (binder-get-item-prop fileid 'display) fileid)))\n    (binder-set-item-prop fileid 'display name)\n    (binder-write-maybe)\n    (binder-sidebar-refresh)))\n\n(defun binder-sidebar-relocate (filepath)\n  \"Change file path of project item at point to FILEPATH.\"\n  (interactive\n   (list (read-file-name\n          (format \"New file path [%s]: \" (binder-sidebar-get-fileid))\n          nil nil t)))\n  (setq filepath (binder-file-relative-to-root filepath))\n  (setcar (binder-get-item (binder-sidebar-get-fileid)) filepath)\n  (binder-write-maybe)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-add-tag (tag)\n  \"Add TAG to marked items or item at point.\"\n  (interactive\n   (list (completing-read\n          \"Add tag: \" (binder-get-tags))))\n  (mapc\n   (lambda (fileid)\n     (binder-add-to-item-prop fileid 'tags tag))\n   (or binder--sidebar-marked\n       (list (binder-sidebar-get-fileid))))\n  (setq binder--sidebar-marked nil)\n  (binder-write-maybe)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-remove-tag (tag)\n  \"Remove TAG to marked items or item at point.\"\n  (interactive\n   (list (completing-read\n          \"Remove tag: \"\n          (binder-get-item-prop (binder-sidebar-get-fileid) 'tags))))\n  (mapc\n   (lambda (fileid)\n     (binder-remove-from-item-prop fileid 'tags tag))\n   (or binder--sidebar-marked\n       (list (binder-sidebar-get-fileid))))\n  (setq binder--sidebar-marked nil)\n  (binder-write-maybe)\n  (binder-sidebar-refresh))\n\n(defun binder-sidebar-toggle-file-extensions ()\n  \"Toggle visibility of item file extensions.\"\n  (interactive)\n  (customize-set-variable 'binder-sidebar-hide-file-extensions\n                          (not binder-sidebar-hide-file-extensions))\n  (let ((fileid (binder-sidebar-get-fileid)))\n    (binder-sidebar-refresh)\n    (binder-sidebar-goto-item fileid))\n  (message \"%s file extensions\"\n           (capitalize\n            (if binder-sidebar-hide-file-extensions\n                \"hiding\" \"showing\"))))\n\n(defun binder-sidebar-toggle-tags ()\n  \"Toggle visibility of tags.\"\n  (interactive)\n  (customize-set-variable 'binder-sidebar-hide-tags\n                          (not binder-sidebar-hide-tags))\n  (let ((fileid (binder-sidebar-get-fileid)))\n    (binder-sidebar-refresh)\n    (binder-sidebar-goto-item fileid))\n  (message \"%s tags\"\n           (capitalize\n            (if binder-sidebar-hide-tags\n                \"hiding\" \"showing\"))))\n\n(defun binder-sidebar-shift-down (&optional n)\n  \"Shift index position of item at point down N places in list.\"\n  (interactive \"p\")\n  (let ((p (if (<= n 0) -1 1))\n        (fileid (binder-sidebar-get-fileid))\n        item fake-index next-index)\n    (setq item (binder-get-item fileid)\n          fake-index (binder-get-item-index fileid t)\n          next-index (seq-position (binder-read)\n                                   (elt (binder-read t) (+ fake-index p))))\n    (when (<= 0 (+ fake-index p)\n              (1- (length (binder-read t))))\n      (binder-delete-item fileid)\n      (binder-insert-item item next-index)\n      (binder-write-maybe)\n      (binder-sidebar-refresh)\n      (binder-sidebar-goto-item fileid))))\n\n(defun binder-sidebar-shift-up (&optional n)\n  \"Shift index position of item at point up N places in list.\"\n  (interactive \"p\")\n  (binder-sidebar-shift-down (- n)))\n\n(defun binder-sidebar-jump-to-current ()\n  \"Jump to current file in sidebar.\"\n  (interactive)\n  (binder-sidebar-goto-item binder--current-fileid))\n\n(defun binder-sidebar-narrow-by-tag (tag)\n  \"\\\\<binder-sidebar-mode-map>Filter sidebar items to include items with TAG.\nTo reset filtering call `binder-sidebar-refresh' (\\\\[binder-sidebar-refresh]).\"\n  (interactive\n   (list (completing-read\n          \"Narrow items by tag: \" (binder-get-tags)\n          nil t)))\n  (unless (or (string-empty-p tag) (member tag binder-narrow-tags))\n    (push tag binder-narrow-tags)\n    (binder-sidebar-refresh)))\n\n(defun binder-sidebar-exclude-by-tag (tag)\n  \"\\\\<binder-sidebar-mode-map>Filter sidebar items to exclude items with TAG.\nTo reset filtering call `binder-sidebar-refresh' (\\\\[binder-sidebar-refresh]).\"\n  (interactive\n   (list (completing-read\n          \"Exclude items by tag: \" (binder-get-tags)\n          nil t)))\n  (unless (or (string-empty-p tag) (member tag binder-exclude-tags))\n    (push tag binder-exclude-tags)\n    (binder-sidebar-refresh)))\n\n(defun binder-sidebar-clear-filters ()\n  \"Clear all sidebar tag filters.\"\n  (interactive)\n  (setq binder-narrow-tags nil\n        binder-exclude-tags nil)\n  (binder-sidebar-refresh)\n  (message \"Sidebar filters cleared\"))\n\n(defun binder-sidebar-copy-filepath ()\n  \"Put the current item filepath into the kill ring.\"\n  (interactive)\n  (let ((fileid (binder-sidebar-get-fileid)))\n    (kill-new fileid)\n    (message \"%S\" fileid)))\n\n(defun binder-highlight-in-sidebar ()\n  \"Highlight the current file in sidebar.\n\nAdded to `window-configuration-change-hook'.\"\n  (unless (or (minibuffer-window-active-p (selected-window))\n              (eq major-mode 'binder-sidebar-mode))\n    (setq binder--current-fileid (binder-get-buffer-fileid))\n    (binder-sidebar-refresh-window)))\n\n(defun binder-sidebar-shrink-window ()\n  \"Shrink the sidebar window horizontally.\n\nCalls `shrink-window-horizontally' with `binder-sidebar-resize-window-step'.\"\n  (interactive)\n  (shrink-window-horizontally binder-sidebar-resize-window-step))\n\n(defun binder-sidebar-enlarge-window ()\n  \"Enlarge the sidebar window horizontally.\n\nCalls `enlarge-window-horizontally' with `binder-sidebar-resize-window-step'.\"\n  (interactive)\n  (enlarge-window-horizontally binder-sidebar-resize-window-step))\n\n(defun binder-sidebar-help (char)\n  \"Provide interactive help prompt by CHAR.\"\n  (declare (interactive-only t))\n  (interactive\n   (list (read-char-choice \"\\\n? = describe-mode, \\\ng = refresh, \\\n| = clear filters, \\\nq = quit-window, \\\nC-g = cancel: \" '(?? ?g ?| ?q))))\n  (cl-case char\n    (?q (quit-window))\n    (?g (binder-sidebar-refresh))\n    (?| (binder-sidebar-clear-filters))\n    (?? (describe-mode))))\n\n(defun binder-reveal-in-sidebar ()\n  \"Reveal current file in binder sidebar.\"\n  (interactive)\n  (let ((filepath (or (buffer-file-name) default-directory)))\n    (select-window (binder-sidebar-create-window))\n    (if (file-equal-p filepath (binder-root))\n        (binder-sidebar-refresh)\n      (let ((fileid (binder-file-relative-to-root filepath)))\n        (setq binder--current-fileid fileid)\n        (unless (binder-get-item fileid)\n          (when (y-or-n-p (format \"Add %s to binder? \" fileid))\n            (binder-sidebar-add-file fileid)))\n        (binder-sidebar-refresh)\n        (binder-sidebar-goto-item fileid)))))\n\n;;;###autoload\n(defun binder-toggle-sidebar ()\n  \"Toggle visibility of project sidebar window.\n\nUnconditionally activates `binder-mode'.\"\n  (interactive)\n  (binder-mode)\n  (if (window-live-p (get-buffer-window binder-sidebar-buffer))\n      (delete-window (get-buffer-window binder-sidebar-buffer))\n    (binder-sidebar-create-window)\n    (when binder-sidebar-select-window\n      (select-window (get-buffer-window binder-sidebar-buffer)))))\n\n(defvar binder-sidebar-mode-map\n  (let ((map (make-sparse-keymap)))\n    (define-key map (kbd \"?\") #'binder-sidebar-help)\n    (define-key map (kbd \"TAB\") #'forward-button)\n    (define-key map (kbd \"<backtab>\") #'backward-button)\n    (define-key map (kbd \"{\") #'binder-sidebar-shrink-window)\n    (define-key map (kbd \"}\") #'binder-sidebar-enlarge-window)\n    (define-key map (kbd \"g\") #'binder-sidebar-refresh)\n    (define-key map (kbd \"|\") #'binder-sidebar-clear-filters)\n    (define-key map (kbd \"j\") #'binder-sidebar-jump-to-current)\n    (define-key map (kbd \"C\") #'binder-sidebar-change-directory)\n    (define-key map (kbd \"n\") #'next-line)\n    (define-key map (kbd \"p\") #'previous-line)\n    (define-key map (kbd \"RET\") #'binder-sidebar-find-file)\n    (define-key map (kbd \"o\") #'binder-sidebar-find-file-other-window)\n    (define-key map (kbd \"s\") #'binder-sidebar-save)\n    (define-key map [remap save-buffer] #'binder-sidebar-save)\n    (define-key map (kbd \"m\") #'binder-sidebar-mark)\n    (define-key map (kbd \"u\") #'binder-sidebar-unmark)\n    (define-key map (kbd \"t\") #'binder-sidebar-add-tag)\n    (define-key map (kbd \"T\") #'binder-sidebar-remove-tag)\n    (define-key map (kbd \"#\") #'binder-sidebar-toggle-tags)\n    (define-key map (kbd \"U\") #'binder-sidebar-unmark-all)\n    (define-key map (kbd \"i\") #'binder-sidebar-toggle-notes)\n    (define-key map (kbd \"z\") #'binder-sidebar-open-notes)\n    (define-key map (kbd \"c\") #'binder-sidebar-copy-filepath)\n    (define-key map (kbd \"M-n\") #'binder-sidebar-shift-down)\n    (define-key map (kbd \"<M-down>\") #'binder-sidebar-shift-down)\n    (define-key map (kbd \"M-p\") #'binder-sidebar-shift-up)\n    (define-key map (kbd \"<M-up>\") #'binder-sidebar-shift-up)\n    (define-key map (kbd \"a\") #'binder-sidebar-add-file)\n    (define-key map (kbd \"A\") #'binder-sidebar-add-all-files)\n    (define-key map (kbd \"d\") #'binder-sidebar-remove)\n    (define-key map (kbd \"r\") #'binder-sidebar-rename)\n    (define-key map (kbd \"R\") #'binder-sidebar-relocate)\n    (define-key map (kbd \"E\") #'binder-sidebar-toggle-file-extensions)\n    (define-key map (kbd \"/\") #'binder-sidebar-narrow-by-tag)\n    (define-key map (kbd \"\\\\\") #'binder-sidebar-exclude-by-tag)\n    (define-key map (kbd \"M-RET\") #'binder-sidebar-new-file)\n    map))\n\n(define-derived-mode binder-sidebar-mode\n  special-mode \"Binder Sidebar\"\n  \"Major mode for working with `binder' projects.\"\n  (setq indent-tabs-mode nil)\n  (face-remap-add-relative 'default 'binder-sidebar)\n  (add-hook 'post-command-hook #'binder-sidebar-sync-notes t t))\n\n\f\n;;; Notes Major Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n(defface binder-notes\n  '((t nil))\n  \"Default base-level face for `binder-notes-mode' buffers.\")\n\n(defcustom binder-notes-buffer\n  \"*Binder Notes*\"\n  \"Buffer name for Binder notes.\"\n  :type 'string\n  :safe 'stringp\n  :group 'binder-sidebar)\n\n(defcustom binder-notes-display-alist\n  '((side . left)\n    (window-width . 40)\n    (slot . 1))\n  \"Association list used to display binder notes buffer.\n\nSee `display-buffer-in-side-window' for example options.\"\n  :type 'alist\n  :group 'binder-sidebar)\n\n(defcustom binder-notes-persistent-window\n  t\n  \"When non-nil, notes will persist when calling `delete-other-windows'.\n\nThis marks `no-delete-other-windows' window parameter as non-nil.\n\nUse `binder-toggle-notes' or `quit-window' to close notes.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-notes-keep-in-sync\n  nil\n  \"If non-nil, moving point in binder sidebar updates notes.\n\nEnabling this can be disconcerting, because notes are not\nautomatically saved.\"\n  :type 'boolean\n  :safe 'booleanp\n  :group 'binder-sidebar)\n\n(defcustom binder-notes-mode-hook\n  '(visual-line-mode)\n  \"Hook run after entering Binder Notes Mode.\"\n  :type 'hook\n  :options '(visual-line-mode))\n\n(defun binder-notes-refresh ()\n  \"Redraw the notes buffer.\"\n  (setq default-directory binder-project-directory)\n  (with-silent-modifications\n    (erase-buffer)\n    (insert (or (binder-get-item-prop binder--notes-fileid 'notes)\n                \"\"))\n    (setq binder--notes-display\n          (binder-get-item-prop binder--notes-fileid 'display))\n    (setq header-line-format\n          (if binder--notes-fileid\n              (list (list :propertize (or binder--notes-display binder--notes-fileid)\n                          'face 'bold)\n                    \"  C-c C-c to commit; C-c C-q to quit\")\n            \"Nothing selected; C-c C-q to quit\"))))\n\n(defun binder-notes-refresh-window ()\n  \"Call `binder-notes-refresh' if notes window is live.\"\n  (when (window-live-p (get-buffer-window binder-notes-buffer))\n    (with-current-buffer binder-notes-buffer\n      (binder-notes-refresh))))\n\n(defun binder-notes-create-buffer ()\n  \"Create the notes buffer.\"\n  (binder-ensure-in-project)\n  (with-current-buffer (get-buffer-create binder-notes-buffer)\n    (binder-notes-mode)\n    (binder-notes-refresh)\n    (current-buffer)))\n\n(defun binder-notes-create-window ()\n  \"Create the notes window.\"\n  (let ((display-buffer-mark-dedicated t))\n    (display-buffer-in-side-window\n     (binder-notes-create-buffer)\n     (append binder-notes-display-alist\n             (when binder-sidebar-persistent-window\n               (list '(window-parameters (no-delete-other-windows . t))))))))\n\n(defun binder-show-notes (&optional fileid select)\n  \"Show the notes for FILEID of the appropriate project item.\nIf argument SELECT is non-nil, select the notes window.\"\n  (binder-ensure-in-project)\n  (if fileid\n      (setq binder--notes-fileid fileid)\n    (let ((filepath (or (buffer-file-name) default-directory)))\n      (unless (file-equal-p filepath (binder-root))\n        (setq binder--notes-fileid (binder-file-relative-to-root filepath)))))\n  (if (window-live-p (get-buffer-window binder-notes-buffer))\n      (binder-notes-refresh-window)\n    (binder-notes-create-window))\n  (when select (select-window (get-buffer-window binder-notes-buffer))))\n\n(defun binder-sidebar-open-notes ()\n  \"Open notes for item at point and select the notes window.\"\n  (interactive)\n  (binder-show-notes (binder-sidebar-get-fileid) t))\n\n(defun binder-toggle-notes ()\n  \"Toggle visibility of binder notes window.\"\n  (interactive)\n  (if (window-live-p (get-buffer-window binder-notes-buffer))\n      (delete-window (get-buffer-window binder-notes-buffer))\n    (binder-show-notes)))\n\n(defun binder-sidebar-toggle-notes ()\n  \"Toggle visibility of binder notes window for item at point.\"\n  (interactive)\n  (if (window-live-p (get-buffer-window binder-notes-buffer))\n      (delete-window (get-buffer-window binder-notes-buffer))\n    (binder-show-notes (binder-sidebar-get-fileid))))\n\n(defun binder-notes-save ()\n  \"Save notes buffer content to project.\n\nThis command writes project data to disk.\"\n  (interactive)\n  (unless (derived-mode-p 'binder-notes-mode)\n    (user-error \"Not in %S\" 'binder-notes-mode))\n  (if (not (buffer-modified-p))\n      (message \"(No changes need to be added to binder)\")\n    (binder-set-item-prop binder--notes-fileid 'notes\n                          (string-trim (buffer-substring-no-properties\n                                        (point-min) (point-max))))\n    (set-buffer-modified-p nil)\n    (binder-write)\n    (binder-sidebar-refresh-window)\n    (message \"Saved notes for %s to binder\"\n             (or binder--notes-display binder--notes-fileid))))\n\n(defun binder-notes-save-and-quit-window ()\n  \"Call `binder-notes-save' and quit the notes window.\"\n  (declare (interactive-only t))\n  (interactive)\n  (binder-notes-save)\n  (quit-window))\n\n(defun binder-notes-expand-window ()\n  \"Toggle the notes window from a side window to full window.\"\n  (declare (interactive-only t))\n  (interactive)\n  (unless (derived-mode-p 'binder-notes-mode)\n    (user-error \"Not in %S\" 'binder-notes-mode))\n  (if (window-parameter (selected-window) 'window-side)\n      (progn\n        (quit-window)\n        (pop-to-buffer (get-buffer-create binder-notes-buffer)))\n    (quit-window)\n    (binder-show-notes binder--notes-fileid t)))\n\n(defun binder-sidebar-sync-notes ()\n  \"Set the current notes to sidebar item at point.\"\n  (while-no-input\n    (redisplay)\n    (when binder-notes-keep-in-sync\n      (setq binder--notes-fileid (binder-sidebar-get-fileid))\n      (binder-notes-refresh-window))))\n\n(defvar binder-notes-mode-map\n  (let ((map (make-sparse-keymap)))\n    (define-key map (kbd \"C-c C-c\") #'binder-notes-save-and-quit-window)\n    (define-key map [remap save-buffer] #'binder-notes-save)\n    (define-key map (kbd \"C-c C-l\") #'binder-notes-expand-window)\n    (define-key map (kbd \"C-c C-q\") #'quit-window)\n    (define-key map (kbd \"C-c C-k\") #'quit-window)\n    map)\n  \"Mode map for `binder-notes-mode'.\")\n\n(define-derived-mode binder-notes-mode\n  text-mode \"Binder Notes Mode\"\n  \"Major mode for editing `binder' notes.\"\n  (face-remap-add-relative 'default 'binder-notes)\n  (binder-notes-refresh))\n\n\f\n\n(provide 'binder)\n;;; binder.el ends here\n\n;; Local Variables:\n;; coding: utf-8\n;; fill-column: 80\n;; indent-tabs-mode: nil\n;; require-final-newline: t\n;; sentence-end-double-space: nil\n;; End:\n"
  },
  {
    "path": "contrib/binder-theme.el",
    "content": ";; To install this theme, copy or symlink it to your `user-emacs-directory'.\n\n(deftheme binder\n  \"Binder theme, inspired by Scrivener.\")\n\n(custom-theme-set-faces\n 'binder\n '(binder-sidebar\n   ((default (:height 0.9))\n    (((background light)) (:background \"#f1f0f6\"))\n    (((background dark)) (:background \"#33323f\"))))\n '(binder-notes\n   ((default (:height 0.9))\n    (((background light)) (:background \"#fefbe8\"))\n    (((background dark)) (:background \"#302c2c\")))))\n\n(provide-theme 'binder)\n"
  }
]