├── .gitignore ├── LICENSE ├── Makefile ├── NEWS ├── README.md ├── binder-tutorial.el ├── binder.el ├── contrib └── binder-theme.el └── screenshots └── 01.png /.gitignore: -------------------------------------------------------------------------------- 1 | *.elc 2 | *-autoloads.el 3 | *-pkg.el 4 | .dir-locals.el 5 | dir 6 | tutorial/ 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .POSIX: 2 | PROG = binder 3 | LISP_FILE = ${PROG}.el 4 | DEPS = seq package-lint 5 | NEWS_FILE = NEWS 6 | VERS = ${shell grep -oE -m1 'Version:[ 0-9.]+' ${LISP_FILE} | tr -d :} 7 | TAG = ${shell echo ${VERS} | sed -E 's/Version:? ([0-9.]+)/v\1/'} 8 | INIT = (progn \ 9 | (require (quote package)) \ 10 | (push (cons "melpa" "https://melpa.org/packages/") package-archives) \ 11 | (package-initialize) \ 12 | (mapc (lambda (pkg) \ 13 | (unless (package-installed-p pkg) \ 14 | (unless (assoc pkg package-archive-contents) \ 15 | (package-refresh-contents)) \ 16 | (package-install pkg))) \ 17 | (quote (${DEPS})))) 18 | 19 | help: 20 | @echo check 21 | @echo compile 22 | @echo all: clean check compile 23 | @echo tag-release: check compile 24 | @echo clean 25 | 26 | all: clean check compile 27 | 28 | check: 29 | emacs -Q --eval '${INIT}' --batch -f package-lint-batch-and-exit ${LISP_FILE} 30 | 31 | compile: 32 | emacs -Q --eval '${INIT}' -L . --batch -f batch-byte-compile ${LISP_FILE} 33 | 34 | tag-release: check compile 35 | sed -i~ '1 s/.*/* ${VERS}/' ${NEWS_FILE} 36 | git commit -m 'Add ${VERS} to ${NEWS_FILE}' ${NEWS_FILE} 37 | awk '/^* Version/ { v ++1 } v == 1' ${NEWS_FILE} | sed 's/^* //' | git tag -F - ${TAG} 38 | 39 | clean: 40 | rm -f ${PROG}.elc 41 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | * current 2 | 3 | - Use buttons in sidebar, allowing mouse interaction 4 | - Remove "include" and "concat" feature, this is better served with tags 5 | and other tools 6 | - Change Binder-Format-Version to 3, providing automatic upgrade to 7 | convert "(include . t)" properties to #include tags 8 | - Add binder-sidebar-copy-filepath command on c key 9 | - Do not force bold header-line-format 10 | - Print existing filepath when calling binder-sidebar-relocate 11 | - Ensure indent-tabs-mode is nil in sidebar, preventing misalignment of 12 | tags 13 | - Append faces in sidebar to allow multiple faces, e.g. button + 14 | binder-sidebar-highlight 15 | 16 | * Version 0.4.4 17 | 18 | - Add binder-sidebar-clear-filters (|) and remove clear-filters arg from 19 | binder-sidebar-refresh 20 | - Set project file to use lisp-data-mode 21 | - Revert change of sidebar selection face 22 | - Use a single-line prompt when switching project directory 23 | - Remove unnecessary autoloads 24 | - History is now tracked in a fancy NEWS file 25 | - Update email, URL 26 | 27 | * Version 0.4.3 28 | 29 | - Use file-relative-name for binder-file-relative-to-root -- this will 30 | set a fileid outside of the project directory as a relative path 31 | instead of absolute 32 | - Add faces binder-sidebar and binder-notes with face remap to default 33 | - Quit and kill binder side windows in all frames on quit 34 | - Remove call to hack-local-variables from binder-sidebar-refresh, as 35 | this can cause a segfault 36 | - Make safer use of set-transient-map 37 | - Add hints for clearing sidebar tag filters (g key) 38 | - Add binder-theme.el to contrib/ 39 | - Small imporvements to tutorial 40 | - Track known issues with FIXME comments in source 41 | - Stipulate acknowledgement of Scrivener in redistribution terms 42 | - Update email, and upstream URL to https://git.skeletons.cc/binder 43 | - Update repository for portability (add a screenshot, no more relying 44 | on GitHub stuff) 45 | 46 | * Version 0.4.2 47 | 48 | - Give notes window same display alist as sidebar window 49 | - Fix byte-compile issue with lisp-mnt (just don't use it) 50 | 51 | * Version 0.4.1 52 | 53 | - Correct spelling of option binder-default-file-extension 54 | 55 | * Version 0.4.0 56 | 57 | - Implement binder-tutorial as separate library 58 | - Don't call binder-mode from binder-reveal-in-sidebar 59 | 60 | * Version 0.3.1 61 | 62 | This release marks Binder as no longer in alpha status. 63 | 64 | - Ensure notes window keeps track of fileid 65 | 66 | - No longer set pop-up-windows as buffer-local in sidebar, set it 67 | lexically. 68 | - binder-get-buffer-fileid returns binder--notes-fileid when in 69 | notes window. 70 | - binder-show-notes now takes FILEID and SELECT to make tracking 71 | notes fileid easier, no longer needing to find it from sidebar. 72 | 73 | - Hack local variables when refreshing sidebar 74 | - Implement item shifting when filtered by tag 75 | - Prefer elt to nth 76 | 77 | * Version 0.3.0 78 | 79 | Changes 80 | 81 | - Change project file format to version 2 (adds binder-upgrade subr) 82 | - Implement binder-init-project command 83 | - Implement binder-sidebar-toggle-hide-tags command 84 | - Add binder-filter function 85 | - Rename binder-concat-find-original-file -> binder-concat-find-original 86 | - Change binder-concat-find-original key binding to C-c RET 87 | - Revert key binding for binder-sidebar-change-directory (P -> C) 88 | - Save project and clear cache on quit 89 | - Always write project data to file on delete item 90 | - Lower Emacs version requirement to 24.4 91 | - Prefer "project" to "binder" in var names and docs 92 | - Update tutorial 93 | 94 | Fixes 95 | 96 | - Rewrite binder-read 97 | - Fix binder-concat-mode-map var name 98 | - Clear tags filter on binder-cd 99 | - Remove binder-sidebar-set-status command (use binder-sidebar-add-tag) 100 | - Call binder-cd when initializing a project 101 | - Only find project file within binder-project-directory 102 | - Fix for calling binder-next when in sidebar 103 | - Set pop-up-windows as buffer-local in binder-sidebar-mode 104 | - Fix binder-sidebar-find-file pop window with ARG 105 | 106 | * Version 0.2.0 107 | 108 | - Rewrite to use global dynamic variable binder-project-file 109 | - Replace status with tags 110 | 111 | Instead of setting a single status per item, now you can set multple 112 | tags. Items displayed in the sidebar can be filtered interactively with 113 | binder-narrow-by-tag and binder-exclude-by-tag comamnds. 114 | 115 | - binder-get-tags now takes arg CURRENT 116 | 117 | CURRENT will get structure accounting for binder-narrow-tags and 118 | binder-exclude-tags 119 | 120 | - Improve aesthetics when tags overwrite item display name 121 | - Add tutorial project 122 | - Ensure binder-root returns directory or nil 123 | - Add binder-get-buffer-fileid for buffers 124 | - Add/rename binder-sidebar|notes-persistent-window options 125 | - Make binder-sidebar-select-window default nil 126 | - Change binder-staple-* -> binder-concat-* 127 | 128 | * Version 0.1.0 129 | 130 | First public release 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Binder has moved to https://codeberg.org/divyaranjan/binder/ 2 | 3 | Binder 4 | ====== 5 | 6 | [![MELPA Stable](https://stable.melpa.org/packages/binder-badge.svg)][1] 7 | [![MELPA](https://melpa.org/packages/binder-badge.svg)][2] 8 | 9 | ![screenshot](screenshots/01.png) 10 | 11 | Binder is global minor mode to facilitate working on a writing project 12 | in multiple files. It is heavily inspired by the binder feature in the 13 | [macOS writing app Scrivener][3]. 14 | 15 | The rationale behind working this way is to split a large writing 16 | project into smaller pieces. 17 | 18 | 19 | Features 20 | -------- 21 | 22 | Primarily, Binder provides a global minor mode `binder-mode`. This 23 | allows working with files in the current `binder-project-directory`. 24 | Data concerning these files is saved in a `.binder.el` file in the 25 | project directory. 26 | 27 | A project can be thought of an ordered list of files with associated 28 | notes and tags. 29 | 30 | 31 | Navigation 32 | ---------- 33 | 34 | At the most basic level, you can navigate back and forth through the 35 | files in a project: 36 | 37 | - `binder-next (C-c ])` visits the next file in the project 38 | - `binder-previous (C-c [)` visits the previous 39 | 40 | Calling these commands activates a transient map so that each command 41 | can be repeated without the prefix key. 42 | 43 | 44 | Sidebar 45 | ------- 46 | 47 | You'll mostly interact with the project structure via the sidebar. 48 | 49 | - `binder-toggle-sidebar (C-c ')` toggles the visibility of the binder 50 | sidebar 51 | - `binder-reveal-in-sidebar (C-c ;)` finds the current file in the 52 | sidebar 53 | 54 | Each project item is a file reference relative to the project directory. 55 | 56 | Project items are displayed in a linear ordered list. Calling 57 | `binder-sidebar-find-file (RET)` or `binder-sidebar-find-file-other-window (o)` 58 | will visit the corresponding file. 59 | 60 | Each item in the sidebar displays the following information: 61 | 62 | 1. `*` denotes that this item has some notes (see **Notes** below), 63 | or... 64 | 2. `?` denotes that the item's corresponding file cannot be found 65 | 3. either the file relative to the project directory, or an arbitrary 66 | display name 67 | 4. `#tag1 #tag2 ...` arbitrary item tags (see **Tags** below) 68 | 69 | An item's display name can be changed with `binder-sidebar-rename (r)`. 70 | If a file cannot be found, relocate with `binder-sidebar-relocate (R)`. 71 | 72 | Calling `binder-sidebar-find-file (RET)` will visit the corresponding 73 | file. 74 | 75 | To add an existing file, call `binder-sidebar-add-file (a)` or add all 76 | files in directory with `binder-sidebar-add-all-files (A)`. 77 | 78 | Add a new file with `binder-sidebar-new-file (M-RET)`. This prompts for a 79 | file-name and adds this (possibly non-existent) file to the project 80 | after the current file's index. If no file-name extension is provided, 81 | use `binder-default-file-extension`. 82 | 83 | > Hint: you can use an alternate default file extension for different 84 | > projects by setting a directory local variable. 85 | 86 | Files can also be added to a project from outside the sidebar with 87 | `binder-add-file (C-c :)`. 88 | 89 | Items can be reordered with `binder-sidebar-shift-up (M-p | M-up)` and 90 | `binder-sidebar-shift-down (M-n | M-down)`. 91 | 92 | Remove items with `binder-sidebar-remove (d)` -- this *does not delete 93 | the files*, only removes them from the project, but it *does* delete the 94 | corresponding notes and tags. 95 | 96 | Hide item file extensions by setting the `binder-sidebar-hide-file-extensions` 97 | option. This can be toggled with `binder-sidebar-toggle-file-extensions (E)`. 98 | 99 | The sidebar can be resized with `binder-sidebar-shrink-window ({)` and 100 | `binder-sidebar-enlarge-window (})`. The window size is changed by the 101 | number of columns specified in option `binder-sidebar-resize-window-step`. 102 | 103 | You can customize how the sidebar window is displayed by setting 104 | `binder-sidebar-display-alist` option. 105 | 106 | 107 | Notes 108 | ----- 109 | 110 | To open the notes buffer from the sidebar, call either 111 | `binder-sidebar-open-notes (z)` to open and select the notes window, or 112 | `binder-sidebar-toggle-notes (i)` to toggle the window. 113 | 114 | To open a project file's notes from outside the sidebar, call 115 | `binder-toggle-notes (C-c ")`. 116 | 117 | You need to call either `binder-notes-save (C-x C-s)` or 118 | `binder-notes-save-and-quit-window (C-c C-c)` to save notes to the 119 | project file. 120 | 121 | Calling `quit-window (C-c C-q | C-c C-k)` or `binder-toggle-sidebar` 122 | does not save notes. 123 | 124 | You can embiggen the notes window, to pop it out from the sidebar and 125 | edit like a regular buffer window, with `binder-notes-expand-window (C-c 126 | C-l)`. 127 | 128 | You can customize how the notes window is displayed by setting 129 | `binder-notes-display-alist` option. 130 | 131 | 132 | Tags 133 | ---- 134 | 135 | Tags can help organize a project. An item can have any number of tags. 136 | 137 | Add a tag to an item with `binder-sidebar-add-tag (t)`. Remove a tag 138 | from an item with `binder-sidebar-remove-tag (T)`. You can tag/untag 139 | multiple items at once by using marks (see **Marking** below). 140 | 141 | Items in the sidebar can be narrowed to only show items with a certain 142 | tag with `binder-sidebar-narrow-by-tag (/)` and/or only show items 143 | without a certain tag with `binder-sidebar-exclude-by-tag (\)`. Each of 144 | these commands can be called multiple times with additional tags. 145 | 146 | Clear the sidebar filters with `binder-sidebar-clear-filters (|)`. 147 | 148 | 149 | Marking 150 | ------- 151 | 152 | Multiple items can be marked to add tags, toggle include state or 153 | delete. Call `binder-sidebar-mark (m)` to mark an item or 154 | `binder-sidebar-unmark (u)` to unmark an item. 155 | 156 | To unmark all sidebar items, call `binder-sidebar-unmark-all (U)`. 157 | 158 | 159 | Requirements 160 | ------------ 161 | 162 | - Emacs 24.4 163 | - seq 2.20 (part of Emacs 25 and later) 164 | 165 | 166 | Installation 167 | ------------ 168 | 169 | The latest stable release of Binder is available via [MELPA-stable][1]. 170 | First, add MELPA-stable to your package archives: 171 | 172 | M-x customize-option RET package-archives RET 173 | 174 | Insert an entry named `melpa-stable` with URL: 175 | https://stable.melpa.org/packages/ 176 | 177 | You can then find the latest stable version of `binder` in the list 178 | returned by: 179 | 180 | M-x list-packages RET 181 | 182 | If you prefer the latest but perhaps unstable version, do the above 183 | using [MELPA][2]. 184 | 185 | 186 | Advanced Installation 187 | --------------------- 188 | 189 | Download the latest tagged release, move this file into your `load-path` 190 | and add to your `init.el` file: 191 | 192 | (require 'binder) 193 | (require 'binder-tutorial) ;; optional 194 | 195 | If you wish to contribute to or alter Binder's code, clone the 196 | repository into your load-path and require as above: 197 | 198 | git clone https://github.com/rnkn/binder.git 199 | 200 | 201 | Bugs and Feature Requests 202 | ------------------------- 203 | 204 | Send me an email (address in the package header). For bugs, please 205 | ensure you can reproduce with: 206 | 207 | $ emacs -Q -l binder.el 208 | 209 | Known issues are tracked with `FIXME` comments in the source. 210 | 211 | 212 | Tutorial 213 | -------- 214 | 215 | Binder comes with a tutorial. Calling `M-x binder-tutorial` will prompt 216 | for an empty directory in which to generate the tutorial files. 217 | 218 | 219 | [1]: https://stable.melpa.org/#/binder 220 | [2]: https://melpa.org/#/binder 221 | [3]: https://www.literatureandlatte.com/scrivener/ 222 | -------------------------------------------------------------------------------- /binder-tutorial.el: -------------------------------------------------------------------------------- 1 | ;;; binder-tutorial.el --- Tutorial for Binder projects -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (c) 2020-2024 Paul W. Rankin 4 | 5 | ;; Author: Paul W. Rankin 6 | ;; Keywords: help, wp, convenience 7 | 8 | ;; This program is free software; you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; This file contains code to generate a Binder project tutorial. It is 24 | ;; loaded upon calling `binder-tutorial'. 25 | 26 | 27 | ;;; Code: 28 | 29 | (require 'binder) 30 | 31 | (defconst binder-tutorial-items 32 | (list 33 | (cons ".binder.el" 34 | (concat binder-file-header "\ 35 | ((\"projects.txt\" 36 | (tags \"start-here\")) 37 | (\"sidebar.txt\" 38 | (tags \"foo\" \"bar\")) 39 | (\"navigation.txt\") 40 | (\"marks.txt\") 41 | (\"notes.txt\" 42 | (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.\")) 43 | (\"tags.txt\" 44 | (tags \"foo\")) 45 | (\"errors.txt\"))")) 46 | (cons "projects.txt" "\ 47 | A project in Binder is a linear list of files in with associated 48 | information (i.e. their order, notes, and tags). This information 49 | is stored in a .binder.el file in the top-level directory of the 50 | project. 51 | 52 | You can only work on one project at a time in one Emacs session. 53 | 54 | When locating the current project file, Binder looks in the current 55 | directory then each parent directory, with the first found taking 56 | precedence. Consider the following file layout: 57 | 58 | ├── .binder.el <-- project A 59 | ├── foo.txt 60 | ├── dir1 61 | │ └── bar.txt 62 | └── dir2 63 | ├── .binder.el <-- project B 64 | └── baz.txt 65 | 66 | Here project A could reference files foo.txt, bar.txt and baz.txt. 67 | However when visiting file baz.txt, project B would take precedence. 68 | 69 | Most management of a project will happen via the sidebar. Type C-c ] to 70 | go to sidebar.txt.") 71 | (cons "sidebar.txt" "\ 72 | By default items in the sidebar will show: 73 | 74 | * name #tag1 #tag2 75 | 76 | These things mean: 77 | 78 | * the item has project notes 79 | name either the item file name, or a custom item display name 80 | #tag arbitrary item tag/s 81 | 82 | You can move about in the sidebar by typing n and p, < and > and visit a 83 | file by simply typing RET. Jump to the current item with j. You can 84 | quickly resize the sidebar with { and }. 85 | 86 | You can rearrange items with M-n and M-p. You can toggle file extensions 87 | with E. 88 | 89 | Type C-c ' to toggle the sidebar on/off. When visiting a project file, 90 | type C-c ; to reveal it in the sidebar. 91 | 92 | Try changing this item's display name with r. You can revert this by 93 | doing the same and entering nothing. 94 | 95 | Binder will automatically write its current project file after a certain 96 | number of changes, but you can manually save a project by typing s. 97 | 98 | Type C-c ] to go to the next file.") 99 | (cons "navigation.txt" "\ 100 | You can navigate through project items forward and backward with C-c ] 101 | and C-c [, which means Emacs will visit each file in the project list in 102 | succession. 103 | 104 | Try typing C-c [ to go back to a previous file. You don't need to prefix 105 | C-c each time, so you can type e.g. C-c [ [ ] ] ] to repeatedly navigate 106 | backward/forward. 107 | 108 | The highlight in the sidebar lets you know where you are so you don't 109 | get lost. 110 | 111 | Type C-c ] to go to the next file.") 112 | (cons "marks.txt" "\ 113 | You can mark multiple project items in the sidebar by typing m. Unmark 114 | an item with u or unmark all items with U. 115 | 116 | Marking items allows you to perform actions on multiple items at once. 117 | 118 | Type C-c ] to go to the next file.") 119 | (cons "notes.txt" "\ 120 | Each item can have notes, which are stored in the project file. In the 121 | sidebar, type z to open this item's notes. 122 | 123 | Add or change the notes and type C-c C-c (save notes and close window) 124 | or C-x C-s (save notes without closing window). To quit the notes window 125 | without saving the notes, type either C-c C-q or C-c C-k. 126 | 127 | You can toggle the notes window without selecting it by typing i. 128 | 129 | To really mix things up, open the notes window and, with it selected, 130 | type C-c C-l. This pops the window out to be a regular window (instead 131 | of a side-window). This command works as a toggle. 132 | 133 | A file's notes can be edited without opening the sidebar with C-c \". 134 | 135 | Type C-c ] to go to the next file.") 136 | (cons "tags.txt" "\ 137 | Each project item can have any number of arbitrary tags, which are 138 | prefixed with # by default. 139 | 140 | To add a tag to an item, type t and enter the tag. To remove a tag, type 141 | T and enter the tag. These commands work either with the item at point, 142 | or all marked items. 143 | 144 | Some tags are already added to play with. Type / then \"foo\" to narrow 145 | the sidebar to only items tagged \"foo\". Now type \\ then \"bar\" to exclude 146 | sidebar items tagged \"bar\". 147 | 148 | You should have a sidebar with only this item showing. 149 | 150 | Filtering the sidebar using tags allows a lot of flexibility with which 151 | project files you want to work with in the sidebar. 152 | 153 | When the sidebar items are filtered, navigating backward/forward only 154 | considers those items. 155 | 156 | Type | to clear the sidebar filters, then C-c ] to go to the next file.") 157 | (cons "errors.txt" "\ 158 | Binder caches project information to avoid contious reading and writing 159 | to disk. However this means errors may occur if a project is moved on 160 | disk while project information is cached. If you plan on moving a 161 | projects on disk it's best to deactivate binder-mode first."))) 162 | 163 | ;;;###autoload 164 | (defun binder-tutorial (directory) 165 | "Generate the Binder tutorial project in empty DIRECTORY." 166 | (interactive "DGenerate tutorial project in directory: ") 167 | (let ((default-directory directory)) 168 | (mapc (lambda (item) 169 | (let ((old-buffer (get-buffer (car item)))) 170 | (when (buffer-live-p old-buffer) (kill-buffer old-buffer))) 171 | (with-temp-buffer 172 | (let ((require-final-newline t)) 173 | (insert (cdr item)) 174 | (write-file (car item))))) 175 | binder-tutorial-items) 176 | (binder-mode 1) 177 | (binder-sidebar-create-window) 178 | (select-window (get-buffer-window binder-sidebar-buffer)))) 179 | 180 | 181 | 182 | (provide 'binder-tutorial) 183 | ;;; binder-tutorial.el ends here 184 | 185 | ;; Local Variables: 186 | ;; coding: utf-8 187 | ;; fill-column: 80 188 | ;; indent-tabs-mode: nil 189 | ;; require-final-newline: t 190 | ;; sentence-end-double-space: nil 191 | ;; End: 192 | -------------------------------------------------------------------------------- /binder.el: -------------------------------------------------------------------------------- 1 | ;;; binder.el --- Global minor mode to facilitate multi-file writing projects -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (c) 2020-2024 Paul W. Rankin 4 | ;; 2024 Divya Ranjan 5 | 6 | ;; Maintainer: Divya Ranjan 7 | ;; Author: Paul W. Rankin 8 | ;; Keywords: files, outlines, wp, text 9 | ;; Version: 0.5.0 10 | ;; Package-Requires: ((emacs "24.4") (seq "2.20")) 11 | ;; URL: https://codeberg.org/divyaranjan/binder/ 12 | 13 | ;; This file is not part of GNU Emacs. 14 | 15 | ;; This program is free software; you can redistribute it and/or modify it under 16 | ;; the terms of the GNU General Public License as published by the Free Software 17 | ;; Foundation, either version 3 of the License, or (at your option) any later 18 | ;; version. 19 | 20 | ;; This program is distributed in the hope that it will be useful, but WITHOUT 21 | ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22 | ;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 23 | ;; details. 24 | 25 | ;; You should have received a copy of the GNU General Public License along with 26 | ;; this program. If not, see . 27 | 28 | ;; In addition to conditions of the GNU General Public License, this program may 29 | ;; not be redistributed without the following acknowledgement: 30 | 31 | ;; This program takes influence from the macOS writing application Scrivener, 32 | ;; created by Literature and Latte . 33 | 34 | ;;; Commentary: 35 | 36 | ;; Binder 37 | ;; ====== 38 | 39 | ;; Binder is global minor mode to facilitate working on a writing project 40 | ;; in multiple files. It is heavily inspired by the binder feature in the 41 | ;; [macOS writing app Scrivener][3]. 42 | 43 | ;; The rationale behind working this way is to split a large writing 44 | ;; project into smaller pieces. 45 | 46 | 47 | ;; Features 48 | ;; -------- 49 | 50 | ;; Primarily, Binder provides a global minor mode binder-mode. This 51 | ;; allows working with files in the current binder-project-directory. 52 | ;; Data concerning these files is saved in a .binder.el file in the 53 | ;; project directory. 54 | 55 | ;; A project can be thought of an ordered list of files with associated 56 | ;; notes and tags. 57 | 58 | 59 | ;; Navigation 60 | ;; ---------- 61 | 62 | ;; At the most basic level, you can navigate back and forth through the 63 | ;; files in a project: 64 | 65 | ;; - binder-next (C-c ]) visits the next file in the project 66 | ;; - binder-previous (C-c [) visits the previous 67 | 68 | ;; Calling these commands activates a transient map so that each command 69 | ;; can be repeated without the prefix key. 70 | 71 | 72 | ;; Sidebar 73 | ;; ------- 74 | 75 | ;; You'll mostly interact with the project structure via the sidebar. 76 | 77 | ;; - binder-toggle-sidebar (C-c ') toggles the visibility of the binder 78 | ;; sidebar 79 | ;; - binder-reveal-in-sidebar (C-c ;) finds the current file in the 80 | ;; sidebar 81 | 82 | ;; Each project item is a file reference relative to the project directory. 83 | 84 | ;; Project items are displayed in a linear ordered list. Calling 85 | ;; binder-sidebar-find-file (RET) or binder-sidebar-find-file-other-window (o) 86 | ;; will visit the corresponding file. 87 | 88 | ;; Each item in the sidebar displays the following information: 89 | 90 | ;; 1. * denotes that this item has some notes (see **Notes** below), 91 | ;; or... 92 | ;; 2. ? denotes that the item's corresponding file cannot be found 93 | ;; 3. either the file relative to the project directory, or an arbitrary 94 | ;; display name 95 | ;; 4. #tag1 #tag2 ... arbitrary item tags (see **Tags** below) 96 | 97 | ;; An item's display name can be changed with binder-sidebar-rename (r). 98 | ;; If a file cannot be found, relocate with binder-sidebar-relocate (R). 99 | 100 | ;; Calling binder-sidebar-find-file (RET) will visit the corresponding 101 | ;; file. 102 | 103 | ;; To add an existing file, call binder-sidebar-add-file (a) or add all 104 | ;; files in directory with binder-sidebar-add-all-files (A). 105 | 106 | ;; Add a new file with binder-sidebar-new-file (M-RET). This prompts for a 107 | ;; file-name and adds this (possibly non-existent) file to the project 108 | ;; after the current file's index. If no file-name extension is provided, 109 | ;; use binder-default-file-extension. 110 | 111 | ;; > Hint: you can use an alternate default file extension for different 112 | ;; > projects by setting a directory local variable. 113 | 114 | ;; Files can also be added to a project from outside the sidebar with 115 | ;; binder-add-file (C-c :). 116 | 117 | ;; Items can be reordered with binder-sidebar-shift-up (M-p | M-up) and 118 | ;; binder-sidebar-shift-down (M-n | M-down). 119 | 120 | ;; Remove items with binder-sidebar-remove (d) -- this *does not delete 121 | ;; the files*, only removes them from the project, but it *does* delete the 122 | ;; corresponding notes and tags. 123 | 124 | ;; Hide item file extensions by setting the binder-sidebar-hide-file-extensions 125 | ;; option. This can be toggled with binder-sidebar-toggle-file-extensions (E). 126 | 127 | ;; The sidebar can be resized with binder-sidebar-shrink-window ({) and 128 | ;; binder-sidebar-enlarge-window (}). The window size is changed by the 129 | ;; number of columns specified in option binder-sidebar-resize-window-step. 130 | 131 | ;; You can customize how the sidebar window is displayed by setting 132 | ;; binder-sidebar-display-alist option. 133 | 134 | 135 | ;; Notes 136 | ;; ----- 137 | 138 | ;; To open the notes buffer from the sidebar, call either 139 | ;; binder-sidebar-open-notes (z) to open and select the notes window, or 140 | ;; binder-sidebar-toggle-notes (i) to toggle the window. 141 | 142 | ;; To open a project file's notes from outside the sidebar, call 143 | ;; binder-toggle-notes (C-c "). 144 | 145 | ;; You need to call either binder-notes-save (C-x C-s) or 146 | ;; binder-notes-save-and-quit-window (C-c C-c) to save notes to the 147 | ;; project file. 148 | 149 | ;; Calling quit-window (C-c C-q | C-c C-k) or binder-toggle-sidebar 150 | ;; does not save notes. 151 | 152 | ;; You can embiggen the notes window, to pop it out from the sidebar and 153 | ;; edit like a regular buffer window, with binder-notes-expand-window (C-c 154 | ;; C-l). 155 | 156 | ;; You can customize how the notes window is displayed by setting 157 | ;; binder-notes-display-alist option. 158 | 159 | 160 | ;; Tags 161 | ;; ---- 162 | 163 | ;; Tags can help organize a project. An item can have any number of tags. 164 | 165 | ;; Add a tag to an item with binder-sidebar-add-tag (t). Remove a tag 166 | ;; from an item with binder-sidebar-remove-tag (T). You can tag/untag 167 | ;; multiple items at once by using marks (see **Marking** below). 168 | 169 | ;; Items in the sidebar can be narrowed to only show items with a certain 170 | ;; tag with binder-sidebar-narrow-by-tag (/) and/or only show items 171 | ;; without a certain tag with binder-sidebar-exclude-by-tag (\). Each of 172 | ;; these commands can be called multiple times with additional tags. 173 | 174 | ;; Clear the sidebar filters with binder-sidebar-clear-filters (|). 175 | 176 | 177 | ;; Marking 178 | ;; ------- 179 | 180 | ;; Multiple items can be marked to add tags, toggle include state or 181 | ;; delete. Call binder-sidebar-mark (m) to mark an item or 182 | ;; binder-sidebar-unmark (u) to unmark an item. 183 | 184 | ;; To unmark all sidebar items, call binder-sidebar-unmark-all (U). 185 | 186 | 187 | ;; Requirements 188 | ;; ------------ 189 | 190 | ;; - Emacs 24.4 191 | ;; - seq 2.20 (part of Emacs 25 and later) 192 | 193 | 194 | ;; Installation 195 | ;; ------------ 196 | 197 | ;; The latest stable release of Binder is available via [MELPA-stable][1]. 198 | ;; First, add MELPA-stable to your package archives: 199 | 200 | ;; M-x customize-option RET package-archives RET 201 | 202 | ;; Insert an entry named melpa-stable with URL: 203 | ;; https://stable.melpa.org/packages/ 204 | 205 | ;; You can then find the latest stable version of binder in the list 206 | ;; returned by: 207 | 208 | ;; M-x list-packages RET 209 | 210 | ;; If you prefer the latest but perhaps unstable version, do the above 211 | ;; using [MELPA][2]. 212 | 213 | 214 | ;; Advanced Installation 215 | ;; --------------------- 216 | 217 | ;; Download the latest tagged release, move this file into your load-path 218 | ;; and add to your init.el file: 219 | 220 | ;; (require 'binder) 221 | ;; (require 'binder-tutorial) ;; optional 222 | 223 | ;; If you wish to contribute to or alter Binder's code, clone the 224 | ;; repository into your load-path and require as above: 225 | 226 | ;; git clone https://github.com/rnkn/binder.git 227 | 228 | 229 | ;; Bugs and Feature Requests 230 | ;; ------------------------- 231 | 232 | ;; Send me an email (address in the package header). For bugs, please 233 | ;; ensure you can reproduce with: 234 | 235 | ;; $ emacs -Q -l binder.el 236 | 237 | ;; Known issues are tracked with FIXME comments in the source. 238 | 239 | 240 | ;; Tutorial 241 | ;; -------- 242 | 243 | ;; Binder comes with a tutorial. Calling M-x binder-tutorial will prompt 244 | ;; for an empty directory in which to generate the tutorial files. 245 | 246 | 247 | ;; [1]: https://stable.melpa.org/#/binder 248 | ;; [2]: https://melpa.org/#/binder 249 | ;; [3]: https://www.literatureandlatte.com/scrivener/ 250 | 251 | 252 | ;;; Code: 253 | 254 | (eval-when-compile (require 'cl-lib)) 255 | (eval-when-compile (require 'subr-x)) 256 | (require 'lisp-mnt) 257 | (require 'seq) 258 | 259 | (defgroup binder () 260 | "Work with a structured project of files." 261 | :group 'files) 262 | 263 | 264 | ;;; Core Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 265 | 266 | (defvar binder-format-version 3) 267 | (defvar binder-file-header 268 | (format "\ 269 | ;; -*- mode: lisp-data; coding: utf-8 -*- 270 | ;; Binder-Format-Version: %s 271 | ;; This is a Binder project file. It is meant to be human-readable, but you 272 | ;; probably shouldn't edit it.\n\n" binder-format-version) 273 | "Header information for project file.") 274 | 275 | (defvar binder--cache nil) 276 | (defvar binder--modification-time nil) 277 | (defvar binder--modification-count 0) 278 | (defvar binder--current-fileid nil) 279 | (defvar binder--sidebar-marked nil) 280 | (defvar binder--notes-fileid nil) 281 | (defvar binder--notes-display nil) 282 | (defvar binder-narrow-tags nil) 283 | (defvar binder-exclude-tags nil) 284 | (defvar binder-status-filter-in nil) 285 | (defvar binder-status-filter-out nil) 286 | 287 | 288 | ;;; Options ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 289 | 290 | (defcustom binder-mode-lighter 291 | " B/" 292 | "Mode-line indicator for `binder-mode'." 293 | :type '(choice (const :tag "No lighter" "") string) 294 | :safe 'stringp 295 | :group 'binder) 296 | 297 | (defcustom binder-default-file 298 | ".binder.el" 299 | "Default file in which to store Binder project data." 300 | :type 'string 301 | :safe 'stringp 302 | :group 'binder) 303 | 304 | (defcustom binder-project-directory 305 | nil 306 | "Directory containing current `binder-default-file' or nil. 307 | 308 | The value set here will be used as default, but may be changed at 309 | any time with `binder-change-directory'." 310 | :type '(choice (const nil) directory) 311 | :safe 'stringp 312 | :group 'binder) 313 | 314 | (defcustom binder-default-file-extension 315 | "txt" 316 | "Default extension for new binder files." 317 | :type 'string 318 | :safe 'stringp 319 | :group 'binder) 320 | 321 | (defcustom binder-save-threshold 322 | 20 323 | "Integer of changes before binder file is automatically saved." 324 | :type 'integer 325 | :safe 'integerp 326 | :group 'binder) 327 | 328 | 329 | ;;; Faces ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 330 | 331 | (defgroup binder-sidebar-faces () 332 | "Default faces for `binder-sidebar-mode'." 333 | :group 'binder-sidebar) 334 | 335 | (defface binder-sidebar-marked 336 | '((t (:inherit (warning)))) 337 | "Default face marked items." 338 | :group 'binder-sidebar-faces) 339 | 340 | (defface binder-sidebar-highlight 341 | '((t (:extend t :inherit (secondary-selection)))) 342 | "Default face for highlighted items." 343 | :group 'binder-sidebar-faces) 344 | 345 | (defface binder-sidebar-missing 346 | '((t (:inherit (trailing-whitespace)))) 347 | "Default face for missing items." 348 | :group 'binder-sidebar-faces) 349 | 350 | (defface binder-sidebar-tags 351 | '((t (:inherit (font-lock-variable-name-face)))) 352 | "Default face for tags." 353 | :group 'binder-sidebar-faces) 354 | 355 | 356 | ;;; Core Non-interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 357 | 358 | (defun binder-root () 359 | "Return the root directory with a project file, or nil." 360 | (locate-dominating-file default-directory binder-default-file)) 361 | 362 | (defun binder-set-modified () 363 | "Set the project data as modified." 364 | (cl-incf binder--modification-count) 365 | (setq binder--modification-time (current-time))) 366 | 367 | (defun binder-set-unmodified () 368 | "Set the project data as unmodified." 369 | (setq binder--modification-count 0 370 | binder--modification-time (current-time))) 371 | 372 | (defun binder-cd (directory) 373 | "Set `binder-project-directory' to DIRECTORY and erase cache." 374 | (customize-set-variable 'binder-project-directory directory) 375 | (setq binder-narrow-tags nil 376 | binder-exclude-tags nil 377 | binder--notes-fileid nil 378 | binder--cache nil) 379 | (binder-set-unmodified)) 380 | 381 | (defun binder-init () 382 | "Initialize an empty project file in `binder-project-directory'." 383 | (with-temp-buffer 384 | (insert binder-file-header 385 | (pp-to-string nil)) 386 | (write-file (expand-file-name binder-default-file binder-project-directory)))) 387 | 388 | (defun binder-locate-project-file () 389 | "Find or initialize current project file." 390 | (let ((binder-file 391 | (expand-file-name binder-default-file binder-project-directory))) 392 | (unless (file-exists-p binder-file) (binder-init)) 393 | binder-file)) 394 | 395 | (defun binder-write () 396 | "Write project data to file." 397 | (let ((binder-file (binder-locate-project-file))) 398 | (with-temp-buffer 399 | (insert binder-file-header 400 | (pp-to-string binder--cache)) 401 | (write-file binder-file))) 402 | (binder-set-unmodified)) 403 | 404 | (defun binder-write-maybe () 405 | "Call `binder-write' if modified threshold has been reached. 406 | Otherwise call `binder-set-modified'." 407 | (if (<= binder-save-threshold binder--modification-count) 408 | (binder-write) 409 | (binder-set-modified))) 410 | 411 | (defun binder-filter (data) 412 | "Filter project DATA by tags. 413 | Included `binder-narrow-tags' and excluded `binder-exclude-tags'." 414 | (seq-filter 415 | (lambda (item) 416 | (and (seq-every-p 417 | (lambda (tag) 418 | (member tag (cdr (assq 'tags item)))) 419 | binder-narrow-tags) 420 | (seq-every-p 421 | (lambda (tag) 422 | (not (member tag (cdr (assq 'tags item))))) 423 | binder-exclude-tags))) 424 | data)) 425 | 426 | (defun binder-upgrade (data version) 427 | "Upgrade project DATA in VERSION to `binder-format-version'." 428 | (cond ((not (stringp version)) 429 | (binder-upgrade (cdr (assq 'structure data)) "2")) 430 | ((= (string-to-number version) 2) 431 | (mapcar 432 | (lambda (item) 433 | (when (cdr (assq 'include item)) 434 | (let ((tags (assq 'tags item))) 435 | (if tags 436 | (cl-pushnew "include" (cdr tags)) 437 | (push (list 'tags "include") (cdr item))))) 438 | (assq-delete-all 'include item)) 439 | data)) 440 | (t data))) 441 | 442 | (defun binder-read (&optional filter) 443 | "Read current project data. 444 | Reads from `binder--cache' if valid, or from project file if not. 445 | With optional argument FILTER, call `binder-filter' on data." 446 | (let ((binder-file (binder-locate-project-file)) 447 | version) 448 | (when binder--cache 449 | (cond 450 | ;; If there's no project file found, signal an error. 451 | ((null binder-file) 452 | (user-error "No binder file found")) 453 | ;; If the cache doesn't refer to the project directory, set the cache to 454 | ;; nil. 455 | ((and (binder-root) 456 | (not (file-equal-p binder-project-directory (binder-root)))) 457 | (setq binder--cache nil)) 458 | ;; If the project file is newer than the cache, offer to revert from disk 459 | ;; (and write binder data), regardless, set the cache to nil. 460 | ((time-less-p binder--modification-time 461 | (elt (file-attributes binder-file) 5)) 462 | (unless (y-or-n-p "Project file changed on disk; revert from disk? ") 463 | (binder-write)) 464 | (setq binder--cache nil)))) 465 | ;; If the cache survived all that, it's valid, otherwise, read from the 466 | ;; project file. 467 | (unless binder--cache 468 | (with-temp-buffer 469 | (insert-file-contents binder-file) 470 | ;; Read Binder-Format-Version header 471 | (setq version (lm-header "binder-format-version")) 472 | (goto-char (point-min)) 473 | (setq binder--cache 474 | (binder-upgrade (read (current-buffer)) version))) 475 | (binder-set-unmodified))) 476 | ;; Finally, return the cache. 477 | (if filter (binder-filter binder--cache) binder--cache)) 478 | 479 | (defun binder-ensure-in-project () 480 | "Ensure the current file or directory is in the project." 481 | (let ((root (binder-root))) 482 | (cond 483 | ;; The project directory matches root, we're all good. 484 | ((and (stringp binder-project-directory) 485 | (stringp root) 486 | (file-equal-p binder-project-directory root)) 487 | t) 488 | ;; The project directory does not match project root; offer to change it to 489 | ;; current project root. 490 | ((and (stringp binder-project-directory) 491 | (stringp root)) 492 | (when (y-or-n-p (format "Change project directory to %s? " 493 | root)) 494 | (binder-cd root))) 495 | ;; The project directory is set but we're not in a project; this is fine. 496 | ((stringp binder-project-directory) 497 | t) 498 | ;; The project directory is not set, but we're in a project; offer to set 499 | ;; it to current project root. 500 | ((stringp root) 501 | (binder-cd root) 502 | (message "Set binder directory to %s" root)) 503 | ;; A fresh project; offer to set project directory to default-directory. 504 | (t 505 | (when (y-or-n-p (format "Set binder directory to %s? " 506 | (abbreviate-file-name default-directory))) 507 | (binder-cd default-directory) 508 | (binder-init)))))) 509 | 510 | (defun binder-file-relative-to-root (filepath) 511 | "Return FILEPATH relative to `binder-project-directory'." 512 | (file-relative-name (or filepath default-directory) 513 | binder-project-directory)) 514 | 515 | (defun binder-get-item (fileid) 516 | "Return project item association list for FILEID." 517 | (assoc-string fileid (binder-read t))) 518 | 519 | (defun binder-get-item-prop (fileid prop) 520 | "Return value of PROP for project item with FILEID." 521 | (cdr (assq prop (cdr (binder-get-item fileid))))) 522 | 523 | (defun binder-set-item-prop (fileid prop value) 524 | "Set VALUE of PROP for project item with FILEID." 525 | (let ((item (binder-get-item fileid))) 526 | (if (or (null value) (and (stringp value) (string-empty-p value))) 527 | (setf item (assq-delete-all prop item)) 528 | (let ((prop-elt (assq prop item))) 529 | (if prop-elt 530 | (setcdr prop-elt value) 531 | (push (cons prop value) (cdr item))))))) 532 | 533 | (defun binder-add-to-item-prop (fileid prop value) 534 | "Add VALUE to PROP for project item with FILEID." 535 | (let ((prop-elt (binder-get-item-prop fileid prop))) 536 | (unless (member value prop-elt) 537 | (binder-set-item-prop fileid prop (push value prop-elt))))) 538 | 539 | (defun binder-remove-from-item-prop (fileid prop value) 540 | "Remove VALUE from PROP for project item with FILEID." 541 | (let ((prop-elt (binder-get-item-prop fileid prop))) 542 | (when (member value (binder-get-item-prop fileid 'tags)) 543 | (binder-set-item-prop fileid prop (remove value prop-elt))))) 544 | 545 | (defun binder-get-item-index (fileid &optional filter) 546 | "Return index position for project item for FILEID. 547 | With option argument FILTER, return index when items are 548 | filtered." 549 | (seq-position (binder-read filter) (binder-get-item fileid))) 550 | 551 | (defun binder-insert-item (item index) 552 | "Insert project ITEM at position INDEX." 553 | (unless (listp item) (setq item (list item))) 554 | (setq binder--cache 555 | (let ((structure (binder-read))) 556 | (append (seq-take structure index) 557 | (cons item (seq-drop structure index)))))) 558 | 559 | (defun binder-delete-item (fileid) 560 | "Delete project item with FILEID." 561 | (setq binder--cache 562 | (remove (binder-get-item fileid) (binder-read)))) 563 | 564 | (defun binder-get-prop-list (prop) 565 | "Return list of values for PROP." 566 | (delq nil 567 | (mapcar 568 | (lambda (item) 569 | (let ((value (cdr (assq prop item)))) 570 | (when (and (stringp value) (< 0 (string-width value))) 571 | value))) 572 | (binder-read)))) 573 | 574 | (defun binder-get-tags (&optional filter) 575 | "Return current project tags. 576 | Optionally pass FILTER to `binder-read'." 577 | (let (tags) 578 | (mapc 579 | (lambda (item) 580 | (mapc 581 | (lambda (tag) 582 | (push tag tags)) 583 | (cdr (assq 'tags item)))) 584 | (binder-read filter)) 585 | (seq-uniq tags 'string-equal))) 586 | 587 | (defun binder-get-buffer-fileid () 588 | "Return buffer binder fileid." 589 | (cl-case major-mode 590 | (binder-sidebar-mode binder--current-fileid) 591 | (binder-notes-mode binder--notes-fileid) 592 | (t (binder-file-relative-to-root (buffer-file-name))))) 593 | 594 | 595 | ;;; Global Minor Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 596 | 597 | (defun binder-init-project (directory) 598 | "Initialize empty project in DIRECTORY." 599 | (interactive "DInitialize empty project in directory: ") 600 | (binder-cd directory) 601 | (binder-init)) 602 | 603 | (defun binder-save (&optional prompt) 604 | "Save project data (with prompt when PROMPT is non-nil)." 605 | (interactive) 606 | (cond ((= 0 binder--modification-count) 607 | (message "(No changes need to be saved)")) 608 | ((and prompt 609 | (y-or-n-p (format "Save binder project %s? " 610 | (abbreviate-file-name binder-project-directory)))) 611 | (binder-write)) 612 | (t 613 | (binder-write)))) 614 | 615 | (defun binder-exit-hook () 616 | "Ensure project data is saved on exit." 617 | (when binder-mode (binder-save 'prompt))) 618 | 619 | (defun binder-change-directory (directory) 620 | "Change to binder project directory DIRECTORY." 621 | (interactive "DDirectory: ") 622 | (binder-save 'prompt) 623 | (binder-cd directory) 624 | (binder-sidebar-refresh-window) 625 | (binder-notes-refresh-window)) 626 | 627 | (defun binder-next (&optional n) 628 | "Visit Nth next file in binder. 629 | Or visit Nth previous file if N is negative." 630 | (interactive "p") 631 | (when (binder-ensure-in-project) 632 | ;; Find the current file/directory fileid, if one. 633 | (let ((this-fileid (binder-get-buffer-fileid)) 634 | (structure (binder-read t)) 635 | index next-index) 636 | ;; If current file has an INDEX, get the NEXT-INDEX. 637 | (setq index (or (binder-get-item-index this-fileid t) 0) 638 | next-index (+ index n)) 639 | ;; If NEXT-INDEX is within the filtered structure length, find the 640 | ;; Nth next/previous file. 641 | (if (not (<= 0 next-index (1- (length structure)))) 642 | (message "End of binder") 643 | (find-file-existing 644 | (expand-file-name (car (elt structure next-index)) 645 | binder-project-directory)) 646 | (binder-sidebar-refresh-window)) 647 | ;; Setup the overriding keymap. 648 | (unless overriding-terminal-local-map 649 | (let ((prefix-keys (substring (this-single-command-keys) 0 -1)) 650 | (map (cdr binder-navigation-map))) 651 | (when (< 0 (length prefix-keys)) 652 | (mapc (lambda (k) (setq map (assq k map))) prefix-keys) 653 | (setq map (cdr-safe map)) 654 | (when (keymapp map) (set-transient-map map t)))))))) 655 | 656 | (defun binder-previous (&optional n) 657 | "Visit Nth previous file in binder. 658 | Or visit Nth next file if N is negative." 659 | (interactive "p") 660 | (binder-next (- n))) 661 | 662 | (defun binder-add-file (fileid &optional index string) 663 | "Add a (possibly non-existent) FILEID at INDEX containing STRING. 664 | If the current file is in the project, add at index after that 665 | one, otherwise insert at end." 666 | (interactive "FAdd file (extension optional): ") 667 | (binder-ensure-in-project) 668 | (setq fileid (binder-file-relative-to-root fileid)) 669 | (unless (< 0 (string-width fileid)) 670 | (user-error "No file name supplied")) 671 | ;; If FILEID is not a directory and no file extension was provided, 672 | ;; add the binder's default file extensions. 673 | (unless (or (file-directory-p fileid) 674 | (and (string-match "\\.[^.]+\\'" fileid) 675 | (not (= 0 (match-beginning 0))))) 676 | (setq fileid 677 | (concat fileid "." binder-default-file-extension))) 678 | ;; If the file/directory does not exist, create it. 679 | (let ((filepath (expand-file-name fileid binder-project-directory))) 680 | (unless (file-exists-p filepath) 681 | (if (file-directory-p filepath) 682 | (make-directory filepath t) 683 | (with-current-buffer (find-file-noselect filepath) 684 | (when (stringp string) (insert string)) 685 | (write-file filepath)))) 686 | ;; Insert FILEID into binder at INDEX, or after current file. 687 | (unless (binder-get-item fileid) 688 | (unless index 689 | (let ((this-file-index 690 | (binder-get-item-index (binder-get-buffer-fileid) t))) 691 | (setq index (if this-file-index 692 | (1+ this-file-index) 693 | (length (binder-read)))))) 694 | (binder-insert-item fileid index)) 695 | (binder-write-maybe) 696 | ;; When binder sidebar is active, refresh it. 697 | (binder-sidebar-refresh-window) 698 | ;; Finally, visit the file FILEPATH. 699 | (let ((pop-up-windows binder-sidebar-pop-up-windows)) 700 | (find-file filepath)))) 701 | 702 | (defun binder-extract-region-to-new-file (beg end fileid) 703 | "Extract region between BEG and END into new project file FILEID." 704 | (interactive "r\nFNew file name (extension optional): ") 705 | (binder-ensure-in-project) 706 | (let ((string (delete-and-extract-region beg end))) 707 | (binder-add-file fileid nil string))) 708 | 709 | (defvar binder-navigation-map 710 | (let ((map (make-sparse-keymap))) 711 | (define-key map (kbd "C-c ]") #'binder-next) 712 | (define-key map (kbd "C-c [") #'binder-previous) 713 | map) 714 | "Navigational mode map for `binder-mode'.") 715 | 716 | (defvar binder-mode-map 717 | (let ((map (make-sparse-keymap))) 718 | (define-key map (kbd "C-c ;") #'binder-reveal-in-sidebar) 719 | (define-key map (kbd "C-c '") #'binder-toggle-sidebar) 720 | (define-key map (kbd "C-c \"") #'binder-toggle-notes) 721 | (define-key map (kbd "C-c :") #'binder-add-file) 722 | map) 723 | "Main mode map for `binder-mode'.") 724 | 725 | (set-keymap-parent binder-mode-map binder-navigation-map) 726 | 727 | ;;;###autoload 728 | (define-minor-mode binder-mode 729 | "Globally interact with `binder'." 730 | :init-value nil 731 | :lighter binder-mode-lighter 732 | :global t 733 | (if binder-mode 734 | (unless noninteractive 735 | (add-hook 'kill-emacs-hook #'binder-exit-hook) 736 | (add-hook 'window-configuration-change-hook #'binder-highlight-in-sidebar)) 737 | (binder-save 'prompt) 738 | (remove-hook 'window-configuration-change-hook #'binder-highlight-in-sidebar) 739 | (when (window-live-p (get-buffer-window binder-sidebar-buffer t)) 740 | (with-selected-window (get-buffer-window binder-sidebar-buffer t) 741 | (quit-window t))) 742 | (when (window-live-p (get-buffer-window binder-notes-buffer t)) 743 | (with-selected-window (get-buffer-window binder-notes-buffer t) 744 | (quit-window t))) 745 | (setq binder--cache nil))) 746 | 747 | 748 | ;;; Sidebar Major Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 749 | 750 | (defgroup binder-sidebar () 751 | "Options for `binder-sidebar-mode'." 752 | :group 'binder) 753 | 754 | (defface binder-sidebar 755 | '((t nil)) 756 | "Default base-level face for `binder-sidebar-mode' buffers.") 757 | 758 | (defcustom binder-sidebar-buffer "*Binder Sidebar*" 759 | "Default buffer name for binder sidebar." 760 | :type 'string 761 | :safe 'stringp 762 | :group 'binder-sidebar) 763 | 764 | (defcustom binder-sidebar-display-alist 765 | '((side . left) 766 | (window-width . 40) 767 | (slot . -1)) 768 | "Association list used to display binder sidebar buffer. 769 | 770 | See `display-buffer-in-side-window' for example options." 771 | :type 'alist 772 | :safe (lambda (value) 773 | (and (listp value) 774 | (seq-every-p 'consp value))) 775 | :group 'binder-sidebar) 776 | 777 | (defcustom binder-sidebar-hide-file-extensions 778 | nil 779 | "When non-nil, list items without file extension." 780 | :type 'boolean 781 | :safe 'booleanp 782 | :group 'binder-sidebar) 783 | 784 | (defcustom binder-sidebar-hide-tags 785 | nil 786 | "When non-nil, list items without tags." 787 | :type 'boolean 788 | :safe 'booleanp 789 | :group 'binder-sidebar) 790 | 791 | (defcustom binder-sidebar-pop-up-windows 792 | nil 793 | "Non-nil means displaying a new buffer should make a new window." 794 | :type 'boolean 795 | :safe 'booleanp 796 | :group 'binder-sidebar) 797 | 798 | (defcustom binder-sidebar-tags-column 799 | 25 800 | "Integer for column to align tags." 801 | :type 'integer 802 | :safe 'integerp 803 | :group 'binder-sidebar) 804 | 805 | (defcustom binder-sidebar-include-char 806 | ?x 807 | "Character to display on items including in joining." 808 | :type 'character 809 | :safe 'characterp 810 | :group 'binder-sidebar) 811 | 812 | (defcustom binder-sidebar-notes-char 813 | ?* 814 | "Character to display on items with notes." 815 | :type 'character 816 | :safe 'characterp 817 | :group 'binder-sidebar) 818 | 819 | (defcustom binder-sidebar-tags-char 820 | ?# 821 | "Character to prefix to item tags." 822 | :type 'character 823 | :safe 'characterp 824 | :group 'binder-sidebar) 825 | 826 | (defcustom binder-sidebar-missing-char 827 | ?? 828 | "Character to display on items with missing files." 829 | :type 'character 830 | :safe 'characterp 831 | :group 'binder-sidebar) 832 | 833 | (defcustom binder-sidebar-select-window 834 | nil 835 | "If non-nil, switch to sidebar upon displaying it." 836 | :type 'boolean 837 | :safe 'booleanp 838 | :group 'binder-sidebar) 839 | 840 | (defcustom binder-sidebar-persistent-window 841 | t 842 | "When non-nil, sidebar will persist when calling `delete-other-windows'. 843 | 844 | This marks `no-delete-other-windows' window parameter as non-nil. 845 | 846 | Use `binder-toggle-sidebar' or `quit-window' to close the sidebar." 847 | :type 'boolean 848 | :safe 'booleanp 849 | :group 'binder-sidebar) 850 | 851 | (defcustom binder-sidebar-resize-window-step 852 | 4 853 | "Integer of columns by which to resize window. 854 | Used by `binder-sidebar-shrink-window' and `binder-sidebar-enlarge-window'." 855 | :type 'integer 856 | :safe 'integerp 857 | :group 'binder-sidebar) 858 | 859 | (defun binder-sidebar-refresh () 860 | "Redraw binder sidebar, reading from cache." 861 | (interactive) 862 | (with-silent-modifications 863 | (setq default-directory binder-project-directory) 864 | (setq header-line-format (abbreviate-file-name binder-project-directory)) 865 | (let ((x (point))) 866 | (erase-buffer) 867 | (mapc 868 | (lambda (item) 869 | (let ((fileid (car item)) 870 | (display (cdr (assq 'display item))) 871 | (notes (cdr (assq 'notes item))) 872 | (tags (cdr (assq 'tags item))) 873 | marked missing tags-overwrite) 874 | ;; Set whether FILEID is MARKED and MISSING. 875 | (when (member fileid binder--sidebar-marked) (setq marked t)) 876 | (when (not (file-exists-p fileid)) (setq missing t)) 877 | ;; Insert the item line elements. 878 | (insert (if marked ">" " ") 879 | (cond (missing binder-sidebar-missing-char) 880 | ((and notes (not (string-empty-p notes))) 881 | binder-sidebar-notes-char) 882 | (t " ")) 883 | " ") 884 | ;; Use either DISPLAY, or if directory ensure a trailing slash, and 885 | ;; finally if we're hiding file extensions, do that, otherwise just 886 | ;; the FILEID is fine. 887 | (insert-text-button 888 | (or display (if (file-directory-p fileid) 889 | (replace-regexp-in-string "/*$" "/" fileid) 890 | (if binder-sidebar-hide-file-extensions 891 | (replace-regexp-in-string ".+\\(\\..+\\)" "" 892 | fileid nil nil 1) 893 | fileid))) 894 | 'binder-fileid fileid 895 | 'face 'button 896 | 'action #'binder-sidebar-button-action 897 | 'help-echo "mouse-1, RET: visit this file" 898 | 'follow-link t) 899 | ;; Add the face properties. Make them front-sticky since we 900 | ;; were previously editing the buffer text (but not anymore). 901 | (put-text-property (line-beginning-position) (line-end-position) 902 | 'binder-fileid fileid) 903 | (put-text-property (line-beginning-position) (line-end-position) 904 | 'front-sticky '(binder-fileid)) 905 | (when missing 906 | (add-face-text-property (line-beginning-position) (line-end-position) 907 | 'binder-sidebar-missing)) 908 | (when marked 909 | (add-face-text-property (line-beginning-position) (line-end-position) 910 | 'binder-sidebar-marked)) 911 | ;; Add the item TAGS with a hashtag, because hashtags are cool, right? 912 | (when (and (not binder-sidebar-hide-tags) tags) 913 | (move-to-column (1- binder-sidebar-tags-column)) 914 | (unless (eolp) (setq tags-overwrite t)) 915 | (move-to-column binder-sidebar-tags-column) 916 | (indent-to-column binder-sidebar-tags-column) 917 | (let ((tags-col (point)) 918 | (tags-char (char-to-string binder-sidebar-tags-char))) 919 | (delete-region (1- tags-col) (line-end-position)) 920 | (insert (if tags-overwrite "~" " ") 921 | tags-char 922 | (string-join tags (concat " " tags-char))) 923 | (add-face-text-property tags-col (line-end-position) 924 | 'binder-sidebar-tags))) 925 | (insert "\n") 926 | (when (string= fileid binder--current-fileid) 927 | (add-face-text-property (line-beginning-position 0) 928 | (line-beginning-position) 929 | 'binder-sidebar-highlight)))) 930 | (binder-read t)) 931 | (goto-char x)))) 932 | 933 | (defun binder-sidebar-button-ensure () 934 | "Ensure point is at button." 935 | (or (button-at (point)) 936 | (and (eolp) (forward-button -1 nil nil t)) 937 | (forward-button 1 nil nil t))) 938 | 939 | (defun binder-sidebar-button-action (button &optional pop-up-window) 940 | (interactive) 941 | (let ((pop-up-windows (or pop-up-window binder-sidebar-pop-up-windows)) 942 | (fileid (button-get button 'binder-fileid)) 943 | filepath) 944 | (setq filepath (expand-file-name fileid)) 945 | (when (file-exists-p filepath) 946 | (setq binder--current-fileid fileid) 947 | (binder-sidebar-refresh) 948 | (find-file filepath)))) 949 | 950 | (defun binder-sidebar-refresh-window () 951 | "Call `binder-sidebar-refresh' if sidebar window is live." 952 | (when (window-live-p (get-buffer-window binder-sidebar-buffer)) 953 | (with-current-buffer binder-sidebar-buffer 954 | (binder-sidebar-refresh)))) 955 | 956 | (defalias 'binder-sidebar-change-directory #'binder-change-directory) 957 | 958 | (defun binder-sidebar-create-buffer () 959 | "Return binder sidebar buffer for DIRECTORY." 960 | (binder-ensure-in-project) 961 | (with-current-buffer (get-buffer-create binder-sidebar-buffer) 962 | (binder-sidebar-mode) 963 | (binder-sidebar-refresh) 964 | (current-buffer))) 965 | 966 | (defun binder-sidebar-create-window () 967 | "Return binder sidebar window for DIRECTORY. 968 | Defaults to current directory." 969 | (let ((display-buffer-mark-dedicated t)) 970 | (display-buffer-in-side-window 971 | (binder-sidebar-create-buffer) 972 | (append binder-sidebar-display-alist 973 | (when binder-sidebar-persistent-window 974 | (list '(window-parameters (no-delete-other-windows . t)))))))) 975 | 976 | (defun binder-sidebar-get-fileid () 977 | "Return fileid for item at point." 978 | (save-excursion 979 | (if (eobp) (forward-line -1) (beginning-of-line)) 980 | (get-text-property (point) 'binder-fileid))) 981 | 982 | (defun binder-sidebar-goto-item (fileid) 983 | "Move point to project item with FILEID." 984 | (goto-char (point-min)) 985 | ;; It would be nice to use find-next-text-property but that isn't 986 | ;; available until Emacs 27. 987 | (let (found) 988 | (while (not (or (eobp) found)) 989 | (if (string= (binder-sidebar-get-fileid) fileid) 990 | (setq found t) 991 | (forward-line 1))))) 992 | 993 | (defun binder-sidebar-find-file (arg) 994 | "Visit project file at point. 995 | When ARG is non-nil, visit in new window." 996 | (interactive "P") 997 | (when (binder-sidebar-button-ensure) 998 | (binder-sidebar-button-action (button-at (point)) arg))) 999 | 1000 | (defun binder-sidebar-find-file-other-window () 1001 | "Visit project file at point in other window." 1002 | (interactive) 1003 | (binder-sidebar-find-file t)) 1004 | 1005 | ;; FIXME: FEATURE - `binder-sidebar-search' to search for strings within 1006 | ;; project. Could be implemented simply as a dynamic command passed to `lgrep'. 1007 | 1008 | (defalias 'binder-sidebar-save #'binder-save) 1009 | 1010 | (defun binder-sidebar-get-index () 1011 | "Return binder index position at point." 1012 | (if (eobp) 1013 | (1- (length (binder-read))) 1014 | (binder-get-item-index (binder-sidebar-get-fileid) t))) 1015 | 1016 | (defun binder-sidebar-mark () 1017 | "Mark the project item at point." 1018 | (interactive) 1019 | (cl-pushnew (binder-sidebar-get-fileid) binder--sidebar-marked) 1020 | (forward-line 1) 1021 | (binder-sidebar-refresh)) 1022 | 1023 | (defun binder-sidebar-unmark () 1024 | "Unmark the project item at point." 1025 | (interactive) 1026 | (setq binder--sidebar-marked 1027 | (remove (binder-sidebar-get-fileid) binder--sidebar-marked)) 1028 | (forward-line 1) 1029 | (binder-sidebar-refresh)) 1030 | 1031 | (defun binder-sidebar-unmark-all () 1032 | "Unmark all project items." 1033 | (interactive) 1034 | (setq binder--sidebar-marked nil) 1035 | (binder-sidebar-refresh)) 1036 | 1037 | (defun binder-sidebar-add-file (fileid) 1038 | "Add (possibly non-existent) file to binder as FILEID." 1039 | (interactive "FAdd file: ") 1040 | (setq fileid (binder-file-relative-to-root fileid)) 1041 | (unless (binder-get-item fileid) 1042 | (binder-insert-item fileid (1+ (binder-sidebar-get-index)))) 1043 | (binder-write-maybe) 1044 | (binder-sidebar-refresh) 1045 | (binder-sidebar-goto-item fileid)) 1046 | 1047 | (defun binder-sidebar-add-all-files () 1048 | "Add all files in current directory to binder." 1049 | (interactive) 1050 | (when (y-or-n-p (format "Add all files in %s? " 1051 | (abbreviate-file-name default-directory))) 1052 | (dolist (file (directory-files default-directory nil "^[^.]")) 1053 | (binder-sidebar-add-file file)))) 1054 | 1055 | (defun binder-sidebar-new-file (fileid) 1056 | "Add a new file to binder as FILEID and visit it." 1057 | (interactive "FAdd file (extension optional): ") 1058 | (unless (eq major-mode 'binder-sidebar-mode) 1059 | (user-error "Not in %S" 'binder-sidebar-mode)) 1060 | (binder-add-file fileid (1+ (binder-sidebar-get-index))) 1061 | (binder-sidebar-goto-item fileid)) 1062 | 1063 | (defun binder-sidebar-remove (arg) 1064 | "Remove marked items or item at point. 1065 | When ARG is non-nil, do not prompt for confirmation." 1066 | (interactive "P") 1067 | (let ((fileid-list (or binder--sidebar-marked 1068 | (list (binder-sidebar-get-fileid))))) 1069 | (when (or arg (y-or-n-p (format "Really remove %s? " 1070 | (string-join fileid-list ", ")))) 1071 | (mapc #'binder-delete-item fileid-list) 1072 | (setq binder--sidebar-marked nil))) 1073 | (binder-write) 1074 | (binder-sidebar-refresh)) 1075 | 1076 | (defun binder-sidebar-rename () 1077 | "Change display name of project item at point." 1078 | (interactive) 1079 | (let ((fileid (binder-sidebar-get-fileid)) 1080 | name) 1081 | (setq name 1082 | (read-string "New name: " 1083 | (or (binder-get-item-prop fileid 'display) fileid))) 1084 | (binder-set-item-prop fileid 'display name) 1085 | (binder-write-maybe) 1086 | (binder-sidebar-refresh))) 1087 | 1088 | (defun binder-sidebar-relocate (filepath) 1089 | "Change file path of project item at point to FILEPATH." 1090 | (interactive 1091 | (list (read-file-name 1092 | (format "New file path [%s]: " (binder-sidebar-get-fileid)) 1093 | nil nil t))) 1094 | (setq filepath (binder-file-relative-to-root filepath)) 1095 | (setcar (binder-get-item (binder-sidebar-get-fileid)) filepath) 1096 | (binder-write-maybe) 1097 | (binder-sidebar-refresh)) 1098 | 1099 | (defun binder-sidebar-add-tag (tag) 1100 | "Add TAG to marked items or item at point." 1101 | (interactive 1102 | (list (completing-read 1103 | "Add tag: " (binder-get-tags)))) 1104 | (mapc 1105 | (lambda (fileid) 1106 | (binder-add-to-item-prop fileid 'tags tag)) 1107 | (or binder--sidebar-marked 1108 | (list (binder-sidebar-get-fileid)))) 1109 | (setq binder--sidebar-marked nil) 1110 | (binder-write-maybe) 1111 | (binder-sidebar-refresh)) 1112 | 1113 | (defun binder-sidebar-remove-tag (tag) 1114 | "Remove TAG to marked items or item at point." 1115 | (interactive 1116 | (list (completing-read 1117 | "Remove tag: " 1118 | (binder-get-item-prop (binder-sidebar-get-fileid) 'tags)))) 1119 | (mapc 1120 | (lambda (fileid) 1121 | (binder-remove-from-item-prop fileid 'tags tag)) 1122 | (or binder--sidebar-marked 1123 | (list (binder-sidebar-get-fileid)))) 1124 | (setq binder--sidebar-marked nil) 1125 | (binder-write-maybe) 1126 | (binder-sidebar-refresh)) 1127 | 1128 | (defun binder-sidebar-toggle-file-extensions () 1129 | "Toggle visibility of item file extensions." 1130 | (interactive) 1131 | (customize-set-variable 'binder-sidebar-hide-file-extensions 1132 | (not binder-sidebar-hide-file-extensions)) 1133 | (let ((fileid (binder-sidebar-get-fileid))) 1134 | (binder-sidebar-refresh) 1135 | (binder-sidebar-goto-item fileid)) 1136 | (message "%s file extensions" 1137 | (capitalize 1138 | (if binder-sidebar-hide-file-extensions 1139 | "hiding" "showing")))) 1140 | 1141 | (defun binder-sidebar-toggle-tags () 1142 | "Toggle visibility of tags." 1143 | (interactive) 1144 | (customize-set-variable 'binder-sidebar-hide-tags 1145 | (not binder-sidebar-hide-tags)) 1146 | (let ((fileid (binder-sidebar-get-fileid))) 1147 | (binder-sidebar-refresh) 1148 | (binder-sidebar-goto-item fileid)) 1149 | (message "%s tags" 1150 | (capitalize 1151 | (if binder-sidebar-hide-tags 1152 | "hiding" "showing")))) 1153 | 1154 | (defun binder-sidebar-shift-down (&optional n) 1155 | "Shift index position of item at point down N places in list." 1156 | (interactive "p") 1157 | (let ((p (if (<= n 0) -1 1)) 1158 | (fileid (binder-sidebar-get-fileid)) 1159 | item fake-index next-index) 1160 | (setq item (binder-get-item fileid) 1161 | fake-index (binder-get-item-index fileid t) 1162 | next-index (seq-position (binder-read) 1163 | (elt (binder-read t) (+ fake-index p)))) 1164 | (when (<= 0 (+ fake-index p) 1165 | (1- (length (binder-read t)))) 1166 | (binder-delete-item fileid) 1167 | (binder-insert-item item next-index) 1168 | (binder-write-maybe) 1169 | (binder-sidebar-refresh) 1170 | (binder-sidebar-goto-item fileid)))) 1171 | 1172 | (defun binder-sidebar-shift-up (&optional n) 1173 | "Shift index position of item at point up N places in list." 1174 | (interactive "p") 1175 | (binder-sidebar-shift-down (- n))) 1176 | 1177 | (defun binder-sidebar-jump-to-current () 1178 | "Jump to current file in sidebar." 1179 | (interactive) 1180 | (binder-sidebar-goto-item binder--current-fileid)) 1181 | 1182 | (defun binder-sidebar-narrow-by-tag (tag) 1183 | "\\Filter sidebar items to include items with TAG. 1184 | To reset filtering call `binder-sidebar-refresh' (\\[binder-sidebar-refresh])." 1185 | (interactive 1186 | (list (completing-read 1187 | "Narrow items by tag: " (binder-get-tags) 1188 | nil t))) 1189 | (unless (or (string-empty-p tag) (member tag binder-narrow-tags)) 1190 | (push tag binder-narrow-tags) 1191 | (binder-sidebar-refresh))) 1192 | 1193 | (defun binder-sidebar-exclude-by-tag (tag) 1194 | "\\Filter sidebar items to exclude items with TAG. 1195 | To reset filtering call `binder-sidebar-refresh' (\\[binder-sidebar-refresh])." 1196 | (interactive 1197 | (list (completing-read 1198 | "Exclude items by tag: " (binder-get-tags) 1199 | nil t))) 1200 | (unless (or (string-empty-p tag) (member tag binder-exclude-tags)) 1201 | (push tag binder-exclude-tags) 1202 | (binder-sidebar-refresh))) 1203 | 1204 | (defun binder-sidebar-clear-filters () 1205 | "Clear all sidebar tag filters." 1206 | (interactive) 1207 | (setq binder-narrow-tags nil 1208 | binder-exclude-tags nil) 1209 | (binder-sidebar-refresh) 1210 | (message "Sidebar filters cleared")) 1211 | 1212 | (defun binder-sidebar-copy-filepath () 1213 | "Put the current item filepath into the kill ring." 1214 | (interactive) 1215 | (let ((fileid (binder-sidebar-get-fileid))) 1216 | (kill-new fileid) 1217 | (message "%S" fileid))) 1218 | 1219 | (defun binder-highlight-in-sidebar () 1220 | "Highlight the current file in sidebar. 1221 | 1222 | Added to `window-configuration-change-hook'." 1223 | (unless (or (minibuffer-window-active-p (selected-window)) 1224 | (eq major-mode 'binder-sidebar-mode)) 1225 | (setq binder--current-fileid (binder-get-buffer-fileid)) 1226 | (binder-sidebar-refresh-window))) 1227 | 1228 | (defun binder-sidebar-shrink-window () 1229 | "Shrink the sidebar window horizontally. 1230 | 1231 | Calls `shrink-window-horizontally' with `binder-sidebar-resize-window-step'." 1232 | (interactive) 1233 | (shrink-window-horizontally binder-sidebar-resize-window-step)) 1234 | 1235 | (defun binder-sidebar-enlarge-window () 1236 | "Enlarge the sidebar window horizontally. 1237 | 1238 | Calls `enlarge-window-horizontally' with `binder-sidebar-resize-window-step'." 1239 | (interactive) 1240 | (enlarge-window-horizontally binder-sidebar-resize-window-step)) 1241 | 1242 | (defun binder-sidebar-help (char) 1243 | "Provide interactive help prompt by CHAR." 1244 | (declare (interactive-only t)) 1245 | (interactive 1246 | (list (read-char-choice "\ 1247 | ? = describe-mode, \ 1248 | g = refresh, \ 1249 | | = clear filters, \ 1250 | q = quit-window, \ 1251 | C-g = cancel: " '(?? ?g ?| ?q)))) 1252 | (cl-case char 1253 | (?q (quit-window)) 1254 | (?g (binder-sidebar-refresh)) 1255 | (?| (binder-sidebar-clear-filters)) 1256 | (?? (describe-mode)))) 1257 | 1258 | (defun binder-reveal-in-sidebar () 1259 | "Reveal current file in binder sidebar." 1260 | (interactive) 1261 | (let ((filepath (or (buffer-file-name) default-directory))) 1262 | (select-window (binder-sidebar-create-window)) 1263 | (if (file-equal-p filepath (binder-root)) 1264 | (binder-sidebar-refresh) 1265 | (let ((fileid (binder-file-relative-to-root filepath))) 1266 | (setq binder--current-fileid fileid) 1267 | (unless (binder-get-item fileid) 1268 | (when (y-or-n-p (format "Add %s to binder? " fileid)) 1269 | (binder-sidebar-add-file fileid))) 1270 | (binder-sidebar-refresh) 1271 | (binder-sidebar-goto-item fileid))))) 1272 | 1273 | ;;;###autoload 1274 | (defun binder-toggle-sidebar () 1275 | "Toggle visibility of project sidebar window. 1276 | 1277 | Unconditionally activates `binder-mode'." 1278 | (interactive) 1279 | (binder-mode) 1280 | (if (window-live-p (get-buffer-window binder-sidebar-buffer)) 1281 | (delete-window (get-buffer-window binder-sidebar-buffer)) 1282 | (binder-sidebar-create-window) 1283 | (when binder-sidebar-select-window 1284 | (select-window (get-buffer-window binder-sidebar-buffer))))) 1285 | 1286 | (defvar binder-sidebar-mode-map 1287 | (let ((map (make-sparse-keymap))) 1288 | (define-key map (kbd "?") #'binder-sidebar-help) 1289 | (define-key map (kbd "TAB") #'forward-button) 1290 | (define-key map (kbd "") #'backward-button) 1291 | (define-key map (kbd "{") #'binder-sidebar-shrink-window) 1292 | (define-key map (kbd "}") #'binder-sidebar-enlarge-window) 1293 | (define-key map (kbd "g") #'binder-sidebar-refresh) 1294 | (define-key map (kbd "|") #'binder-sidebar-clear-filters) 1295 | (define-key map (kbd "j") #'binder-sidebar-jump-to-current) 1296 | (define-key map (kbd "C") #'binder-sidebar-change-directory) 1297 | (define-key map (kbd "n") #'next-line) 1298 | (define-key map (kbd "p") #'previous-line) 1299 | (define-key map (kbd "RET") #'binder-sidebar-find-file) 1300 | (define-key map (kbd "o") #'binder-sidebar-find-file-other-window) 1301 | (define-key map (kbd "s") #'binder-sidebar-save) 1302 | (define-key map [remap save-buffer] #'binder-sidebar-save) 1303 | (define-key map (kbd "m") #'binder-sidebar-mark) 1304 | (define-key map (kbd "u") #'binder-sidebar-unmark) 1305 | (define-key map (kbd "t") #'binder-sidebar-add-tag) 1306 | (define-key map (kbd "T") #'binder-sidebar-remove-tag) 1307 | (define-key map (kbd "#") #'binder-sidebar-toggle-tags) 1308 | (define-key map (kbd "U") #'binder-sidebar-unmark-all) 1309 | (define-key map (kbd "i") #'binder-sidebar-toggle-notes) 1310 | (define-key map (kbd "z") #'binder-sidebar-open-notes) 1311 | (define-key map (kbd "c") #'binder-sidebar-copy-filepath) 1312 | (define-key map (kbd "M-n") #'binder-sidebar-shift-down) 1313 | (define-key map (kbd "") #'binder-sidebar-shift-down) 1314 | (define-key map (kbd "M-p") #'binder-sidebar-shift-up) 1315 | (define-key map (kbd "") #'binder-sidebar-shift-up) 1316 | (define-key map (kbd "a") #'binder-sidebar-add-file) 1317 | (define-key map (kbd "A") #'binder-sidebar-add-all-files) 1318 | (define-key map (kbd "d") #'binder-sidebar-remove) 1319 | (define-key map (kbd "r") #'binder-sidebar-rename) 1320 | (define-key map (kbd "R") #'binder-sidebar-relocate) 1321 | (define-key map (kbd "E") #'binder-sidebar-toggle-file-extensions) 1322 | (define-key map (kbd "/") #'binder-sidebar-narrow-by-tag) 1323 | (define-key map (kbd "\\") #'binder-sidebar-exclude-by-tag) 1324 | (define-key map (kbd "M-RET") #'binder-sidebar-new-file) 1325 | map)) 1326 | 1327 | (define-derived-mode binder-sidebar-mode 1328 | special-mode "Binder Sidebar" 1329 | "Major mode for working with `binder' projects." 1330 | (setq indent-tabs-mode nil) 1331 | (face-remap-add-relative 'default 'binder-sidebar) 1332 | (add-hook 'post-command-hook #'binder-sidebar-sync-notes t t)) 1333 | 1334 | 1335 | ;;; Notes Major Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1336 | 1337 | (defface binder-notes 1338 | '((t nil)) 1339 | "Default base-level face for `binder-notes-mode' buffers.") 1340 | 1341 | (defcustom binder-notes-buffer 1342 | "*Binder Notes*" 1343 | "Buffer name for Binder notes." 1344 | :type 'string 1345 | :safe 'stringp 1346 | :group 'binder-sidebar) 1347 | 1348 | (defcustom binder-notes-display-alist 1349 | '((side . left) 1350 | (window-width . 40) 1351 | (slot . 1)) 1352 | "Association list used to display binder notes buffer. 1353 | 1354 | See `display-buffer-in-side-window' for example options." 1355 | :type 'alist 1356 | :group 'binder-sidebar) 1357 | 1358 | (defcustom binder-notes-persistent-window 1359 | t 1360 | "When non-nil, notes will persist when calling `delete-other-windows'. 1361 | 1362 | This marks `no-delete-other-windows' window parameter as non-nil. 1363 | 1364 | Use `binder-toggle-notes' or `quit-window' to close notes." 1365 | :type 'boolean 1366 | :safe 'booleanp 1367 | :group 'binder-sidebar) 1368 | 1369 | (defcustom binder-notes-keep-in-sync 1370 | nil 1371 | "If non-nil, moving point in binder sidebar updates notes. 1372 | 1373 | Enabling this can be disconcerting, because notes are not 1374 | automatically saved." 1375 | :type 'boolean 1376 | :safe 'booleanp 1377 | :group 'binder-sidebar) 1378 | 1379 | (defcustom binder-notes-mode-hook 1380 | '(visual-line-mode) 1381 | "Hook run after entering Binder Notes Mode." 1382 | :type 'hook 1383 | :options '(visual-line-mode)) 1384 | 1385 | (defun binder-notes-refresh () 1386 | "Redraw the notes buffer." 1387 | (setq default-directory binder-project-directory) 1388 | (with-silent-modifications 1389 | (erase-buffer) 1390 | (insert (or (binder-get-item-prop binder--notes-fileid 'notes) 1391 | "")) 1392 | (setq binder--notes-display 1393 | (binder-get-item-prop binder--notes-fileid 'display)) 1394 | (setq header-line-format 1395 | (if binder--notes-fileid 1396 | (list (list :propertize (or binder--notes-display binder--notes-fileid) 1397 | 'face 'bold) 1398 | " C-c C-c to commit; C-c C-q to quit") 1399 | "Nothing selected; C-c C-q to quit")))) 1400 | 1401 | (defun binder-notes-refresh-window () 1402 | "Call `binder-notes-refresh' if notes window is live." 1403 | (when (window-live-p (get-buffer-window binder-notes-buffer)) 1404 | (with-current-buffer binder-notes-buffer 1405 | (binder-notes-refresh)))) 1406 | 1407 | (defun binder-notes-create-buffer () 1408 | "Create the notes buffer." 1409 | (binder-ensure-in-project) 1410 | (with-current-buffer (get-buffer-create binder-notes-buffer) 1411 | (binder-notes-mode) 1412 | (binder-notes-refresh) 1413 | (current-buffer))) 1414 | 1415 | (defun binder-notes-create-window () 1416 | "Create the notes window." 1417 | (let ((display-buffer-mark-dedicated t)) 1418 | (display-buffer-in-side-window 1419 | (binder-notes-create-buffer) 1420 | (append binder-notes-display-alist 1421 | (when binder-sidebar-persistent-window 1422 | (list '(window-parameters (no-delete-other-windows . t)))))))) 1423 | 1424 | (defun binder-show-notes (&optional fileid select) 1425 | "Show the notes for FILEID of the appropriate project item. 1426 | If argument SELECT is non-nil, select the notes window." 1427 | (binder-ensure-in-project) 1428 | (if fileid 1429 | (setq binder--notes-fileid fileid) 1430 | (let ((filepath (or (buffer-file-name) default-directory))) 1431 | (unless (file-equal-p filepath (binder-root)) 1432 | (setq binder--notes-fileid (binder-file-relative-to-root filepath))))) 1433 | (if (window-live-p (get-buffer-window binder-notes-buffer)) 1434 | (binder-notes-refresh-window) 1435 | (binder-notes-create-window)) 1436 | (when select (select-window (get-buffer-window binder-notes-buffer)))) 1437 | 1438 | (defun binder-sidebar-open-notes () 1439 | "Open notes for item at point and select the notes window." 1440 | (interactive) 1441 | (binder-show-notes (binder-sidebar-get-fileid) t)) 1442 | 1443 | (defun binder-toggle-notes () 1444 | "Toggle visibility of binder notes window." 1445 | (interactive) 1446 | (if (window-live-p (get-buffer-window binder-notes-buffer)) 1447 | (delete-window (get-buffer-window binder-notes-buffer)) 1448 | (binder-show-notes))) 1449 | 1450 | (defun binder-sidebar-toggle-notes () 1451 | "Toggle visibility of binder notes window for item at point." 1452 | (interactive) 1453 | (if (window-live-p (get-buffer-window binder-notes-buffer)) 1454 | (delete-window (get-buffer-window binder-notes-buffer)) 1455 | (binder-show-notes (binder-sidebar-get-fileid)))) 1456 | 1457 | (defun binder-notes-save () 1458 | "Save notes buffer content to project. 1459 | 1460 | This command writes project data to disk." 1461 | (interactive) 1462 | (unless (derived-mode-p 'binder-notes-mode) 1463 | (user-error "Not in %S" 'binder-notes-mode)) 1464 | (if (not (buffer-modified-p)) 1465 | (message "(No changes need to be added to binder)") 1466 | (binder-set-item-prop binder--notes-fileid 'notes 1467 | (string-trim (buffer-substring-no-properties 1468 | (point-min) (point-max)))) 1469 | (set-buffer-modified-p nil) 1470 | (binder-write) 1471 | (binder-sidebar-refresh-window) 1472 | (message "Saved notes for %s to binder" 1473 | (or binder--notes-display binder--notes-fileid)))) 1474 | 1475 | (defun binder-notes-save-and-quit-window () 1476 | "Call `binder-notes-save' and quit the notes window." 1477 | (declare (interactive-only t)) 1478 | (interactive) 1479 | (binder-notes-save) 1480 | (quit-window)) 1481 | 1482 | (defun binder-notes-expand-window () 1483 | "Toggle the notes window from a side window to full window." 1484 | (declare (interactive-only t)) 1485 | (interactive) 1486 | (unless (derived-mode-p 'binder-notes-mode) 1487 | (user-error "Not in %S" 'binder-notes-mode)) 1488 | (if (window-parameter (selected-window) 'window-side) 1489 | (progn 1490 | (quit-window) 1491 | (pop-to-buffer (get-buffer-create binder-notes-buffer))) 1492 | (quit-window) 1493 | (binder-show-notes binder--notes-fileid t))) 1494 | 1495 | (defun binder-sidebar-sync-notes () 1496 | "Set the current notes to sidebar item at point." 1497 | (while-no-input 1498 | (redisplay) 1499 | (when binder-notes-keep-in-sync 1500 | (setq binder--notes-fileid (binder-sidebar-get-fileid)) 1501 | (binder-notes-refresh-window)))) 1502 | 1503 | (defvar binder-notes-mode-map 1504 | (let ((map (make-sparse-keymap))) 1505 | (define-key map (kbd "C-c C-c") #'binder-notes-save-and-quit-window) 1506 | (define-key map [remap save-buffer] #'binder-notes-save) 1507 | (define-key map (kbd "C-c C-l") #'binder-notes-expand-window) 1508 | (define-key map (kbd "C-c C-q") #'quit-window) 1509 | (define-key map (kbd "C-c C-k") #'quit-window) 1510 | map) 1511 | "Mode map for `binder-notes-mode'.") 1512 | 1513 | (define-derived-mode binder-notes-mode 1514 | text-mode "Binder Notes Mode" 1515 | "Major mode for editing `binder' notes." 1516 | (face-remap-add-relative 'default 'binder-notes) 1517 | (binder-notes-refresh)) 1518 | 1519 | 1520 | 1521 | (provide 'binder) 1522 | ;;; binder.el ends here 1523 | 1524 | ;; Local Variables: 1525 | ;; coding: utf-8 1526 | ;; fill-column: 80 1527 | ;; indent-tabs-mode: nil 1528 | ;; require-final-newline: t 1529 | ;; sentence-end-double-space: nil 1530 | ;; End: 1531 | -------------------------------------------------------------------------------- /contrib/binder-theme.el: -------------------------------------------------------------------------------- 1 | ;; To install this theme, copy or symlink it to your `user-emacs-directory'. 2 | 3 | (deftheme binder 4 | "Binder theme, inspired by Scrivener.") 5 | 6 | (custom-theme-set-faces 7 | 'binder 8 | '(binder-sidebar 9 | ((default (:height 0.9)) 10 | (((background light)) (:background "#f1f0f6")) 11 | (((background dark)) (:background "#33323f")))) 12 | '(binder-notes 13 | ((default (:height 0.9)) 14 | (((background light)) (:background "#fefbe8")) 15 | (((background dark)) (:background "#302c2c"))))) 16 | 17 | (provide-theme 'binder) 18 | -------------------------------------------------------------------------------- /screenshots/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rnkn/binder/5c668cba1dc768aa25e5b2a2b446a2ad4babf8bb/screenshots/01.png --------------------------------------------------------------------------------