Repository: nobiot/org-remark Branch: main Commit: 4389853625f5 Files: 28 Total size: 280.8 KB Directory structure: gitextract_gk7ypw4z/ ├── .dir-locals.el ├── .elpaignore ├── .github/ │ └── workflows/ │ └── gh-docs.yml ├── .gitignore ├── CHANGELOG ├── LICENSE ├── Makefile ├── NEWS ├── README-elpa ├── README.org ├── docs/ │ ├── .nojekyll │ ├── Makefile │ ├── articles/ │ │ ├── 2023-08-20T183400_how-to-buffer-window.org │ │ └── 2023-08-20T184309_C_how-to-set-icons-to-be-svg-images.md │ ├── fdl.texi │ ├── marginalia.org │ ├── org-remark.org │ └── resources/ │ ├── manual.css │ ├── reset.css │ └── style.css ├── org-remark-convert-legacy.el ├── org-remark-eww.el ├── org-remark-global-tracking.el ├── org-remark-icon.el ├── org-remark-info.el ├── org-remark-line.el ├── org-remark-nov.el └── org-remark.el ================================================ FILE CONTENTS ================================================ ================================================ FILE: .dir-locals.el ================================================ ((nil (time-stamp-format . "%02d %:B %Y") (time-stamp-start . "modified:[ ]+\\\\?") (time-stamp-end . "$") ;; "Last modified in source code files are at line 20" (time-stamp-line-limit . 20) ;; Need this locale to be "C" or "en_US.UTF-8" or something to standardize the ;; time stamp with English (system-time-locale . "C")) (fill-column . 80) (indent-tabs-mode . nil)) ================================================ FILE: .elpaignore ================================================ demo test test* docs resources Makefile .gitignore .elpaignore .github .dir-locals.el ================================================ FILE: .github/workflows/gh-docs.yml ================================================ name: GH-Page AutoGen on: push: branches: [ main ] pull_request: branches: [ main ] jobs: build-and-deploy: runs-on: ubuntu-latest continue-on-error: false steps: - uses: actions/checkout@v2 - uses: purcell/setup-emacs@master with: version: '27.2' - name: Install dependencies run: sudo apt-get install texinfo - name: Run docs/make gh-html run: | cd docs make gh-html - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@4.1.7 with: branch: gh-pages # The branch the action should deploy to. folder: docs # The folder the action should deploy. ================================================ FILE: .gitignore ================================================ */#marginalia.org# *.bak *.log *.elc test test* # ELPA-generated files. /org-remark-autoloads.el /org-remark-pkg.el ================================================ FILE: CHANGELOG ================================================ [More recent changes v1.0.0 are in NEWS file] Version 0.2.0 - add: org-remark-delete - rm: Adding Org-ID automatically to file level when file is empty Version 0.1.0 * Features & additions - docs: comprehensive user manual (online - Info to be added on ELPA release) - feat: org-remark-create macro to let users create their own custom pens - feat: minor-mode menu for menu-bar-mode This works as mouse context-menu for the new context-menu-mode (>= Emacs 28) - add: browse-next/prev: move and display next/prev marginal notes at the same time - add: view/open to display side-window by default (user option) - add: org-remark-link property in marginal notes file with ::line-number search option - feat: org-remark-legacy-convert as a separate feature This is for automatically converting legacy Org-marginalia file to Org-remark. - feat: Legacy data facility with org-remark-tracking * Changes - chg: `remove' (and delete) only removes one highlight at a time instead of remove all at point - chg: Save marginal notes on `mark' instead of wainting for `save' - chg: define org-remark-mark explicitly for autoload cookie - chg: `org-remark-view' and `org-remark-open'. View will stay in the current main note; open will move the cursor to the marginal notes buffer for further editing. - chg: When updating the existing headline and position properties, don't update the headline text when it already exists. Let the user decide how to manage headlines. - doc: copyright assignment to FSF; copyright years * Alpha ** 0.0.6 Feature: - feat: Add =org-marginalia-global-tracking-mode= with a separate .el file - feat: Use Org-ID to create a link from the marginal notes back to the main file Add Customizable variable =org-marginalia-use-org-id=; default is =t= Change: - chg: Highlights are now overlay; no longer text-properties Improvement to existing functions - add: Deactivate mark after highlighting - add: org-marginalia-remove can take C-u to delete Fix & Internal Refactor - intrnl: Add housekeeping for =org-marginalia-highlights= variable - fix: org-id-uuid is not found - fix: Add highlighter face def for terminal ** 0.0.5 - break: Replace the prefix "om/" in the source code with "org-marginalia" - break: Remove default keybindings; add examples in readme instead. Addresses [#3](https://github.com/nobiot/org-marginalia/issues/3) ** 0.0.4 - feat: Add transient navigation to next/prev See [[*Credits][§ Credits]] for the piece of code to achieve the transient map I used. ** 0.0.3 - feat: Add om/toggle for show/hide highlighters ** 0.0.2 - feat: Add om/next and /prev - break: Change om/open-at-point to org-marginalia-open - break: Change om/save-all to org-marginalia-save ** 0.0.1 Initial alpha release. I consider it to be the minimal viable scope. ================================================ FILE: LICENSE ================================================ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ================================================ FILE: Makefile ================================================ # For ELPA, below should be added to the spec: # ("org-remark" :url "https://github.com/nobiot/org-remark" # :make "README-elpa" # :doc "docs/org-remark.org" # :auto-sync t) README-elpa: README.org -emacs --batch $< -f org-ascii-export-to-ascii -mv README.txt README-elpa .PHONY: test-compile test-compile: emacs --batch --eval "(add-to-list 'load-path default-directory)" \ -f batch-byte-compile ./*.el # Check declare-function emacs --batch --eval "(check-declare-directory default-directory)" .PHONY: clean clean: find . -name "*.elc" -delete ================================================ FILE: NEWS ================================================ Current development version Fixes: - fix: When the notes = source, the title is incorrect #97 Version 1.3.0 - 2025-01-28 Features: - feat: Define `org-remark-report-no-highlights` krisbalintona/chatty-no-highlights (#86) by Kristoffer Balintona - Ability to highlight a whole line and show a mark on the margin (#71) - Option to delete the whole notes entry when highlight is removed if there is no notes body text (#21) - `org-remark-open` to open the associated marginal notes file if cursor outside a highlight (#72) Fixes: - fix: crash when highlighting non-org source and org-remark-use-org-id is true (#95) - fix: org-remark-info-mode interfering with isearch-forward (#93) - fix: fix: args-out-of-range error during loading highlights (#89) - fix: `org-remark-link` gets wrongly referenced (#83) - fix: josephmturner/fixes (#87): typo in package description - fix: compiler warning ‘org-remark-highlight-save’ is an obsolete... - fix: Highlights overlay can get added to unsupported buffer (ef98c27) - fix(highlights-delay-load): rm window-state-change-functions (#82) Version 1.2.2 - 2024-03-25 - fix: program error #78 mapconcat's 3rd arg is not optional in Emacs 28 Version 1.2.1 - 2023-08-20 - fix: org-remark-icon-mode is a void symbol Version 1.2.0 - 2023-08-20 - feat(info): Org-remark supports Info + Advice has been implemented. It is added and removed by `org-remark-info-mode`. + No suitable hook is avaialble to trigger a function after the Info node is rendered. This is necessary as Info renders a new node in the same buffer (in the same way as Nov.el does). - feat: icons for additional information for highlights + Notes exists for the highlight (*) + The highlight position auto-adjusted (d) + Uses the new `org-remark-highlights-after-load-functions' + Icons are customizable. You can also disable icons by setting the respective customizing variable to nil + The default face of auto-adjusted icon is customizable with face `org-remark-highlighter-warning' + `org-remark-toggle' also toggles the icon display - feat: nov.el support for epub books + The link is added to the notes org file correctly pointing back to epub's highlight location with using :nov link type added by nov.el.l - feat: Adjust positions after load + This is useful especially for epubs via nov.el. Nov.el renders tables on differently depending on the size of the window. This causes the positions of subsequent text elements to move depending on the window size when the page is rendered, dislocating the positions of highlights. This feature attemps to auto-correct the location on the fly. The feature works generically, so Org-remark attemps to correct minior edits to websites (for EWW). + The fact that a given highlight has been automatically moved is indicated by an icon - feat: org-remark-highlights-after-load-functions Abnormal hook Fixes: - fix: org 9.6.7 breaks org-remark-highlights-get (#70) - fix: Make load process robust + When error occurs during the load process, instead of emitting an error, Org-remark now halts the load process and returns without an error. This has been proven useful especially for epub support with nov.el. Nov.el renders by reusing the same buffer instead of generating a new one. When error occurs during the load process (e.g. user accidentally deletes some property data in the notes org buffer), the error would cause nov.el to not properly render the epub book. This could override the epub archive file wiht a plain text file of a single file from the book, errasing the entire book. With this change, Org-remark does not cause the error when loading highlights from the notes org file to preven this distructive process from happening. + `org-remark-highlights-get' existence checks beg and end beg and end must exist. If either is nil, `number-to-string` errors and load stops prematurely. This can happen when the user manually manages the notes file and accidentally deletes the beg/end props. - fix: default highlighter color for dark theme No functional change. Changed the default color of the highlighter to be more visible in the dark theme. Version 1.1.0 - 2023-05-20 Features: - feat: notes-and-source sync Previously, Org-remark was designed to create/update/delete highlights from the source buffer to its marginal notes buffer; this was always one-way from the source to the notes. Now we have implemented the updating process in the other direction from the notes to source. Functionally, we currently have echo-text/tooltip containing an excerpt from the body of notes from the notes buffer (thanks to @mooseyboots). Other than this additional feature, there should be no visible change for end users. The update should all happen transparently behind the scenes with no to little change for end users of Org-remark. - feat: echo-text update from the marginal notes to the source buffer This is a code contribution by marty hiatt (@mooseyboots). He has done FSF copyright assignment in July, 2022. Now the source buffer can Display annotation text as help-echo or tooltip. Thank you, @mooseyboots. This has opened up an avenue to implement "notes sync" feature which updates select elements of marginal notes buffer back into the source buffer for highlight overlays. - feat: Extend support for non-file-visiting buffer We now have an approach to extend Org-remark to support non-file-visiting buffers of various modes. Currently it is assumed that the support is to be implemented per mode basis. We have support for EWW with 'org-remark-eww-mode' and its dedicated file and feature 'org-remark-eww'. Refer to its implementation as a reference as to how this approach is currently practiced. - feat: Global minor mode org-remark-eww-mode Support taking annotations in eww buffers for websites A new feature contributed by Vedang Manerikar (@vedang). He has completed FSF paperwork in May, 2022 and received a PDF regarding the same from the FSF. This has opened up a big new avenue to support highlights in non-file visiting buffers. Thank you @vedang. EWW support is modularized in a separate file 'org-remark-eww.el'. org-remark-link: prop for EWW Now 'org-remark-link' property in the marginal notes buffer contains the URL that you can follow for the source website. - add: org-remark-open-hook #40 Hook run when a note buffer is opened/visited. The current buffer is the note buffer. Fixes: - refactor: change the default colors of yellow pen #52 This is to cater to users who have dark theme that may render the highlighted text illegible due to the default background color of yellow. - fix: Text cut off in notes if the highlight spans across two lines #56 Thanks to GitHub user @sati-bodhi for reporting and suggesting a fix (code implemented by nobiot). Thank you @sati-bodhi. - fix: issue #44 change CATEGORY Now CATEGORY property from the highlight can be properly deleted if a new pen does not have CATEGORY. - fix: case for highlight-get-text empty notes at the bottom of buffer - fix: text-property org-remark-label to be symbol Fixes the error when you do 'describe-text-properties' on the highlight overlay - fix: move org-remark-source-find-file-name to tracking After EWW support, 'org-remark-source-get-file-name' is now moved to 'org-remark-global-tracking.el' file - fix: source-file-name incorrect issue #39 PR #38 by Nan Jun Jie (@nanjj). Thank you @nanjj. Version 1.0.5 - fix #28 toggle causes error on saving highlights - fix #39 source-file-name incorrect issue Version 1.0.4 - fix: "Wrong type argument: stringp, nil" on highlightintg in scratch Version 1.0.3 - fix #23: "Wrong type argument: stringp, nil" on org export - fix #22: highlights not found when marginalia does not show all Version 1.0.2 - Update README, user manual, and doc strings in source Version 1.0.1 - Update user manual Version 1.0.0 - chg: align with GNU convention: path -> file name Regarding user option `org-remark-notes-file-path`, the GNU convention is to call this a "file name" rather than a "path"; "path" is only used for lists of directories as in `load-path` (pointed out by Stefan Monnier; thank you). To align with the GNU convention, the following changes are done. Users should not have to change their existing customization as the old names are aliased to the new ones. User option: - org-remark-notes-file-path -> org-remark-notes-file-name - org-remark-source-path-function -> 'org-remark-source-file-name Function: - org-remark-notes-file-path-function -> org-remark-notes-file-name-function Private Function: - org-remark-notes-get-file-path -> org-remark-notes-get-file-name `org-remark-notes-file-path`, `org-remark-source-path-function`, and `org-remark-notes-file-path-function` are used by existing customization, thus both explicitly made obsolete and aliased to the new file-name equivalents. - fix: Relative file name of the source file in the notes file The relative file name of the source was not relative from the marginal notes file but from the source file itself -- this should be relative from the marginal notes. - chg: `org-remark-global-tracking-mode' has been simplified. This is not expected to break the user's workflow or configuration -- simply removing a superfluous feature. .org-remark-tracking file is no longer necessary and can be safely deleted from the user's Emacs configuraiton directory if present. Automatic activation of `org-remark-mode' is done by looking the presence of a marginal notes file for current buffer open. `org-remark-global-tracking-mode' itself is still relevant and recommended to be setup as was previously in the user manual. - add: Option to use relative links from the marginal notes back to the source Adding user option org-remark-source-path-function. The default is file-relative-name. - add: Adding a new option to org-remark-notes-file-path to use a function Its default function is org-remark-notes-file-path-function. It returns a file name like this: "FILE-notes.org" by adding "-notes.org" as a suffix to the file name without the extension. [Older changes before v1.0.0 are in CHANGELOG file] ================================================ FILE: README-elpa ================================================ _____________________ README – ORG-REMARK _____________________ Table of Contents _________________ 1. Introduction 2. Features 3. Installation 4. Contributing and Feedback 5. Contributors 6. License 1 Introduction ============== Org-remark lets you highlight and annotate text files, websites, EPUB books and Info documentation with using Org mode. A user manual is available [online] or Emacs in-system as an Info node `(org-remark)': (`C-h i' and find the `Org-remark' node) . The user manual is also available in Japanese: [マニュアル日本語版] 🇯🇵 (translated by ayatajesi, GitHub user @ayatakesi) together with his review with EWW, "[org-remarkでウェブページに注釈をつける]". For installation and minimum configuration, refer to [Installation] below or the user manual: [online] or Info node `(org-remark) Installation'. Getting Started in the user manual will get you started in 5 minutes: [online] or or Info node `(org-remark) Getting Started'. For customization, refer to the customization group `org-remark' or user manual: [online] or Info node `(org-remark) Customizing'. A [separate online article] has been written to guide you on how to customize an icon (also part of the user manual. Evaluate (info "(or-gremark) How to Set Org-remark to Use SVG Icons"). An [introductory video] (8 minutes) and [V1.1.0 release introduction] (12 minutes) are available on YouTube. [online] [マニュアル日本語版] [org-remarkでウェブページに注釈をつける] [Installation] See section 3 [online] [online] [online] [separate online article] [introductory video] [V1.1.0 release introduction] 2 Features ========== - Highlight and annotate any text file. The highlights and notes are kept in an Org file as the plain text database. This lets you easily manage your marginal notes and use the built-in Org facilities on them -- e.g. create a sparse tree based on the category of the notes - Create your your own highlighter pens with different colors, type (e.g. underline, squiggle, etc. optionally with Org's category for search and filter on your highlights and notes) - Have the same highlighting and annotating functionality for + Websites when you use EWW to browse them + EPUB books with [nov.el] + Info documentation + [wallabag.el] (it has been [reported]) Refer to [NEWS] file for a list of new features and fixes. [nov.el] [wallabag.el] [reported] [NEWS] 3 Installation ============== This package is available on: - [GNU-ELPA] (releases only; equivalent to MELPA-Stable) - [GNU-devel ELPA] (unreleased main branch; equivalent to MELPA) GNU ELPA should be already set up in your Emacs by default. If you wish to add GNU-devel ELPA, simply add its URL to `package-archives' like this: ,---- | (add-to-list 'package-archives | '("gnu-devel" . "https://elpa.gnu.org/devel/") :append) `---- After installation, we suggest you put the setup below in your configuration. ,---- | (org-remark-global-tracking-mode +1) | | ;; Optional if you would like to highlight websites via eww-mode | (with-eval-after-load 'eww | (org-remark-eww-mode +1)) | | ;; Optional if you would like to highlight EPUB books via nov.el | (with-eval-after-load 'nov | (org-remark-nov-mode +1)) | | ;; Optional if you would like to highlight Info documentation via Info-mode | (with-eval-after-load 'info | (org-remark-info-mode +1)) `---- Unless you explicitly load `org' during Emacs initialization, I suggest to defer loading `org-remark' (thus there is no `(require 'org-remark)' in the example above). This is because it will also pull in `org', which can slow down initialization. You can control the timing of loading `org-remark' by autoloading some commands in a similar way with the example keybindings below. Below are example keybindings you might like to consider: ,---- | ;; Key-bind `org-remark-mark' to global-map so that you can call it | ;; globally before the library is loaded. | | (define-key global-map (kbd "C-c n m") #'org-remark-mark) | | ;; The rest of keybidings are done only on loading `org-remark' | (with-eval-after-load 'org-remark | (define-key org-remark-mode-map (kbd "C-c n o") #'org-remark-open) | (define-key org-remark-mode-map (kbd "C-c n ]") #'org-remark-view-next) | (define-key org-remark-mode-map (kbd "C-c n [") #'org-remark-view-prev) | (define-key org-remark-mode-map (kbd "C-c n r") #'org-remark-remove) | (define-key org-remark-mode-map (kbd "C-c n d") #'org-remark-delete)) `---- Alternatively, you can use `use-package' to set up Org-remark. The example provided below should be equivalent to the setup described above. ,---- | (use-package org-remark-global-tracking | ;; It is recommended that `org-remark-global-tracking-mode' be | ;; enabled when Emacs initializes. You can set it in | ;; `after-init-hook'. | :hook after-init | :config | ;; Selectively keep or comment out the following if you want to use | ;; extensions for Info-mode, EWW, and NOV.el (EPUB) respectively. | (use-package org-remark-info :after info :config (org-remark-info-mode +1)) | (use-package org-remark-eww :after eww :config (org-remark-eww-mode +1)) | (use-package org-remark-nov :after nov :config (org-remark-nov-mode +1))) | | (use-package org-remark | :bind (;; :bind keyword also implicitly defers org-remark itself. | ;; Keybindings before :map is set for global-map. Adjust the keybinds | ;; as you see fit. | ("C-c n m" . org-remark-mark) | ("C-c n l" . org-remark-mark-line) | :map org-remark-mode-map | ("C-c n o" . org-remark-open) | ("C-c n ]" . org-remark-view-next) | ("C-c n [" . org-remark-view-prev) | ("C-c n r" . org-remark-remove) | ("C-c n d" . org-remark-delete))) `---- [GNU-ELPA] [GNU-devel ELPA] 4 Contributing and Feedback =========================== Create issues, discussion, and/or pull requests in the GitHub repository. All welcome. Org-remark is available on GNU ELPA and thus copyrighted by the [Free Software Foundation] (FSF). This means that anyone who is making a substantive code contribution will need to "assign the copyright for your contributions to the FSF so that they can be included in GNU Emacs" ([Org Mode website]). Thank you. [Free Software Foundation] [Org Mode website] 5 Contributors ============== *New features* - User option `org-remark-report-no-highlights`by Kristoffer Balintona (@krisbalintona) - EPUB books (nov.el) support would not have been possible without collaboration with @sati-bodhi - `echo-text' update from the marginal notes to the source buffer by marty hiatt (@mooseyboots) - Support for websites with `eww-mode' by Vedang Manerikar (@vedang) *Bug fixes* Joseph Turner (@josephmturner) @alan-w-255, Nan Jun Jie (@nanjj), @sgati-bodhi *Documentation (including README, NEWS, CHANGELOG)* @randomwangran, marty hiatt (@mooseyboots), @jsntn Thank-you to all the comments, issues, and questions on GitHub! 6 License ========= This work is licensed under a GPLv3 license. For a full copy of the license, refer to [LICENSE]. [LICENSE] <./LICENSE> ================================================ FILE: README.org ================================================ #+title: README – Org-remark #+options: toc:t creator:nil author:nil broken-links:t #+html: GNU Emacs #+html: GPLv3 #+html: GNU ELPA #+html: GNU-devel ELPA * Introduction Org-remark lets you highlight and annotate text files, websites, EPUB books and Info documentation with using Org mode. A user manual is available [[https://nobiot.github.io/org-remark/][online]] or Emacs in-system as an Info node `(org-remark)': (~C-h i~ and find the =Org-remark= node) . The user manual is also available in Japanese: [[https://qiita.com/ayatakesi/items/69d43671b28bb27a9c52][マニュアル日本語版]] 🇯🇵 (translated by ayatajesi, GitHub user @ayatakesi) together with his review with EWW, "[[https://qiita.com/ayatakesi/items/8986af2bf2ccca170439][org-remarkでウェブページに注釈をつける]]". For installation and minimum configuration, refer to [[#installation][Installation]] below or the user manual: [[https://nobiot.github.io/org-remark/#Installation][online]] or Info node `(org-remark) Installation'. Getting Started in the user manual will get you started in 5 minutes: [[https://nobiot.github.io/org-remark/#Getting-Started][online]] or or Info node `(org-remark) Getting Started'. For customization, refer to the customization group `org-remark' or user manual: [[https://nobiot.github.io/org-remark/#Customizing][online]] or Info node `(org-remark) Customizing'. A [[https://github.com/nobiot/org-remark/tree/main/docs/articles/2023-08-20T184309_C_how-to-set-icons-to-be-svg-images.md][separate online article]] has been written to guide you on how to customize an icon (also part of the user manual. Evaluate (info "(or-gremark) How to Set Org-remark to Use SVG Icons"). An [[https://youtu.be/c8DHrAsFiLc][introductory video]] (8 minutes) and [[https://youtu.be/BTFuS21N00k][V1.1.0 release introduction]] (12 minutes) are available on YouTube. * Features - Highlight and annotate any text file. The highlights and notes are kept in an Org file as the plain text database. This lets you easily manage your marginal notes and use the built-in Org facilities on them -- e.g. create a sparse tree based on the category of the notes - Create your your own highlighter pens with different colors, type (e.g. underline, squiggle, etc. optionally with Org's category for search and filter on your highlights and notes) - Have the same highlighting and annotating functionality for + Websites when you use EWW to browse them + EPUB books with [[https://depp.brause.cc/nov.el/][nov.el]] + Info documentation + [[https://github.com/chenyanming/wallabag.el][wallabag.el]] (it has been [[https://github.com/nobiot/org-remark/issues/92#issuecomment-2601307855][reported]]) Refer to [[https://github.com/nobiot/org-remark/blob/main/NEWS][NEWS]] file for a list of new features and fixes. * Screenshots and Videos :noexport: [[./resources/images/2022-01-22-Title.png]] *Figure 1*. Left: Org-mode with text enlarged; Right: marginal notes with an inline image. [[https://youtu.be/c8DHrAsFiLc][Introductory video]] (8 minutes) and [[https://youtu.be/BTFuS21N00k][v1.1.0 release introduction]] (12 minutes) are available on YouTube [[./resources/images/2022-01-22-Context-menu.png]] *Figure 2*. Mouse context menu with built-in ~context-menu-mode~ available with Emacs version 28 onward [[./resources/images/2023-08-20-epub-prince-icon.png]] *Figure 3*. EPUB book ("Prince" by Niccolò Machiavelli via https://www.gutenberg.org/) with icon indicating there are annotations to the highlight: new features with v1.2.0 (2023-08-20). Left: marginal notes file with annotations; Right: an EPUB book file with a highlight and simple ASCII icon. [[./resources/images/v1.3.0/2023-08-19-line-highlights-with-icons.png]] *Figure 4*. Line-highlights with using icons (as of v1.3.0). Refer to the user manual or [[https://nobiot.com/blog/2023-09-11_org-remark-v1.3-line-highlight/][this article]] for more detail. * Installation :PROPERTIES: :CUSTOM_ID: installation :END: This package is available on: - [[https://elpa.gnu.org/packages/org-remark.html][GNU-ELPA]] (releases only; equivalent to MELPA-Stable) - [[https://elpa.gnu.org/devel/org-remark.html][GNU-devel ELPA]] (unreleased main branch; equivalent to MELPA) GNU ELPA should be already set up in your Emacs by default. If you wish to add GNU-devel ELPA, simply add its URL to ~package-archives~ like this: #+BEGIN_SRC elisp (add-to-list 'package-archives '("gnu-devel" . "https://elpa.gnu.org/devel/") :append) #+END_SRC After installation, we suggest you put the setup below in your configuration. #+begin_src emacs-lisp (org-remark-global-tracking-mode +1) ;; Optional if you would like to highlight websites via eww-mode (with-eval-after-load 'eww (org-remark-eww-mode +1)) ;; Optional if you would like to highlight EPUB books via nov.el (with-eval-after-load 'nov (org-remark-nov-mode +1)) ;; Optional if you would like to highlight Info documentation via Info-mode (with-eval-after-load 'info (org-remark-info-mode +1)) #+end_src Unless you explicitly load ~org~ during Emacs initialization, I suggest to defer loading ~org-remark~ (thus there is no ~(require 'org-remark)~ in the example above). This is because it will also pull in ~org~, which can slow down initialization. You can control the timing of loading ~org-remark~ by autoloading some commands in a similar way with the example keybindings below. Below are example keybindings you might like to consider: #+begin_src emacs-lisp ;; Key-bind `org-remark-mark' to global-map so that you can call it ;; globally before the library is loaded. (define-key global-map (kbd "C-c n m") #'org-remark-mark) ;; The rest of keybidings are done only on loading `org-remark' (with-eval-after-load 'org-remark (define-key org-remark-mode-map (kbd "C-c n o") #'org-remark-open) (define-key org-remark-mode-map (kbd "C-c n ]") #'org-remark-view-next) (define-key org-remark-mode-map (kbd "C-c n [") #'org-remark-view-prev) (define-key org-remark-mode-map (kbd "C-c n r") #'org-remark-remove) (define-key org-remark-mode-map (kbd "C-c n d") #'org-remark-delete)) #+end_src Alternatively, you can use ~use-package~ to set up Org-remark. The example provided below should be equivalent to the setup described above. #+begin_src emacs-lisp (use-package org-remark-global-tracking ;; It is recommended that `org-remark-global-tracking-mode' be ;; enabled when Emacs initializes. You can set it in ;; `after-init-hook'. :hook after-init :config ;; Selectively keep or comment out the following if you want to use ;; extensions for Info-mode, EWW, and NOV.el (EPUB) respectively. (use-package org-remark-info :after info :config (org-remark-info-mode +1)) (use-package org-remark-eww :after eww :config (org-remark-eww-mode +1)) (use-package org-remark-nov :after nov :config (org-remark-nov-mode +1))) (use-package org-remark :bind (;; :bind keyword also implicitly defers org-remark itself. ;; Keybindings before :map is set for global-map. Adjust the keybinds ;; as you see fit. ("C-c n m" . org-remark-mark) ("C-c n l" . org-remark-mark-line) :map org-remark-mode-map ("C-c n o" . org-remark-open) ("C-c n ]" . org-remark-view-next) ("C-c n [" . org-remark-view-prev) ("C-c n r" . org-remark-remove) ("C-c n d" . org-remark-delete))) #+end_src * Contributing and Feedback Create issues, discussion, and/or pull requests in the GitHub repository. All welcome. Org-remark is available on GNU ELPA and thus copyrighted by the [[http://fsf.org][Free Software Foundation]] (FSF). This means that anyone who is making a substantive code contribution will need to "assign the copyright for your contributions to the FSF so that they can be included in GNU Emacs" ([[https://orgmode.org/contribute.html#copyright][Org Mode website]]). Thank you. * Contributors *New features* - User option `org-remark-report-no-highlights`by Kristoffer Balintona (@krisbalintona) - EPUB books (nov.el) support would not have been possible without collaboration with @sati-bodhi - ~echo-text~ update from the marginal notes to the source buffer by marty hiatt (@mooseyboots) - Support for websites with ~eww-mode~ by Vedang Manerikar (@vedang) *Bug fixes* Joseph Turner (@josephmturner) @alan-w-255, Nan Jun Jie (@nanjj), @sgati-bodhi *Documentation (including README, NEWS, CHANGELOG)* @randomwangran, marty hiatt (@mooseyboots), @jsntn Thank-you to all the comments, issues, and questions on GitHub! * License This work is licensed under a GPLv3 license. For a full copy of the license, refer to [[./LICENSE][LICENSE]]. ================================================ FILE: docs/.nojekyll ================================================ ================================================ FILE: docs/Makefile ================================================ .POSIX: EMACS = emacs MAKEINFO = makeinfo INSTALLINFO = install-info MV = mv RM = rm MANUAL_HTML_ARGS =--html --no-split --footnote-style=separate --css-ref=resources/manual.css ## Build ############################################################# .PHONY: gh-html gh-html: index.html clean .PHONY: all all: index.html org-remark.info clean index.html: org-remark.texi @printf "\n\n### Generating manual .html files \n\n" $(MAKEINFO) $(MANUAL_HTML_ARGS) $< -o index.html org-remark.texi: org-remark.org @printf "\n\n### Generating manual .texi file \n\n" $(EMACS) --batch -L --file $< \ -f org-texinfo-export-to-texinfo org-remark.info: org-remark.texi @printf "\n\n### Generating manual .info file \n\n" makeinfo org-remark.texi -o org-remark.info .PHONY: clean clean: @printf "\n\n### Clear .texi file \n\n" $(RM) org-remark.texi* ================================================ FILE: docs/articles/2023-08-20T183400_how-to-buffer-window.org ================================================ Buffer window customization #43 https://github.com/nobiot/org-remark/discussions/43 ================================================ FILE: docs/articles/2023-08-20T184309_C_how-to-set-icons-to-be-svg-images.md ================================================ --- title: How to Set Org-remark to Use SVG Icons created: 2023-08-20 modified: 16 September 2023 category: #creation id: 2023-08-20T184309 --- # How to Set Org-remark to Use SVG Icons ![Highlights with an icon indicating annotations exist](../screen-images/v1.2.0/2023-08-20-SVG-icon.png "Highlights with an icon indicating annotations exist") I have released version 1.2.0 of Org-remark. In this version, highlights can display an icon to visually indicate that annotations exist for them. This was implemented in response to a feature request I received via YouTube comments and recorded in [issue #64](https://github.com/nobiot/org-remark/issues/64). The icon by default is a string of ASCII characters "`(*)`" so that it can be used for terminals. You can easily customize Org-remark to use an SVG image as shown in the image above. There are mainly two ways: 1. Use the new built-in `icons` library available as of Emacs version 29.1 2. Create a custom function and use a third-party library such as [`svg-lib`](https://github.com/rougier/svg-lib) by Nicolas Rougier I will quickly show you the first option to use the new built-in library, which I believe is the easier. ## Define an icon 1. Get or create an SVG icon In my example, I downloaded a "pen" icon as an `.svg` file from [Boxicons](https://boxicons.com/?query=pen) ([licensed under The MIT License](https://boxicons.com/usage#license)). 2. Put the downloaded SVG file somewhere in your local I put it at `~/.config/emacs/.cache/svg/bx-pen.svg`. 3. Use `define-icon` macro to create an icon with the SVG file For example, I used the code below. Make sure to change my example to your own file name. You can also play with the `:height` property as you see fit. You can refer to the relevant Info nodes for more configuration detail by evaluating `(info "(elisp)icons)` and `(info "(emacs)icons")` in Emacs (version 29.1 onward). ``` emacs-lisp (define-icon annotation nil '((image "/home/nobiot/.config/emacs/.cache/svg/bx-pen.svg" :height (0.8 . em))) "Notes svg icon for Org-remark" :version 29.1) ``` ## Customize Org-remark to use the icon Now the icon has been defined, you can set it to customizing variable `org-remark-icon-notes`, like so: ``` emacs-lisp ;; I use `setopt` that is made available as of 29.1. `setq` works too. ;; Use whichever you prefer. (setopt org-remark-icon-notes (icon-string 'annotation)) ``` If you have a buffer with highlights already open, you would need to `revert-buffer` to reload the highlights. You should see the icon you have defined instead of the default "`(*)`" string, like you see in the screen capture at the top of this article. ================================================ FILE: docs/fdl.texi ================================================ @c The GNU Free Documentation License. @center Version 1.3, 3 November 2008 @c This file is intended to be included within another document, @c hence no sectioning command or @node. @display Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. @uref{https://fsf.org/} Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @end display @enumerate 0 @item PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document @dfn{free} in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of ``copyleft'', which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. @item APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The ``Document'', below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as ``you''. You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A ``Modified Version'' of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A ``Secondary Section'' is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The ``Invariant Sections'' are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The ``Cover Texts'' are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A ``Transparent'' copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not ``Transparent'' is called ``Opaque''. Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, La@TeX{} input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG@. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The ``Title Page'' means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, ``Title Page'' means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. The ``publisher'' means any person or entity that distributes copies of the Document to the public. A section ``Entitled XYZ'' means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as ``Acknowledgements'', ``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title'' of such a section when you modify the Document means that it remains a section ``Entitled XYZ'' according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. @item VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. @item COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. @item MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: @enumerate A @item Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. @item List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. @item State on the Title page the name of the publisher of the Modified Version, as the publisher. @item Preserve all the copyright notices of the Document. @item Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. @item Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. @item Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. @item Include an unaltered copy of this License. @item Preserve the section Entitled ``History'', Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled ``History'' in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. @item Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the ``History'' section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. @item For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. @item Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. @item Delete any section Entitled ``Endorsements''. Such a section may not be included in the Modified Version. @item Do not retitle any existing section to be Entitled ``Endorsements'' or to conflict in title with any Invariant Section. @item Preserve any Warranty Disclaimers. @end enumerate If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled ``Endorsements'', provided it contains nothing but endorsements of your Modified Version by various parties---for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. @item COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled ``History'' in the various original documents, forming one section Entitled ``History''; likewise combine any sections Entitled ``Acknowledgements'', and any sections Entitled ``Dedications''. You must delete all sections Entitled ``Endorsements.'' @item COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. @item AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an ``aggregate'' if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. @item TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled ``Acknowledgements'', ``Dedications'', or ``History'', the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. @item TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License. However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it. @item FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See @uref{https://www.gnu.org/licenses/}. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License ``or any later version'' applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document. @item RELICENSING ``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A ``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the site means any set of copyrightable works thus published on the MMC site. ``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization. ``Incorporate'' means to publish or republish a Document, in whole or in part, as part of another Document. An MMC is ``eligible for relicensing'' if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008. The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing. @end enumerate @page @heading ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: @smallexample @group Copyright (C) @var{year} @var{your name}. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License''. @end group @end smallexample If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the ``with@dots{}Texts.''@: line with this: @smallexample @group with the Invariant Sections being @var{list their titles}, with the Front-Cover Texts being @var{list}, and with the Back-Cover Texts being @var{list}. @end group @end smallexample If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. @c Local Variables: @c ispell-local-pdict: "ispell-dict" @c End: ================================================ FILE: docs/marginalia.org ================================================ :PROPERTIES: :ID: 2022-01-15T093859 :END: * Org-remark User Manual :PROPERTIES: :org-remark-file: ~/src/org-remark/docs/org-remark.org :END: ** TODO vindex :PROPERTIES: :CATEGORY: important :END: - (defcustom org-remark-create-default-pen-set t - [ ] #+vindex: org-remark-notes-file-path - [ ] #+vindex: org-remark-notes-display-buffer-action - (defcustom org-remark-notes-buffer-name "*marginal notes*" - (defcustom org-remark-use-org-id nil ================================================ FILE: docs/org-remark.org ================================================ #+title: Org-remark User Manual #+author: Noboru Ota #+macro: version 1.3.x #+macro: modified 01 February 2024 #+language: en #+export_file_name: org-remark.texi #+texinfo_dir_category: Emacs #+texinfo_dir_title: Org-remark: (org-remark) #+texinfo_dir_desc: Highlight and annotate any text file #+texinfo: @paragraphindent asis #+options: toc:nil ':t This manual is for Org-remark version {{{version}}}. The new features introduced with version {{{version}}} are currently only available [[https://elpa.gnu.org/devel/org-remark.html][GNU-devel ELPA]] until the new version is released to [[https://elpa.gnu.org/packages/org-remark.html][GNU-ELPA]]. Last updated: {{{modified}}}. Org-remark lets you highlight and annotate text files, websites (EWW), EPUB books (nov.el) and Info documentation (Info-mode). #+texinfo: @insertcopying * COPYING :PROPERTIES: :COPYING: t :END: Copyright \copy 2021-2023 Free Software Foundation, Inc. #+begin_quote Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being “A GNU Manual,” and with the Back-Cover Texts as in (a) below. A copy of the license is included in the section entitled “GNU Free Documentation License.” (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and modify this GNU manual.” #+end_quote * Installation :PROPERTIES: :CUSTOM_ID: installation :END: This package is available on: - [[https://elpa.gnu.org/packages/org-remark.html][GNU-ELPA]] (releases only; equivalent to MELPA-Stable) - [[https://elpa.gnu.org/devel/org-remark.html][GNU-devel ELPA]] (unreleased main branch; equivalent to MELPA) GNU ELPA should be already set up in your Emacs by default. If you wish to add GNU-devel ELPA, simply add its URL to ~package-archives~ like this: #+BEGIN_SRC elisp (add-to-list 'package-archives '("gnu-devel" . "https://elpa.gnu.org/devel/") :append) #+END_SRC ** Basic Setup After installation, we suggest you put the setup below in your configuration. #+name: basic-setup #+begin_src emacs-lisp (org-remark-global-tracking-mode +1) ;; Optional if you would like to highlight websites via eww-mode (with-eval-after-load 'eww (org-remark-eww-mode +1)) ;; Optional if you would like to highlight EPUB books via nov.el (with-eval-after-load 'nov (org-remark-nov-mode +1)) ;; Optional if you would like to highlight Info documentation via Info-mode (with-eval-after-load 'info (org-remark-info-mode +1)) #+end_src ~org-remark-global-tracking-mode~ automatically turns on ~org-remark-mode~ when you open a file, website via EWW, EPUB book via nov.el, or other supported buffer that has a marginal notes file associated with it. This is useful to keep the location of your highlights correct across Emacs sessions after you shutdown Emacs. Unless you explicitly load ~org~ during Emacs initialization, we suggest to defer loading ~org-remark~ (thus there is no ~(require 'org-remark)~ in the example above). This is because it will also pull in ~org~, which can slow down initialization. You can control the timing of loading ~org-remark~ by autoloading some commands in a similar way with the example keybindings below. Below are example keybindings you might like to consider: #+begin_src emacs-lisp ;; Key-bind `org-remark-mark' to global-map so that you can call it ;; globally before the library is loaded. (define-key global-map (kbd "C-c n m") #'org-remark-mark) (define-key global-map (kbd "C-c n l") #'org-remark-mark-line) ; new in v1.3 ;; The rest of keybidings are done only on loading `org-remark' (with-eval-after-load 'org-remark (define-key org-remark-mode-map (kbd "C-c n o") #'org-remark-open) (define-key org-remark-mode-map (kbd "C-c n ]") #'org-remark-view-next) (define-key org-remark-mode-map (kbd "C-c n [") #'org-remark-view-prev) (define-key org-remark-mode-map (kbd "C-c n r") #'org-remark-remove) (define-key org-remark-mode-map (kbd "C-c n d") #'org-remark-delete)) #+end_src ** Setup with ~use-package~ Alternatively, you can use ~use-package~ to set up Org-remark. The example provided below should be equivalent to the setup described above. #+name: setup-with-use-package #+begin_src emacs-lisp (use-package org-remark-global-tracking ;; It is recommended that `org-remark-global-tracking-mode' be ;; enabled when Emacs initializes. You can set it in ;; `after-init-hook'. :hook after-init :config ;; Selectively keep or comment out the following if you want to use ;; extensions for Info-mode, EWW, and NOV.el (EPUB) respectively. (use-package org-remark-info :after info :config (org-remark-info-mode +1)) (use-package org-remark-eww :after eww :config (org-remark-eww-mode +1)) (use-package org-remark-nov :after nov :config (org-remark-nov-mode +1))) (use-package org-remark :bind (;; :bind keyword also implicitly defers org-remark itself. ;; Keybindings before :map is set for global-map. Adjust the keybinds ;; as you see fit. ("C-c n m" . org-remark-mark) ("C-c n l" . org-remark-mark-line) :map org-remark-mode-map ("C-c n o" . org-remark-open) ("C-c n ]" . org-remark-view-next) ("C-c n [" . org-remark-view-prev) ("C-c n r" . org-remark-remove) ("C-c n d" . org-remark-delete))) #+end_src * Getting Started :PROPERTIES: :CUSTOM_ID: getting-started :END: ** Highlighting and Annotating #+findex: org-remark-mark #+findex: org-remark-mark-line #+findex: org-remark-open #+findex: org-remark-view #+cindex: Marginal notes file #+cindex: line-highlight #+cindex: range-highlight #+vindex: org-remark-line-margin-side #+vindex: org-remark-notes-display-buffer-action Once you have installed and set it up ([[#installation][Installation]]), Org-remark is simple to use. Select a part of text and call ~M-x org-remark-mark~ to highlight it. You will see the selected text gets highlighted. This is a range-highlight. With the new version 1.3, you can also highlight a whole line in addition to a range of text by calling ~org-remark-mark-line~. Visually, instead of adding a highlight to the line, it will add a mark on the margin of the buffer (the left margin is the default and you can customize it with ~org-remark-line-margin-side~). This is a line-highlight. Both the range- and line-highlights behave the same way except for how they appear in the buffer you are editing or viewing. You can mix them in the same buffer as you see fit for your purposes. The menu bar item "Org-remark" is available when you turn on ~org-remark-mode~. It helps you discover Org-remark's main commands. If you use Emacs version 28 or newer, a context menu is also available by right-clicking your mouse. Turn on the Emacs built-in ~context-menu-mode~ to enable the context menu. To display the marginal notes for the highlight you have just marked, place your cursor on the highlight and call ~M-x org-remark-open~ or ~M-x org-remark-view~. This will create a new buffer to the left of the current buffer you are editing. You can customize where the marginal notes buffer is to be placed (see the documentation of customizing variable ~org-remark-notes-display-buffer-action~). The ~open~ command takes the cursor to the marginal notes buffer for you to edit notes; the ~view~ command keeps the cursor in the current buffer only to display the marginal notes. Both commands narrow the *marginal notes file* to the entry for the highlight under the cursor. The marginal notes file is a normal Org file. Edit your notes just as you would do with any other Org files and save the buffer. ** Navigating from One Highlight to Another #+findex: org-remark-view-next #+findex: org-remark-view-prev #+cindex: Menu in the menu bar #+cindex: Context menu After you have added a couple of highlights in the text, you can move through the highlights easily. Use ~org-remark-view-next~ and ~org-remark-view-prev~ to browse the marginal notes as you move from one highlight to another. They display the marginal notes on the side-window by default. Or use ~org-remark-next~ and ~org-remark-prev~ if you simply want to move to the next/previous highlight without displaying marginal notes for them. To make navigation easy, you can use define the same "prefix key" to Org-remark commands like this: - ~C-c n o~: ~org-remark-open~ - ~C-c n ]~: ~org-remark-view-next~ - ~C-c n [~: ~org-remark-view-prev~ - ~C-c n r~: ~org-remark-remove~ - ~C-c n d~: ~org-remark-delete~ The ~C-c n~ part is the prefix key common to all of them. If you set the keybindings like this, you can use ~C-c n ]~ once to view the next highlight and keep pressing a single key ~]~ or ~[~ to browse through the next/previous highlights. After you have reached the one you like to act on, press ~o~ to open it, ~r~ or ~d~ to remove/delete it. ** Create Your Own Highlighter Pens #+cindex: Custom highlighter pens Org-remark has a default highlighter pen function, and comes with a set of two additional pens by default: - ~org-remark-mark~ :: default highlighter pen - ~org-remark-mark-line~ :: default line-highlighter pen, which adds a mark on the margin instead of a range of text - ~org-remark-mark-yellow~ :: yellow highlight with "important" category in the marginal notes entry - ~org-remark-mark-red-line~ :: wavy red underline with "review" category in the marginal notes entry and "Review this" in tool-tips Org-remark lets you create your own custom pen functions with ~org-remark-create~. Use the yellow and red line pens as examples, and create your own. For how to do it, [[#create-custom-pens][How to Create Custom Highlighter Pens]]. This is all you need to get started. For more detail, refer to the rest of this user manual, especially [[#usage][Usage]] and [[#customizing][Customizing]] sections. There is more to the commands introduced in this section and more ways in which you can customize Org-remark. ** Highlight and Annotate Websites #+cindex: Highlighting websites with EWW #+findex: org-remark-eww-mode ~org-remark-eww-mode~ lets you highlight and annotate websites just like text files. It is a global minor mode. It does not require any additional configuration. All you need is to turn it on, visit a website with ~eww-mode~, and select text and highlight it. Refer to the example of a basic setup given in [[#installation][Installation]]. Org-remark can attempt to automatically adjust the position of highlights when a websites get edited. Learn more about the feature in [[#auto-adjust][What is Automatic Adjustment of Highlight Positions?]] ** Highlight and Annotate EPUB Books #+cindex: Highlighting EPUB Books with nov.el #+findex: org-remark-nov-mode ~org-remark-nov-mode~ lets you highlight and annotate EPUB books just like text files. It is a global minor mode. It does not require any additional configuration. All you need is to turn it on, open a EPUB book with ~nov-mode~, and select text and highlight it. Refer to the example of a basic setup given in [[#installation][Installation]]. If you read books with tables, it is useful to learn about the feature that automatically adjust the highlight positions: [[#auto-adjust][What is Automatic Adjustment of Highlight Positions?]] ** Highlight and Annotate Info documentation in ~Info-mode~ #+cindex: Highlighting Info documentation with Info-mode #+findex: org-remark-info-mode ~org-remark-info-mode~ lets you highlight and annotate Info documentation just like text files. It is a global minor mode. It does not require any additional configuration. All you need is to turn it on, open an Info node with ~Info-mode~, and select text and highlight it. Refer to the example of a basic setup given in [[#installation][Installation]]. * Usage, Features, Concepts :PROPERTIES: :CUSTOM_ID: usage :END: ** How to Create Custom Highlighter Pens :PROPERTIES: :CUSTOM_ID: create-custom-pens :END: #+cindex: Custom highlighter pens #+cindex: Org-remark properties for highlights #+findex: org-remark-mark #+findex: org-remark-mark-yellow #+findex: org-remark-mark-red-line #+findex: org-remark-create ~org-remark-create~ is a macro that lets you create your own custom pen functions. Org-remark comes with two additional pens that are created by default. Use them as examples to learn how to create your own. #+begin_src elisp (org-remark-create "red-line" '(:underline (:color "dark red" :style wave)) '(CATEGORY "review" help-echo "Review this")) (org-remark-create "yellow" '(:underline "gold" :background "lemon chiffon") '(CATEGORY "important")) #+end_src - Macro: ~org-remark-create~ label &optional face properties :: Create and register new highlighter pen functions. The newly created pen function will be registered to variable ~org-remark-available-pens~. It is used by ~org-remark-change~ as a selection list. ~LABEL~ is the name of the highlighter and mandatory. The function will be named ~org-remark-mark-LABEL~. The highlighter pen function will apply ~FACE~ to the selected region. ~FACE~ can be an anonymous face. When ~FACE~ is nil, this macro uses the default face ~org-remark-highlighter~. ~PROPERTIES~ is a plist of pairs of a symbol and value. Each highlighted text region will have a corresponding Org headline in the notes file, and it can have additional properties in the property drawer from the highlighter pen. To do this, prefix property names with "=org-remark-=" or use "=CATEGORY=". As of version 1.3, you can use ~org-remark-create~ to create a new line-highlighter pen. Use the ~PROPERTIES~ parameter like the example below to specify ~org-remark-type~ to be ~line~. This tells Org-remark to create a line-highlighter pen function instead of a default range-highlighter one. The ~LABEL~ does not need to include the string "line", but it is recommended for consistency with the default command ~org-remark-mark-line~. #+begin_src emacs-lisp ;; This creates a custom command named org-remark-mark-line-alt with ;; face diff-hunk-header (org-remark-create "line-alt" 'diff-hunk-header '(org-remark-type line)) #+end_src #+ATTR_TEXINFO: :tag NOTE #+begin_quote Don't use =category= (all lowercase, symbol) as a property -- it's a special one for text properties. If you use it, the value also need to be a symbol; otherwise, you will get an error. You can use =CATEGORY= (all uppercase, symbol), which will result in adding =CATEGORY= with the value in the property drawer in marginal notes Org files. #+end_quote ** How to Automatically Turn On Highlights after Re-starting Emacs #+findex: org-remark-global-tracking-mode #+findex: org-remark-mode It is recommended that ~org-remark-global-tracking-mode~ be turned on as part of your Emacs initialization. This should be done before you start adding highlights in any file. Once you have added highlights to some files, quit Emacs, and re-start it, active ~org-remark-global-tracking-mode~ will automatically turn on ~org-remark-mode~ and load the highlights from your previous sessions for the files being globally tracked. Without this global minor mode, you would need to remember to activate ~org-remark-mode~ for each file where you add highlights and annotation. This is often unpractical. ** How to Manage Marginal Notes :PROPERTIES: :DESCRIPTION: Where Org-remark stores highlights and how to control it :END: *** Marginal Notes File #+cindex: Marginal notes file #+cindex: Org-remark properties for highlights When you mark a part of text with a highlighter pen function, Org-remark will automatically create a *marginal notes file*. By default, it will be named ~marginalia.org~ and created in the same directory as the file you are editing ([[#change-marginal-notes-filename][How to Change Where Marginal Notes File is Saved]] [[#customizing][;Customizing]], ~org-remark-notes-file-name~). The important thing to note is that Org-remark uses following properties in the property drawer of the headline to remember the highlights: - :org-remark-beg: - :org-remark-end: - :org-remark-id: - :org-remark-label: Essentially, the marginal notes file is a database in the plain text with using Org mode. As a plain text database, you can easily edit these properties manually if necessary. You can directly edit the marginal notes file as a normal Org file. The marginal notes file stores highlights and notes like this below; it is designed to organize highlights and notes for multiple files and multiple highlights (You are free to change the default headline titles Org-remark automatically inserts. Refer to section [[#organize-headlines][Organize Headlines in Marginal Notes Buffer in Your Way]]). #+begin_src org ,* File 1 ,** Highlight 1 in File 1 ,** Highlight 2 in File 1 [...] ,* File 2 ,** Highlight 1 in File 2 [...] #+end_src You can leave the marginal notes file as it is without writing any notes. In this case, the entries in marginal notes file simply save the locations of your highlighted text. After you quit Emacs, re-start it, and visit the same source file, Org-remark uses this information to highlight the text again. In addition to the properties above that Org-remark reserves for itself, you can add your own custom properties and ~CATEGORY~ property. Use "org-remark-" as the prefix to the property names (or "CATEGORY", which is the only exception), and Org-remark put them to the property drawer of highlight's headline entry in the marginal notes buffer. Define the custom properties in your own custom pen functions (for how to create your own pens, [[#create-custom-pens][How to Create Custom Highlighter Pens]]). *** Organize Headlines in Marginal Notes Buffer in Your Way :PROPERTIES: :CUSTOM_ID: organize-headlines :END: #+vindex: org-remark-line-heading-title-max-length #+vindex: org-remark-line-ellipsis When you highlight a range of text or a line, Org-remark creates a corresponding headline in the marginal notes buffer with using Org mode. By default, the headline's title is either the selected text for the range-highlight or the first 40 characters of the line for the line-highlight. For the latter, if the string is longer than the maximum characters, it will be truncated and replaced by an ellipsis "…". Both the 40 character maximum length and the ellipsis can be customized with customizing variables ~org-remark-line-heading-title-max-length~ and ~org-remark-line-ellipsis~ respectively. These are only default initial headline titles and you are free to change them as you see fit. For example, you may add a line-highlight to the line where you define a function in an Emacs Lisp script file. The initial title of the corresponding headline in the marginal notes buffer will be something like this below. #+begin_example ,** (defun name-of-the-function (arg)...) :PROPERTIES:... I will revisit this function later. #+end_example It may make sense to change this to something like this, especially if you would prefer to organize marginal notes as ~TODO~ items so as to show the headlines in your agenda. #+begin_example ,** TODO review name-of-the-function :PROPERTIES:... I will revisit this function later. #+end_example *** =*marginal-notes*= Buffer #+cindex: *marginal notes* buffer #+cindex: Echo text / Tool tip on the Highlight When you display the marginal notes with ~org-remark-view~ or ~org-remark-open~ for a given highlight, Org-remark creates a cloned indirect buffer visiting the marginal notes file. By default, it is a dedicated side-window opened to the left part of the current frame, and it is named =*marginal notes*=. You can change the behavior of ~display-buffer~ function and the name of the buffer ([[#customizing][Customizing]]). Org-remark displays the marginal notes buffer narrowed to the highlight the cursor is on. After all the properties, you can freely write your notes for the highlight. Once you save the notes buffer, an excerpt of the text (currently up to 200 characters) gets updated back onto the highlight in the source buffer. You can hover your mouse over the highlight to see the excerpt displayed in the echo area (bottom of the screen) of Emacs. If you have ~tooltip-mode~ mode turned on, the excerpt is displayed as a took tip for the highlight. *** How to Change Where Marginal Notes File is Saved :PROPERTIES: :CUSTOM_ID: change-marginal-notes-filename :END: #+vindex: org-remark-notes-file-name The location of the marginal notes file is specified by user option ~org-remark-notes-file-name~ and its default is "marginalia.org". This means the marginal notes file will reside in the same directory as the source files as a separate file. If you use the ~customize~ command to customize ~org-remark-notes-file-name~, you will have an option to choose a =File= or =Function= (customization group ~org-remark~). The default is =File= with the default "marginal.org" as noted above. Use a string to specify the single file name; you can specify a relative path like the default or an absolute path. If you would like to dynamically change the location based on the file and various different conditions, select the function as an option. The default function is ~org-remark-notes-file-name-function~. It adds =-notes.org= as a suffix to the source file's name without the extension. For example, for a file named =my-source-file.txt=, Org-remark will store highlights in =my-source-file-notes.org=. You can create your own function and use it. Some examples and use cases are listed below: - Store Marginal Notes in the Source File :: In order to use the source file also as the marginal notes file (storing the notes in the source file), you can set the built-in function ~buffer-file-name~ as the value of ~org-remark-notes-file-name~. Note that you will need to ensure that the source files are an Org file. - Create a marginal notes file for each source file and store all of them in a specific location :: Create a custom function that returns an absolute file name per source file, and set ~org-remark-notes-file-name~ to the function name. It might look like this: #+begin_src elisp (defun my/function () (concat "~/path/to/note-files/" (file-name-base (org-remark-notes-file-name-function)) ".org")) (setq org-remark-notes-file-name #'my/function) #+end_src *** How to Use Relative or Absolute File Names for Links in Marginal Notes File #+cindex: Relative or absolute file names pointing back at source files in marginal notes #+vindex: org-remark-source-file-name The marginal notes file stores the file name pointing back at source files. For example, a marginal notes entry for File1.txt might look like this example below. #+begin_src org ,* File 1 :PROPERTIES: :org-remark-file: path/to/File1.txt :END: ,** Highlight 1 in File 1 :PROPERTIES: :[...other-properties]: :org-remark-link: [[file:path/to/File1.txt::14]] :END: #+end_src The level-1 headline named "File 1" records the file name of the source file =path/to/File1.txt=. Similarly, the level-2 headline named "Highlight 1 in File 1" stores the link pointing back at the source file and the line number of the highlight. As you can see, both file names use a relative file name from the marginal notes file. This is the default setting of ~org-remark-source-file-name~. You can customize the variable to use absolute file names, or to use a function of your choice. The function is called with a single argument: the absolute file name of source file. The ~default-directory~ is temporarily set to the directory where the marginal notes file resides. If you choose to use relative file names, the relative path is computed from ~default-directory~. ** How to Remove and Delete Highlights #+findex: org-remark-remove #+findex: org-remark-delete #+vindex: org-remark-notes-auto-delete You can remove the highlight under the cursor with command ~org-remark-remove~. This command does not delete the corresponding entry in the marginal notes file. This is intentional; Org-remark is conservative when it deletes anything that the user might have edited. If you wish to delete the entry and the highlight at the same time, pass a universal argument to `org-remark-remove` (e.g. by adding ~C-u~ before ~M-x org-remark-remove~) or use ~org-remark-delete~. ~org-remark-delete~ is identical with adding ~C-u~ to ~org-remark-remove~. The delete function will prompt for confirmation if it detects any notes present in the corresponding entry for the highlight in question in the marginal notes buffer. #+ATTR_TEXINFO: :tag NOTE #+begin_quote Note that you can undo the deletion or removal *in the marginal notes buffer* -- not in the source buffer where you mark text with a highlighter. Technically, highlights are overlays and are therefore not part of the undo tree in the source buffer. #+end_quote As of version 1.3, you can use a new optional feature, automatic deletion. When the feature is enabled, Org-remark will automatically delete the highlight's headline when you delete text that includes a highlight, provided there is no marginal notes for it. If marginal notes are present for the highlight's headline, Org-remark only removes the highlight, deleting the properties from the highlight headline -- same operation as ~org-remark-remove~. Your marginal notes will be kept intact. In either case, Org-remark does not ask for your confirmation. You can enable it with the new user option ~org-remark-notes-auto-delete~ like this example below. #+begin_src emacs-lisp (setopt org-remark-notes-auto-delete :auto-delete) #+end_src Furthermore, with v1.3, if you pass a universal argument to ~org-remark-delete~ (e.g. ~C-u M-x org-remark-delete~) you can manually get Org-remark to do automatic deletion for the highlight at point. You can also pass double universal arguments to ~org-remark-remove~ (e.g. ~C-u C-u M-x org-remark-remove~) for the same operation. This should make sense because passing a single universal argument to ~org-remark-remove~ is the same as ~org-remark-delete~. Refer to the documentation of the customizing variable ~org-remark-notes-auto-delete,~ the functions ~org-remark-remove~ and ~org-remark-delete~. ** What is Automatic Adjustment of Highlight Positions? :PROPERTIES: :CUSTOM_ID: auto-adjust :END: #+cindex: Org-remark automatically adjusts positions of highlights #+vindex: org-remark-icon-position-adjusted #+vindex: org-remark-highlighter-warning Org-remark by default attempts to automatically adjust the position of highlights when they are loaded. This is useful especially for EPUB books read by nov.el. It renders tables in different sizes depending on the available space of the window to maximize their readability. This is a good feature for reading; however, it also changes the positions of subsequent text elements depending on the window size when the page is rendered. It can result in dislocating the positions of highlights, different from they are originally created. Org-remark attempts to automatically corrects the highlights dislocated. This is a general feature so Org-remark attempts to correct minor edits to websites (for EWW). More technically, it works as follows. 1. When you create a new highlight, Org-remark records the original text highlighted in the Org property named "~org-remark-original-text~". 2. Next time when you open a new file (EPUB book as an example), Org-remark loads the highlights from the notes Org buffer. 3. For each highlight, it compares the currently highlighted text with the value of ~org-remark-original-text~ property. 4. If they are the same, Org-remark does nothing. 5. If different, Org-remark by default looks for the same text string +- two paragraphs. When it finds the *first* matching text string, it automatically moves the highlight to the matched text string. 6. Org-remark adds an icon to the auto-adjusted highlight to make it clear that the position of highlight has been adjusted. 7. This adjustment is temporary. If you prefer to change the position permanently, you can do so by manually changing the ~org-remark-beg~ and ~org-remark-end~ properties in the notes buffer and save. You can also choose to alter the value of ~org-remark-original-text~ if you have adjusted the range of highlighted text. You can customize the icon itself and its face with the following customizing variables: - Option: ~org-remark-icon-position-adjusted~ - Face: ~org-remark-highlighter-warning~ ** How to Set Org-remark to Use SVG Icons :PROPERTIES: :CUSTOM_ID: icon :END: As of v1.2, highlights can display an icon. With this option, you can customize Org-remark to visually indicate that marginal notes exist for them instead of the default ASCII string "(*)", or to indicate that the Org-remark has automatically adjusted the highlight position (default ASCII string "(d)"; refer to [[#auto-adjust][What is Automatic Adjustment of Highlight Positions?]]). There are mainly two ways to set up SVG icons. 1. Use the new built-in `icons` library available as of Emacs version 29.1 2. Create a custom function and use a third-party library such as [[https://github.com/rougier/svg-lib][~svg-lib~]] by Nicolas Rougier Below is a quick guide on the first option to use the built-in library 1. Get or create an SVG icon 2. Put the downloaded SVG file somewhere in your local 3. Use define-icon macro to create an icon with the SVG file First, create or download an icon as an ~.svg~ file. For example, [[https://boxicons.com/][Boxicons]] has a collection of SVG icons, which [[https://boxicons.com/usage#license][are provided under The MIT License]]. Second, place the SVG file in your local directory, e.g. ~~/.config/emacs/.cache/svg/bx-pen.svg~. And finally, use ~define-icon~ to define the icon in your configuration like this example below. #+begin_src emacs-lisp (define-icon annotation nil '((image "~/.config/emacs/.cache/svg/bx-pen.svg" :height (0.8 . em))) "Notes svg icon for Org-remark" :version 29.1) #+end_src Now the icon has been defined, you can set it to customizing variable ~org-remark-icon-notes~ like so: #+begin_src emacs-lisp ;; This example uses `setopt' that is made available as of 29.1. `setq' works too. (setopt org-remark-icon-notes (icon-string 'annotation)) #+end_src If you have a buffer with highlights already open, use ~revert-buffer~ to reload the highlights. You should see the icon you have defined instead of the default “(*)” string. ** Other Commands #+findex: org-remark-toggle #+findex: org-remark-change #+findex: org-remark-next #+findex: org-remark-prev - Command ~org-remark-toggle~ :: Toggle showing/hiding of highlights in current buffer. If you would like to hide/show the highlights in the current buffer, it is recommended to use this command instead of ~org-remark-mode~. This command only affects the display of the highlights and their locations are still kept tracked. Toggling off ~org-remark-mode~ stops this tracking completely, which will likely result in inconsistency between the marginal notes file and the current source buffer. - Command ~org-remark-change~ :: Change the highlight at point to one by another pen. This command will show you a list of available pens to choose from. To navigate through highlights in the current buffer, you can use ~org-remark-view-next~ / ~org-remark-view-prev~ or the following pair of commands. The former moves your cursor and displays the marginal notes buffer; the latter only moves your cursor. - Command ~org-remark-next~ :: Move to the next highlight, if any. If there is none below the point but there is a highlight in the buffer, cycle back to the first one. After the point has moved to the next highlight, this command lets you move further by re-entering only the last letter like this example: =C-n ] ] ] ] ]= (assuming this command is bound to C-n ]) - Command ~org-remark-prev~ :: Move to the previous highlight, if any. * Customizing :PROPERTIES: :CUSTOM_ID: customizing :END: #+vindex: org-remark-highlighter #+vindex: org-remark-create-default-pen-set #+vindex: org-remark-notes-file-name #+vindex: org-remark-notes-display-buffer-action #+vindex: org-remark-notes-buffer-name #+vindex: org-remark-source-file-name #+vindex: org-remark-use-org-id #+vindex: org-remark-open-hook #+vindex: org-remark-icon-notes #+vindex: org-remark-icon-position-adjusted #+vindex: org-remark-highlights-after-load-functions #+vindex: org-remark-highlighter-warning Org-remark's user options are available in the customization group ~org-remark~. - Face: ~org-remark-highlighter~ :: Default face for ~org-remark-mark~ - Option: ~org-remark-create-default-pen-set~ :: When non-nil, Org-remark creates default pen set. Set to nil if you prefer for it not to. - Option: ~org-remark-notes-file-name~ :: Name of the file where we store highlights and marginal notes. It can be either a string or function. If it is a string, it should be a file name to the marginal notes file. The default is =marginalia.org=. The default will result in one marginal notes file per directory. Ensure that it is an Org file. If it is a function, the default function is ~org-remark-notes-file-name-function~. It returns a file name like this: =FILE-notes.org= by adding =-notes.org= as a suffix to the file name without the extension. - Option: ~org-remark-notes-display-buffer-action~ :: Buffer display action that Org-remark uses to open marginal notes buffer. - Option: ~org-remark-notes-buffer-name~ :: Buffer name of the marginal notes buffer. ~org-remark-open~ and ~org-remark-visit~ create an indirect clone buffer with this name. - Option: ~org-remark-source-file-name~ :: Function that returns the file name to point back at the source file. The function is called with a single argument: the absolute file name of source file. The =default-directory= is temporarily set to the directory where the marginal notes file resides. This means that when the =Relative file name= option is selected, the source file name recorded in the marginal notes file will be relative to it. - Option: ~org-remark-use-org-id~ :: When non-nil, Org-remark adds an Org-ID link to marginal notes. The link points at the relevant Org-ID in the source file. Org-remark does not create this ID, which needs to be added manually or some other function to either the headline or file. - Option: ~org-remark-icon-notes~ :: It's the icon used to indicate that a given highlight has its associated notes entry. The default is a combination of ASCII characters to be compatible with terminal and others. If it is preferred, you can set an emoji to it. The author has not experienced well with icon fonts and other means of displaying graphic elements. The face of the icon becomes the same as the highlight, thus it does not have its own face definition. By setting it to ~nil~, you can disable the icon altogether. ~org-remark-toggle~ also toggles the icon along with the highlight - Option: ~org-remark-icon-position-adjusted~ : It's the icon used to indicate that the position of a given highlight has been automatically adjusted by Org-remark. The default is a combination of ASCII characters to be compatible with terminal and others. If it is preferred, you can set an emoji to it. The author has not experienced well with icon fonts and other means of displaying graphic elements. By setting it to ~nil~, you can disable the icon altogether. ~org-remark-toggle~ also toggles the icon along with the highlight - Face: ~org-remark-highlighter-warning~ :: This face is used by the icon to indicate that the position of a given highlight has been adjusted. To know more about the feature itself, refer to [[#auto-adjust][What is Automatic Adjustment of Highlight Positions?]]. - Option: ~org-remark-open-hook~ :: Hook run when a note buffer is opened/visited. It gets run with no additional argument but the current buffer will become the note buffer. - Option ~org-remark-highlights-after-load-functions~ :: Abnormal hook run after Org-remark loads the highlights from the note org buffer. It is run with OVERLAYS and NOTES-BUF as arguments. OVERLAYS are highlights. It is run with the source buffer as current buffer. This hook is used by the automatic adjustment feature. To know more about the feature itself, refer to [[#auto-adjust][What is Automatic Adjustment of Highlight Positions?]]. ** Customizing Line Highlights #+vindex: org-remark-line-highlighter #+vindex: org-remark-line-icon #+vindex: org-remark-line-minimum-margin-width #+vindex: org-remark-line-margin-padding #+vindex: org-remark-line-margin-side #+vindex: org-remark-line-heading-title-max-length #+vindex: org-remark-line-ellipsis These are user options for line highlights available as of v1.3. They are listed in customizing group ~org-remark-line~. - Face: ~org-remark-line-highlighter~ :: Face for the default line highlighter pen. - Option: ~org-remark-line-icon~ :: Glyph displayed on the margin to indicate the line-highlight. You can set an SVG icon to it. Refer to [[#icon][How to Set Org-remark to Use SVG Icons]]. - Option: ~org-remark-line-minimum-margin-width~ :: Margin width in a natural number. It can be a single number or a cons cell of two. When it is a single number, both the left and right margin widths will be the same. When this customizing variable is a cons cell, the format is as follows: (LEFT-MARGIN-WIDTH . RIGHT-MARGIN-WIDTH). - Option: ~org-remark-line-margin-padding~ :: Padding between the main text area the glyph/icon on the margin. - Option: ~org-remark-line-margin-side~ :: The side of margin to display line highlights. Left or Right can be chosen. - Option: ~org-remark-line-heading-title-max-length~ :: Maximum length of string included as the highlight title. - Option ~org-remark-line-ellipsis~ :: Ellipsis used when the highlight title is longer than maximum. The maximum is set in ~org-remark-line-heading-title-max-length~. * Known Limitations - No export together with the source file :: There is no out-of-the-box feature to export marginal notes together with the source file. Nevertheless, the marginal notes is a normal Org file, thus if the source file is also an Org file, you could use the built-in =include= feature, for example, to include relevant parts of the marginal notes into the export output. - Copy & pasting loses highlights :: Overlays are not part of the kill; thus cannot be yanked. - Undo highlight does not undo it :: Overlays are not part of the undo list; you cannot undo highlighting. Use ~org-remark-remove~ or ~org-remark-delete~ commands instead. - Moving source files and marginal notes files :: Moving your files and remark file to another directory does not update the source paths and file names stored in the marginal notes file. One way to keep the links between the source files and marginal notes files is to use relative file names with ~org-remark-source-file-name~ (default). - With ~org-remark-eww-mode~ highlights can get displaced :: This happens when the website is edited and its content changes outside Emacs -- of course this is normal for websites. Currently there is no way to fix the location of highlights. * Credits To create this package, I was inspired by the following packages. I did not copy any part of them, but borrowed some ideas from them -- e.g. saving the margin notes in a separate file. - [[https://github.com/jkitchin/ov-highlight][Ov-highlight]] :: John Kitchin's (author of Org-ref). Great UX for markers with hydra. Saves the marker info and comments directly within the Org file as Base64 encoded string. It uses overlays with using ~ov~ package. - [[https://github.com/bastibe/annotate.el][Annotate.el]] :: Bastian Bechtold's (author of Org-journal). Unique display of annotations right next to (or on top of) the text. It seems to be designed for very short annotations, and perhaps for code review (programming practice); I have seen recent issues reported when used with variable-pitch fonts (prose). - [[https://github.com/tkf/org-mode/blob/master/contrib/lisp/org-annotate-file.el][Org-annotate-file]] :: Part of Org's contrib library. It seems to be designed to annotate a whole file in a separate Org file, rather than specific text items. - [[https://github.com/IdoMagal/ipa.el][InPlaceAnnotations (ipa-mode)]] :: It looks similar to Annotate.el above. - Transient navigation feature :: To implement the transient navigation feature, I liberally copied the relevant code from a wonderful Emacs package, [[https://github.com/rnkn/binder/blob/24d55db236fea2b405d4bdc69b4c33d0f066059c/binder.el#L658-L665][Binder]] by Paul W. Rankin (GitHub user [[https://github.com/rnkn][rnkn]]). * Contributing & Feedback Create issues, discussion, and/or pull requests in the GitHub repository. All welcome. Org-remark is planned to be submitted to GNU ELPA and thus copyrighted by the [[http://fsf.org][Free Software Foundation]] (FSF). This means that anyone who is making a substantive code contribution will need to "assign the copyright for your contributions to the FSF so that they can be included in GNU Emacs" ([[https://orgmode.org/contribute.html#copyright][Org Mode website]]). Thank you. * Index - Features :PROPERTIES: :CUSTOM_ID: cindex :APPENDIX: t :INDEX: cp :DESCRIPTION: Key concepts & features :END: * Index - Commands :PROPERTIES: :APPENDIX: t :INDEX: fn :DESCRIPTION: Interactive functions :END: * Index - User Options :PROPERTIES: :APPENDIX: t :INDEX: vr :DESCRIPTION: Customizable variables & faces :END: * GNU Free Documentation License :PROPERTIES: :appendix: t :END: #+texinfo: @include fdl.texi # Local Variables: # time-stamp-start: "modified +\\\\?" # End: ================================================ FILE: docs/resources/manual.css ================================================ /* Style-sheet to use for Emacs manuals */ /* Copyright (C) 2013-2022 Free Software Foundation, Inc. Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty. */ @import url('style.css'); /* makeinfo convert @deffn and similar functions to something inside
. style.css uses italic for blockquote. This looks poor in the Emacs manuals, which make extensive use of @defun (etc). In particular, references to function arguments appear as inside
. Since is also italic, it makes it impossible to distinguish variables. We could change to e.g. bold-italic, or normal, or a different color, but that does not look as good IMO. So we just override blockquote to be non-italic. */ blockquote { font-style: normal; } var { font-style: italic; } ================================================ FILE: docs/resources/reset.css ================================================ /* Software License Agreement (BSD License) Copyright (c) 2006, Yahoo! Inc. All rights reserved. Redistribution and use of this software in source and binary forms, with or without modification, arepermitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ html { color: #000; background: #FFF; } body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td { margin: 0; padding: 0; } table { border-collapse: collapse; border-spacing: 0; } fieldset, img { border: 0; } address, caption, cite, code, dfn, em, strong, th, var, optgroup { font-style: inherit; font-weight: inherit; } del, ins { text-decoration: none; } li { list-style:none; } caption, th { text-align: left; } h1, h2, h3, h4, h5, h6 { font-size: 100%; font-weight: normal; } q:before, q:after { content:''; } abbr, acronym { border: 0; font-variant: normal; } sup { vertical-align: baseline; } sub { vertical-align: baseline; } legend { color: #000; } input, button, textarea, select, optgroup, option { font-family: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; } input, button, textarea, select { *font-size: 100%; } ================================================ FILE: docs/resources/style.css ================================================ /* This stylesheet is used by manuals and a few older resources. */ @import url('reset.css'); /*** PAGE LAYOUT ***/ html, body { font-size: 1em; text-align: left; text-decoration: none; } html { background-color: #e7e7e7; } body { max-width: 74.92em; margin: 0 auto; padding: .5em 1em 1em 1em; background-color: white; border: .1em solid #c0c0c0; } /*** BASIC ELEMENTS ***/ /* Size and positioning */ p, pre, li, dt, dd, table, code, address { line-height: 1.3em; } h1 { font-size: 2em; margin: 1em 0 } h2 { font-size: 1.50em; margin: 1.0em 0 0.87em 0; } h3 { font-size: 1.30em; margin: 1.0em 0 0.87em 0; } h4 { font-size: 1.13em; margin: 1.0em 0 0.88em 0; } h5 { font-size: 1.00em; margin: 1.0em 0 1.00em 0; } p, pre { margin: 1em 0; } pre { overflow: auto; padding-bottom: .3em; } ul, ol, blockquote { margin-left: 1.5%; margin-right: 1.5%; } hr { margin: 1em 0; } /* Lists of underlined links are difficult to read. The top margin gives a little more spacing between entries. */ ul li { margin: .5em 1em; } ol li { margin: 1em; } ol ul li { margin: .5em 1em; } ul li p, ul ul li { margin-top: .3em; margin-bottom: .3em; } ul ul, ol ul { margin-top: 0; margin-bottom: 0; } /* Separate description lists from preceding text */ dl { margin: 1em 0 0 0; } /* separate the "term" from subsequent "description" */ dt { margin: .5em 0; } /* separate the "description" from subsequent list item when the final
child is an anonymous box */ dd { margin: .5em 3% 1em 3%; } /* separate anonymous box (used to be the first element in
) from subsequent

*/ dd p { margin: .5em 0; } table { display: block; overflow: auto; margin-top: 1.5em; margin-bottom: 1.5em; } th { padding: .3em .5em; text-align: center; } td { padding: .2em .5em; } address { margin-bottom: 1em; } caption { margin-bottom: .5em; text-align: center; } sup { vertical-align: super; } sub { vertical-align: sub; } /* Style */ h1, h2, h3, h4, h5, h6, strong, dt, th { font-weight: bold; } /* The default color (black) is too dark for large text in bold font. */ h1, h2, h3, h4 { color: #333; } h5, h6, dt { color: #222; } a[href] { color: #005090; } a[href]:visited { color: #100070; } a[href]:active, a[href]:hover { color: #100070; text-decoration: none; } h1 a[href]:visited, h2 a[href]:visited, h3 a[href]:visited, h4 a[href]:visited { color: #005090; } h1 a[href]:hover, h2 a[href]:hover, h3 a[href]:hover, h4 a[href]:hover { color: #100070; } ol { list-style: decimal outside;} ul { list-style: square outside; } ul ul, ol ul { list-style: circle; } li { list-style: inherit; } hr { background-color: #ede6d5; } table { border: 0; } abbr,acronym { border-bottom:1px dotted #000; text-decoration: none; cursor:help; } del { text-decoration: line-through; } em { font-style: italic; } small { font-size: .9em; } img { max-width: 100%} /*** SIMPLE CLASSES ***/ .center, .c { text-align: center; } .nocenter{ text-align: left; } .underline { text-decoration: underline; } .nounderline { text-decoration: none; } .no-bullet { list-style: none; } .inline-list li { display: inline } .netscape4, .no-display { display: none; } /*** MANUAL PAGES ***/ /* This makes the very long tables of contents in Gnulib and other manuals easier to read. */ .contents ul, .shortcontents ul { font-weight: bold; } .contents ul ul, .shortcontents ul ul { font-weight: normal; } .contents ul { list-style: none; } /* For colored navigation bars (Emacs manual): make the bar extend across the whole width of the page and give it a decent height. */ .header, .node { margin: 0 -1em; padding: 0 1em; } .header p, .node p { line-height: 2em; } /* For navigation links. We can't use inline-block display to avoid wrapping because this makes the links appear much smaller than normal text on phones with Chromium (RT #1872370). */ .node a, .header a { /*display: inline-block;*/ line-height: 2em; } .node a:hover, .header a:hover { background: #f2efe4; } /* Inserts */ table.cartouche td { padding: 1.5em; } div.display, div.lisp, div.smalldisplay, div.smallexample, div.smalllisp { margin-left: 3%; } div.example { padding: .8em 1.2em .4em; } pre.example { padding: .8em 1.2em; } div.example, pre.example { margin: 1em 0 1em 3% ; -webkit-border-radius: .3em; -moz-border-radius: .3em; border-radius: .3em; border: 1px solid #d4cbb6; background-color: #f2efe4; } div.example > pre.example { padding: 0 0 .4em; margin: 0; border: none; } pre.menu-comment { padding-top: 1.3em; margin: 0; } /*** FOR WIDE SCREENS ***/ @media (min-width: 40em) { body { padding: .5em 3em 1em 3em; } div.header, div.node { margin: 0 -3em; padding: 0 3em; } } ================================================ FILE: org-remark-convert-legacy.el ================================================ ;;; org-remark-convert-legacy.el --- Convert legacy Org-marginalia files to Org-remark -*- lexical-binding: t; -*- ;; Copyright (C) 2022-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Last modified: 23 January 2025 ;; Created: 16 January 2022 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, writing, note-taking, marginal notes ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This file is part of Org-remark and contains a feature that helps users of ;; Org-marginalia (former name of Org-remark) convert their legacy ;; marginalia.org files to those compatible with Org-remark. ;; ;; (require 'org-remark-convert-legacy-data) for `org-remark' to use ;; `org-remark-convert-legacy-data' function to automatically convert legacy ;; data on save and load. Alternatively, use the same function as an ;; interactive command on a marginalia.org buffer that contains legacy ;; Org-marginalia data. ;;; Code: (require 'org) (require 'org-remark) (defun org-remark-convert-legacy-data () "Convert the legacy Org-marginalia properties to those for Org-remark. You can call this function interactively to convert the current buffer. It also gets automatically triggered when you save or load Org-remark marginal notes file if `org-remark-convert-legacy' user option is non-nil. This function checks whether or not there is at least one legacy entry with property \"marginalia-source-file\" in the current buffer. If one found, this function will: 1. Create a backup copy with the filename \"_archive\" 2. Convert all \"marginalia-*\" properties to \"org-remark-*\" equivalents - marginalia-source-file -> org-remark-file - marginalia-id -> org-remark-id - marginalia-source-beg -> org-remark-beg - marginalia-source-end -> org-remark-end This assumes that all the \"marginalia-*\" properties were used solely by Org-marginalia." (interactive) (org-with-wide-buffer ;; Check that there is at least one legacy entry in the current buffer (goto-char (point-min)) (when (save-excursion (org-find-property "marginalia-source-file")) ;; Do the process only when there is at least one entry ;; Create a backup copy (let ((filename (abbreviate-file-name (concat (buffer-file-name) "_archive")))) (write-region (point-min) (point-max) filename) (message (format "org-remark: created backup file %s" filename))) ;; Scan the whole marginal notes file (while (not (org-next-visible-heading 1)) (when-let (source-file (org-entry-get (point) "marginalia-source-file")) (org-delete-property "marginalia-source-file") (org-set-property org-remark-prop-source-file source-file)) (when-let ((id (org-entry-get (point) "marginalia-id")) (beg (string-to-number (org-entry-get (point) "marginalia-source-beg"))) (end (string-to-number (org-entry-get (point) "marginalia-source-end")))) (org-delete-property "marginalia-id") (org-delete-property "marginalia-source-beg") (org-delete-property "marginalia-source-end") (org-set-property org-remark-prop-id id) (let ((props '())) (plist-put props org-remark-prop-source-beg (number-to-string beg)) (plist-put props org-remark-prop-source-end (number-to-string end)) (org-remark-notes-set-properties props)))) (goto-char (point-min)) (message (format "org-remark: Legacy \"marginalia-*\" properties updated for %s" (abbreviate-file-name (buffer-file-name)))) t))) (provide 'org-remark-convert-legacy) ;;; org-remark-convert-legacy.el ends here ================================================ FILE: org-remark-eww.el ================================================ ;;; org-remark-eww.el --- Enable Org-remark for EWW -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Authors: Vedang Manerikar ;; Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 23 December 2022 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This file is part of org-remark. ;; This feature to support for EWW was originally added by Vedang ;; Manerika with commit 5e4b27ar feat: Support taking annotations in eww ;; buffers. nobit has refactored it as a separate file. ;;; Code: (require 'eww) (require 'org-remark-global-tracking) ;;;###autoload (define-minor-mode org-remark-eww-mode "Enable Org-remark to work with EWW." :global t :group 'org-remark-eww (if org-remark-eww-mode ;; Enable (progn (add-hook 'eww-after-render-hook #'org-remark-auto-on) (add-hook 'org-remark-source-find-file-name-functions #'org-remark-eww-find-file-name) (add-hook 'org-remark-highlight-link-to-source-functions #'org-remark-eww-highlight-link-to-source)) ;; Disable (remove-hook 'eww-after-render-hook #'org-remark-auto-on) (remove-hook 'org-remark-source-find-file-name-functions #'org-remark-eww-find-file-name) (remove-hook 'org-remark-highlight-link-to-source-functions #'org-remark-eww-highlight-link-to-source))) (defun org-remark-eww-find-file-name () "Return URL without the protocol as the file name for the website. It assumes the buffer is the source website to be annotated. This function is meant to be set to hook `org-remark-source-find-file-name-functions'." (when (eq major-mode 'eww-mode) (let ((url-parsed (url-generic-parse-url (eww-current-url)))) (concat (url-host url-parsed) (url-filename url-parsed))))) (defun org-remark-eww-highlight-link-to-source (filename _point) "Return URL pointinting to the source website (FILENAME). It assumes https: This function is meant to be set to hook `org-remark-highlight-link-to-source-functions'." (when (eq major-mode 'eww-mode) ;;; FIXME we shhould not assume https? (concat "[[https://" filename "]]"))) (provide 'org-remark-eww) ;;; org-remark-eww.el ends here ================================================ FILE: org-remark-global-tracking.el ================================================ ;;; org-remark-global-tracking.el --- Track files and auto-activate Org-remark -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 15 August 2021 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; This file is part of org-remark ;;; Code: (declare-function org-remark-mode "org-remark") (defvaralias 'org-remark-notes-file-path 'org-remark-notes-file-name) (make-obsolete-variable 'org-remark-notes-file-path 'org-remark-notes-file-name "0.2.0") (defcustom org-remark-notes-file-name "marginalia.org" "Name of the file where we store highlights and marginal notes. It can be either a string or function. If it is a string, it should be a file name to the marginal notes file. The default is \"marginalia.org\". The default will result in one marginal notes file per directory. Ensure that it is an Org file. If it is a function, the default function is `org-remark-notes-file-name-function'. It returns a file name like this: \"FILE-notes.org\" by adding \"-notes.org\" as a suffix to the file name without the extension. When the buffer is not visiting a file (e.g. a website via EWW), the file name will be \"marginalia.org\" in your `user-emacs-directory'." :group 'org-remark :safe #'stringp :type '(choice (file "marginalia.org") (function org-remark-notes-file-name-function))) (defcustom org-remark-highlight-link-to-source-functions nil "Abnormal hook called to create a link to source in notes file. Each one is called with FILENAME as an argument." :group 'org-remark :type '(repeat function)) (defvar org-remark-source-find-file-name-functions nil "List of functions to get the source file name. It is an abnormal hook run with no argument and each function must return a file-name-equvalent as a string that uniquely identifies the source. The hook is run when `buffer-file-name` in source buffer returns nil, meaning the source buffer is not visiting a file. Meant to be set by extensions such as `org-remark-eww'") ;;;###autoload (define-minor-mode org-remark-global-tracking-mode "Automatically activates local minor mode `org-remark-mode'. When this global minor mode is active, a function added to `find-file-hook' will look for a marginal notes file for the file as defined by `org-remark-notes-file-path'. If it is found and readable, the function automatically activates `org-remark'." :init-value nil :lighter " ormk-auto" :global t :group 'org-remark (if org-remark-global-tracking-mode ;; Enable (add-hook 'find-file-hook #'org-remark-auto-on) ;; Disable (remove-hook 'find-file-hook #'org-remark-auto-on))) ;;; Functions (defun org-remark-notes-file-name-function () "Return a marginal notes file name for the current buffer. This is the default function for the customizing variable `org-remark-notes-file-name' for its function option. When the current buffer is visiting a file, the name of marginal notes file will be \"FILE-notes.org\", adding \"-notes.org\" as a suffix to the file name without the extension. If the current buffer is not visiting a file, the file name will be marginalia.org in your `user-emacs-directory'. If this file name is not suitable, either override the function or set the user option to use your own custom function." (if buffer-file-name (let ((source-filename (org-remark-source-find-file-name))) (when (and (stringp source-filename) (file-exists-p source-filename)) (concat (file-name-sans-extension (file-name-nondirectory source-filename)) "-notes.org"))) ;; If buffer is not visiting a file, we use the default file name. ;; If this file name is not suitable, either override the function ;; or set the user option to a custom function. (expand-file-name "marginalia.org" user-emacs-directory))) (defalias 'org-remark-notes-file-path-function 'org-remark-notes-file-name-function) (make-obsolete 'org-remark-notes-file-path-function 'org-remark-notes-file-name-function "0.2.0" ) ;;;; Private Functions (defun org-remark-auto-on () "Automatically activates `org-remark-mode' for current buffer when relevant. This function is meant to be added to `find-file-hook' by `org-remark-global-tracking-mode'." (when-let (notes-file (org-remark-notes-get-file-name)) (when (file-readable-p notes-file) (unless (featurep 'org-remark) (require 'org-remark)) (org-remark-mode +1)))) (cl-defgeneric org-remark-notes-get-file-name () "Return the name of marginal notes file for current buffer.") (cl-defmethod org-remark-notes-get-file-name () "Return the name of marginal notes file for current buffer. This method is major modes derived from `text-mode'." (if (functionp org-remark-notes-file-name) (funcall org-remark-notes-file-name) (if buffer-file-name org-remark-notes-file-name (expand-file-name org-remark-notes-file-name user-emacs-directory)))) (defun org-remark-source-find-file-name () "Return the filename for the source buffer. We use this filename to identify the source buffer in all operations related to marginal notes. Assumes that we are currently in the source buffer." (let ((filename (or (and (not (derived-mode-p 'special-mode)) buffer-file-name) (run-hook-with-args-until-success 'org-remark-source-find-file-name-functions)))) filename)) (provide 'org-remark-global-tracking) ;;; org-remark-global-tracking.el ends here ================================================ FILE: org-remark-icon.el ================================================ ;;; org-remark-icon.el --- Enable Org-remark to use icons -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 29 July 2023 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; Code: (require 'cl-macs) ;; Silence compiler (defvar org-remark-default-feature-modes) (defgroup org-remark-icon nil "Enable `org-remark' to display glyph/icon indicators." :group 'org-remark :prefix "org-remark-icon" :link '(url-link :tag "GitHub" "https://github.com/nobiot/org-remark")) (defcustom org-remark-icon-notes "(*)" "String to be displayed when notes exist for a given highlight. You can set a function to this user option. In this case, the function must take one argument, which is FACE. FACE can be a named face (a symbol), or an anonymous face (plist of face attributes). The function can ignore them and set its own face and/or text-property to the string. This means you can return a string with a display property to show an SVG icon instead of the underlying string. Nil means no icon is to be displayed. If you wants to use image icons (e.g. SVG image icon created with package `icons', available Emacs 29.1 or higher), you're limited to a single character with no space before and after the character. This limitation does not apply to string of characters without images, but it is generally assumed that the the value set to this customizing variable will be a short string (e.g 3 characters long with a pair of parentheses before and after a single character, such as the default value.)" :safe #'stringp :type '(choice (string "(*)") (function))) (defcustom org-remark-icon-position-adjusted "(d)" "String to be displayed when a highlight position adjusted. You can set a function to this user option. In this case, the function must take one argument, which is FACE. FACE can be a named face (a symbol), or an anonymous face (plist of face attributes). The function can ignore them and set its own face and/or text-property to the string. This means you can return a string with a display property to show an SVG icon instead of the underlying string. Nil means no icon is to be displayed. If you wants to use image icons (e.g. SVG image icon created with package `icons', available Emacs 29.1 or higher), you're limited to a single character with no space before and after the character. This limitation does not apply to string of characters without images, but it is generally assumed that the the value set to this customizing variable will be a short string (e.g 3 characters long with a pair of parentheses before and after a single character, such as the default value." :safe #'stringp :type '(choice (string "(d)") (function))) ;; Register a mode for automatic enablement at the same time as ;; `org-remark-mode'. (add-to-list 'org-remark-default-feature-modes #'org-remark-icon-mode) ;;;###autoload (define-minor-mode org-remark-icon-mode "Enable Org-remark to display icons. The icons currently available are defined in `org-remark-icons'." :global nil :group 'org-remark (if org-remark-icon-mode ;; Enable (progn (add-hook 'org-remark-highlights-toggle-hide-functions #'org-remark-icon-toggle-hide nil :local) (add-hook 'org-remark-highlights-toggle-show-functions #'org-remark-icon-toggle-show :local) ;; Add-icons should be the last function because other functions may do ;; something relevant for an icon -- e.g. adjust-positon." (add-hook 'org-remark-highlights-after-load-functions #'org-remark-highlights-add-icons-maybe 80 :local)) ;; Disable (remove-hook 'org-remark-highlights-toggle-hide-functions #'org-remark-icon-toggle-hide :local) (remove-hook 'org-remark-highlights-toggle-show-functions #'org-remark-icon-toggle-show :local) (remove-hook 'org-remark-highlights-after-load-functions #'org-remark-highlights-add-icons-maybe :local))) (defvar org-remark-icons (list (list 'notes #'org-remark-icon-notes-p nil) (list 'position-adjusted #'org-remark-icon-position-adjusted-p 'org-remark-highlighter-warning)) "List of icons enabled. It is an alist. Each element is a list of this form: (ICON-NAME PREDICATE DEFAULT-FACE) ICON-NAME must be a symbol such as \\='notes\\=' and \\='position-adjusted\\='. They are used as a suffix to be added to \\='org-remark-icon-\\=' to form a customizing variable such as `org-remark-icon-notes' and `org-remark-icon-position-adjusted'. PREDICATE must be a function that accepts one argument OV, which is the highlight overlay. If PREDICATE returns non-nil, the icon for ICON-NAME will be added to the highlight. DEFAULT FACE must be a named face. It is optinal and can be nil.") (defun org-remark-icon-notes-p (ov) (and org-remark-icon-notes (overlay-get ov '*org-remark-note-body))) (defun org-remark-icon-position-adjusted-p (ov) (and org-remark-icon-position-adjusted (overlay-get ov '*org-remark-position-adjusted))) (defun org-remark-icon-toggle-hide (highlight) (overlay-put highlight '*org-remark-icons (overlay-get highlight 'after-string)) (overlay-put highlight 'after-string nil)) (defun org-remark-icon-toggle-show (highlight) (overlay-put highlight 'after-string (overlay-get highlight '*org-remark-icons)) (overlay-put highlight '*org-remark-icons nil)) (defun org-remark-highlights-add-icons-maybe (overlays _notes-buf) "Add icons to OVERLAYS. Each overlay is a highlight." (dolist (ov overlays) ;; icons added to line highlighters differently from normal ones. (cl-flet ((add-icon-maybe (icon) (cl-destructuring-bind (icon-name pred default-face) icon (when (funcall pred ov) (org-remark-icon-propertize icon-name ov default-face))))) (let ((icon-string ;; The third arg of `mapconcat' is not optional in Emacs 28 or lower. (mapconcat #'add-icon-maybe org-remark-icons nil))) (when (length> icon-string 0) (org-remark-icon-overlay-put ov icon-string (overlay-get ov 'org-remark-type))))))) (cl-defgeneric org-remark-icon-overlay-put (_ov _icon-string _org-remark-type) "Default method to deal with icon. This is used when a method specific \\='org-remark-type\\=' not implemented." (ignore)) (cl-defmethod org-remark-icon-overlay-put (ov icon-string (_org-remark-type (eql nil))) (overlay-put ov 'after-string icon-string)) (defun org-remark-icon-propertize (icon-name highlight default-face) "Return a propertized string. ICON-NAME is a symbol such as \\='notes\\=' and \\='position-adjusted\\='. They are used as a suffix to be added to \\='org-remark-icon-\\=' to form an ICON, which is a customizing variable such as `org-remark-icon-notes' and `org-remark-icon-position-adjusted'. HIGHLIGHT is the current highlight overlay being worked on. It is useful to obtain its face to add the matching face to the icon (HIGHLIGHT-FACE). DEFAULT-FACE is the default face for the ICON. It can be nil, in which case the face of the HIGHLIGHT should be used. This depends on the value of ICON. ICON is a customizing variable, it can be set to a string. In this case, the DEFAULT-FACE is used when available; if not, HIGHLIGHT-FACE. ICON can also be a function. In this case, three arguments are pass to it: ICON-NAME, HIGHLIGHT-FACE, and DEFAULT-FACE. It is up to the function whether or not to use any of them. All it needs to do is to return a string that represents an icon, typically propertized with a face." (let ((icon (symbol-value (intern (concat "org-remark-icon-" (symbol-name icon-name))))) (highlight-face (org-remark-icon-highlight-get-face highlight (overlay-get highlight 'org-remark-type))) (default-face default-face)) (if (functionp icon) (funcall icon icon-name highlight-face default-face) (propertize icon 'face (if default-face default-face highlight-face))))) (cl-defgeneric org-remark-icon-highlight-get-face (highlight _org-remark-type) "Return the face of the HIGHLIGHT overlay. This is default method for range-highlights." (overlay-get highlight 'face)) (provide 'org-remark-icon) ;;; org-remark-icon.el ends here ================================================ FILE: org-remark-info.el ================================================ ;;; org-remark-info.el --- Support Org-remark with Info-mode -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 16 July 2023 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;; This file is an Org-remark extension to add highlights and ;; annotation support for Info-mode. ;; ;; The extension can be enabled globally with `org-remark-info-mode' ;; ;; Highlights will include the links to the original with using ;; `ol-info' (Org mode's info: link type). By default, it opens the ;; node within the same window as the Org buffer, which is not ;; convenient for the purpose of Org-remark. You can configure Emacs to ;; open info: link into another window. See an example of such a ;; customization below: ;; ;; (setopt switch-to-buffer-obey-display-actions t) ;; (add-to-list 'display-buffer-alist ;; '("\*info\*.*" ;; (display-buffer-reuse-mode-window) ;; (mode . Info-mode))) ;; ;; You will need to use `org-remark-info-mode' in conjunction with ;; `org-remark-global-tracking-mode' and `org-remark-mode'. For more, ;; refer to the following Info node: ;; ;; - Info node `(org-remark) Installation' ;; - Info node `(org-remark) Getting Started' ;;; Code: (require 'ol-info) (require 'info) (require 'org-remark-global-tracking) (defvar org-remark-prop-source-file) (defvar org-remark-mode) (declare-function org-remark-highlights-load "org-remark") (declare-function org-remark-mode "org-remark") ;;;###autoload (define-minor-mode org-remark-info-mode "Enable Org-remark to work with `Info-mode' for Info documentation reader." :global t :group 'org-remark-info (if org-remark-info-mode ;; Enable (progn (add-hook 'org-remark-source-find-file-name-functions #'org-remark-info-get-node) (add-hook 'org-remark-highlight-link-to-source-functions #'org-remark-info-link) (add-hook 'Info-selection-hook #'org-remark-info-highlights-load)) ;; Disable (remove-hook 'org-remark-source-find-file-name-functions #'org-remark-info-get-node) (remove-hook 'org-remark-highlight-link-to-source-functions #'org-remark-info-link) (remove-hook 'Info-selection-hook #'org-remark-info-highlights-load))) (defun org-remark-info-highlights-load (&rest _args) "Wrapper for `org-remark-highlights-load'. It is necessary as this function is intended to be used as part of advice for `Info-goto-node', which gets arguments passed to it. `org-remark-highlights-load' should be called with no arguments for the purpose of `org-remark-info-mode'." ;; Enabling `org-remark-mode' runs `org-remark-highlights-load', which ;; would result in duplicating the highlights. As this function should ;; be run only once for initial load or only once for subsequent ;; re-load. This `if' statement is to differentiate the initial load ;; when no Info node has been opened from subsequent reloads when the ;; user moves to another Info node. In addition, `featurep' is used ;; because variable `org-remark-mode' may not have been loaded yet to ;; avoid symbol void. (if (or (not (featurep 'org-remark)) (not org-remark-mode)) (org-remark-mode +1) (org-remark-highlights-load))) (defun org-remark-info-get-node () "Return the current Info file/node." (when (eq major-mode 'Info-mode) (concat (file-name-nondirectory Info-current-file) "/" Info-current-node))) (defun org-remark-info-link (_filname _point) "Return \"info:\" link with current point in `Info-mode' buffer. This function only works when the mode is `Info-mode'. Assume the point is on the highlight in source Info document buffer and `ol-info' is loaded. The latter is necessary for `org-store-link' to work wiht Info buffer." (when (eq major-mode 'Info-mode) (org-store-link nil nil))) (cl-defmethod org-remark-highlight-get-constructors (&context (major-mode Info-mode)) "Construct lists for creating MAJOR-MODE specific hierarchy. This method is for `Info-mode'. Return the value in a alist like this: (SOURCE-FILENAME-FN TITLE-FN PROP-TO-FIND)" (let* ((headline-1 (list ;; SOURCE-FILENAME-FN ;; Don't include the full directory path for Info ;; node. This may change when Emacs version or ;; package version changes. (lambda () (file-name-nondirectory Info-current-file)) ;; TITLE-FN (lambda () (file-name-nondirectory Info-current-file)) ;; PROP-TO-FIND "org-remark-info-file")) (headline-2 (list ;; SOURCE-FILENAME-FN #'org-remark-info-get-node ;; TITLE-FN (lambda () Info-current-node) ;; PROP-TO-FIND org-remark-prop-source-file)) (headline-constructors (list headline-1 headline-2))) headline-constructors)) (provide 'org-remark-info) ;;; org-remark-info.el ends here ================================================ FILE: org-remark-line.el ================================================ ;;; org-remark-line.el --- Enable Org-remark to highlight a line -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 01 August 2023 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; Code: (require 'org-remark) (defgroup org-remark-line nil "Enable`org-remark' to highlight and annotate whole lines." :group 'org-remark :prefix "org-remark-line" :link '(url-link :tag "GitHub" "https://github.com/nobiot/org-remark")) (defcustom org-remark-line-icon " * " "Glyph displayed on the margin to indicate the line-highlight. If you wants to use image icons (e.g. SVG image icon created with package `icons', available Emacs 29.1 or higher), you're limited to a single character with no space before and after the character. This limitation does not apply to string of characters without images, but it is generally assumed that the the value set to this customizing variable will be a short string (e.g 3 characters long with a padding spaces before and after a single character, such as the default value.)" :local t :type 'string :safe 'stringp) (defcustom org-remark-line-minimum-margin-width 3 "Margin width in a natural number. It can be a single number or a cons cell of two. When it is a single number, both the left and right margin widths will be the same. When this customizing variable is a cons cell, the format is as follows: (LEFT-MARGIN-WIDTH . RIGHT-MARGIN-WIDTH)." :local t :type '(choice (natnum :tag "Minimum margin width for both left and right margins" 3) (cons :tag "Left and right margin widths" natnum natnum))) (defcustom org-remark-line-margin-padding 1 "Padding between the main text area the glyph/icon on the margin." :local t :type 'natnum) (defcustom org-remark-line-margin-side 'left-margin "The side of margin to display line highlights. Left or right can be chosen." :local t :type '(radio (const :tag "Left margin" left-margin) (const :tag "Right margin" right-margin))) (defcustom org-remark-line-heading-title-max-length 40 "Maximum length of string included as the highlight title." :type 'natnum) (defcustom org-remark-line-ellipsis "…" "Ellipsis used when the highlight title is longer than maximum. The maximum is set in `org-remark-line-heading-title-max-length'." :type 'string :safe 'stringp) (defface org-remark-line-highlighter '((((class color) (min-colors 88) (background light)) :foreground "#dbba3f" :inherit default) (((class color) (min-colors 88) (background dark)) :foreground "#e2d980" :inherit default) (t :inherit highlight)) "Face for the default line highlighter pen.") (defvar-local org-remark-line-minimum-left-margin-width nil "Computed minimum `left-margin' width.") (defvar-local org-remark-line-minimum-right-margin-width nil "Computed minimum `right-margin' width.") (defvar-local org-remark-line-margins-original '() "Original window margin width values. It is the original margins returned by function `window-margins' in cons cell (or nil) before function `org-remark-line-set-window-margins' set margins.") (defvar-local org-remark-line-margins-set-p nil "Status indicating if margins are set by `org-remark-line'.") ;;;###autoload (define-minor-mode org-remark-line-mode "Enable Org-remark to highlight and annotate the whole line." :global nil :group 'org-remark (if org-remark-line-mode ;; Enable (progn ;; Depth is deeper than the default one for range-highlight. ;; This is to prioritize it over line-highlight when the fomer ;; is at point and yet on the same line of another ;; line-highlight. (add-hook 'org-remark-find-dwim-functions #'org-remark-line-find 80 :local) ;; olivetti sets DEPTH to t (=90). We need go lower priority than it (add-hook 'window-size-change-functions #'org-remark-line-set-window-margins 95 :local) ;; Need to reload to cater to margin changes done by `olivetti'. (add-hook 'window-size-change-functions #'org-remark-line-highlights-redraw 96 :local) (add-hook 'org-remark-highlight-other-props-functions #'org-remark-line-prop-line-number-get) (org-remark-line-set-window-margins)) ;; Disable (remove-hook 'org-remark-find-dwim-functions #'org-remark-line-find :local) (remove-hook 'window-size-change-functions #'org-remark-line-set-window-margins :local) (remove-hook 'window-size-change-functions #'org-remark-line-highlights-redraw :local) (remove-hook 'org-remark-highlight-other-props-functions #'org-remark-line-prop-line-number-get) (when org-remark-line-margins-set-p (setq left-margin-width (car org-remark-line-margins-original)) (setq right-margin-width (cdr org-remark-line-margins-original)) (set-window-margins nil left-margin-width right-margin-width) (set-window-buffer (get-buffer-window) (current-buffer) nil) (setq org-remark-line-minimum-left-margin-width nil) (setq org-remark-line-minimum-right-margin-width nil) (setq org-remark-line-margins-set-p nil)))) ;; Default line-highlighter pen ;;;###autoload (defun org-remark-mark-line (_beg _end &optional _id _mode) "Apply face to the region selected by BEG and END. Dummy function definition to let autoload work. The actual implementation is added when this library is loaded and macro `org-remark-create' creates the actual function.") (org-remark-create "line" `org-remark-line-highlighter `(org-remark-type line)) (defun org-remark-line-set-window-margins (&optional window) "Set the margins of WINDOW or window that displays current buffer. Return a cons of the form (LEFT-WIDTH . RIGHT-WIDTH). If a marginal area does not exist, return nil." (let ((window (or window (get-buffer-window)))) (when (and (windowp window) (not (window-minibuffer-p window))) (cl-destructuring-bind (left-width . right-width) (window-margins) (unless org-remark-line-margins-set-p (setq org-remark-line-margins-original (window-margins)) (setq org-remark-line-margins-set-p t) (setq org-remark-line-minimum-left-margin-width (+ (if (numberp org-remark-line-minimum-margin-width) org-remark-line-minimum-margin-width (car org-remark-line-minimum-margin-width)) org-remark-line-margin-padding)) (setq org-remark-line-minimum-right-margin-width (+ (if (numberp org-remark-line-minimum-margin-width) org-remark-line-minimum-margin-width (cdr org-remark-line-minimum-margin-width)) org-remark-line-margin-padding))) (if (or (eq left-width nil) (< left-width org-remark-line-minimum-left-margin-width)) (setq left-margin-width org-remark-line-minimum-left-margin-width) (setq left-margin-width left-width)) (if (or (eq right-width nil) (< right-width org-remark-line-minimum-right-margin-width)) (setq right-margin-width org-remark-line-minimum-right-margin-width) (setq right-margin-width right-width)) ;; For `set-window-margins' window should be specified. ;; Howerver, `set-window-buffer' should get nil for window. ;; Otherwise, the minibuffer also gets the margins. It's a ;; little tricky behaviour. Both functions seem to be required. ;; The former changes the current window's margin display ;; immediately. The latter makes the margin widths the default ;; for future, when window gets split, etc. (set-window-margins window left-margin-width right-margin-width) (set-window-buffer nil (current-buffer) 'keep-margins) (window-margins))))) (defun org-remark-line-pos-bol (pos) "Return the beginning of the line position for POS." (save-excursion (goto-char pos) (pos-bol))) (defun org-remark-line-highlight-p (highlight) "Return t if HIGHLIGHT is one for the line. HIGHLIGHT is an overlay." (eql 'line (overlay-get highlight 'org-remark-type))) (defun org-remark-line-find (&optional point) "Return the line-highight (overlay) of the current line. When POINT is passed, one for the line it belongs to. If there are multiple line-hilights, return the car of the list returned by `overlays-in'." (let* ((point (or point (point))) (bol (org-remark-line-pos-bol point)) (highlights (overlays-in bol bol))) (seq-find #'org-remark-line-highlight-p highlights))) (defun org-remark-line-prop-line-number-get (highlight) "Return the line number for HIGHLIGHT overlay. This happens only when HIGHLIGHT is a line-highlight." (when (org-remark-line-highlight-p highlight) (list 'org-remark-line-number (number-to-string (org-current-line (overlay-start highlight)))))) (cl-defmethod org-remark-beg-end ((_org-remark-type (eql 'line))) "Return beg and end for ORG-REMARK-TYPE line." (let ((bol (org-remark-line-pos-bol (point)))) (list bol bol))) (defun org-remark-line-make-spacer-overlay (pos) "Return a spacer overlay at POS." (let* ((left-margin (or (car (window-margins)) left-margin-width)) ;;(right-margin (or (cdr (window-margins)) right-margin-width)) (string-length (length org-remark-line-icon)) (spaces-base-length (if (eql org-remark-line-margin-side 'right-margin) org-remark-line-margin-padding (- left-margin (+ string-length org-remark-line-margin-padding)))) (spaces-length (if (> spaces-base-length 0) spaces-base-length 0)) (spacer-ov (make-overlay pos pos nil :front-advance))) ;; Add a spacing overlay before the line-highlight overlay but we ;; only need one of these; remove it if one already exits (remove-overlays (overlay-start spacer-ov) (overlay-end spacer-ov) 'category 'org-remark-spacer) (overlay-put spacer-ov 'before-string (propertize " " 'display `((margin ,org-remark-line-margin-side) (space . (:width ,spaces-length))))) (overlay-put spacer-ov 'category 'org-remark-spacer) spacer-ov)) (defun org-remark-line-highlights-redraw (&optional window) "Redraw line-highlights to adjust the spaces/padding. When WINDOW is nil, this function gets window that current buffer is displayed." (let ((window (or window (get-buffer-window)))) (when (and (windowp window) (not (window-minibuffer-p window))) (org-with-wide-buffer (let ((highlights (seq-filter (lambda (ov) (eql 'line (overlay-get ov 'org-remark-type))) org-remark-highlights))) (dolist (ov highlights) (let* ((beg (overlay-start ov)) (spacer-ov (org-remark-line-make-spacer-overlay beg)) (copied-highlight (copy-overlay ov)) (display-props (get-text-property 0 'display (overlay-get copied-highlight 'before-string)))) (setf (car display-props) `(margin ,org-remark-line-margin-side)) (push copied-highlight org-remark-highlights) (copy-overlay spacer-ov) (delete-overlay ov) (org-remark-highlights-housekeep) (org-remark-highlights-sort)))))))) (defun org-remark-line-highlight-propertize (ov icon-string) "Propertize ICON-STRING and add it to OV." ;; If the icon-string has a display properties, assume it is an icon image (let ((display-prop (get-text-property 0 'display icon-string))) (cond (display-prop ; svg-based icon (let* ((display-prop (list `(margin ,org-remark-line-margin-side) display-prop)) ;; TODO margin needs to be calculated ;; (list `(margin ,org-remark-line-margin-side) ;; (append display-prop '(:margin (10 . 0)))))) (icon-face (get-text-property 0 'face icon-string)) (icon-string (propertize " " 'display display-prop))) (when icon-face (setq icon-string (propertize icon-string 'face icon-face))) (overlay-put ov 'before-string icon-string))) (icon-string ; text/string-based icon (let ((icon-string icon-string)) (overlay-put ov 'before-string (propertize " " 'display (list `(margin ,org-remark-line-margin-side) icon-string))))) (t (ignore))))) (cl-defmethod org-remark-highlight-make-overlay (beg end face (_org-remark-type (eql 'line))) "Make and return a highlight overlay in BEG END for line-highlight. This function adds FACE to line icon string. If FACE is nil, this function uses default `org-remark-line-highlighter'. Return nil when no window is created for current buffer." (when (get-buffer-window) (unless org-remark-line-mode (org-remark-line-mode +1)) (let* ((face (or face 'org-remark-line-highlighter)) (string (propertize org-remark-line-icon 'face face)) (spacer-ov (org-remark-line-make-spacer-overlay beg)) (ov (make-overlay beg end nil :front-advance))) ;; line-highlight overlay (org-remark-line-highlight-propertize ov string) ;; Let highlight overlay to take care of the spacer movement (overlay-put ov 'insert-in-front-hooks (list 'org-remark-line-highlight-modified)) ;; Copy spacer overlay. It is put after the line-highlight to ;; limit and reset the face added by the line-highlight back to ;; default. This is especially done for RTL languages and when the ;; face include a background color different from that of default. ;; Without it, the background color goes all the way to the end of ;; the right margin. (copy-overlay spacer-ov) ov))) (defun org-remark-line-highlight-find-spacers (pos) "Find the two spacers for POS." (let ((highlights (overlays-in pos pos))) (seq-filter (lambda (ov) (eql 'org-remark-spacer (overlay-get ov 'category))) highlights))) (defun org-remark-line-highlight-modified (ov after-p beg _end &optional _length) "Move spacers and lighlight OV to follow the point. Without this function, the line-highlighter mark does not move when the user press RET to add a newline at the beginning of the line-highlight. This is unintuitive for the user. This function is meant to be added to insert-in-front-hooks of the overlay that represents line-highlight. It must be called AFTER-P is non-nil and move BEG to one position forward." (when after-p (save-excursion (goto-char beg) (when (looking-at "\n") ;; The sequence must be 1. spacer; 2. highlight 3. spacer (let ((spacers (org-remark-line-highlight-find-spacers beg))) (when spacers (move-overlay (pop spacers) (1+ beg) (1+ beg))) (move-overlay ov (1+ beg) (1+ beg)) (when spacers (move-overlay (pop spacers) (1+ beg) (1+ beg)))))))) (cl-defmethod org-remark-highlight-headline-text (ov (_org-remark-type (eql 'line))) "Return the first N characters of the highlighted line OV. N is customized with `org-remark-line-heading-title-max-length'. If the line starts with any space or tab, they will be trimmed. If the line (after trimming) is shorter than N, then this function will include the charcters up to the newline char. In addition, if the text happens to be empty, the function uses \"Empty line highlight\" as the fallback; headlines with no title is not considered valid for the purpose of `org-remark' and thus risks unexpected results (mostly the highlight skipped when loading highlights)." (let ((line-text (buffer-substring-no-properties (overlay-start ov) (pos-eol)))) (if (or (eq line-text nil) (string= line-text "")) "Empty line highlight" (setq line-text (string-trim-left line-text)) (if (length< line-text (1+ org-remark-line-heading-title-max-length)) line-text (concat (substring line-text 0 org-remark-line-heading-title-max-length) org-remark-line-ellipsis))))) (cl-defmethod org-remark-highlights-adjust-positions-p ((_org-remark-type (eql 'line))) "Return t if adjust-positions feature is relevant. For line-highlights, adjust-positions is not relevant." nil) (cl-defmethod org-remark-highlights-housekeep-delete-p (_ov (_org-remark-type (eql 'line))) "Always return nil when ORG-REMARK-TYPE is \\='line\\='. Line-highlights are designed to be zero length with the start and end of overlay being identical." nil) (cl-defmethod org-remark-highlights-housekeep-per-type (ov (_org-remark-type (eql 'line))) "Ensure line-highlight OV is always at the beginning of line." ;; if `pos-bol' is used to move, you can actually get the highlight to ;; always follow the point, keeping the original place unless you ;; directly change the notes. That's not really an intutive behaviour, ;; though in some cases, it imay be useful. ;; (if (not (overlay-start ov)) (delete-overlay ov) (when (overlay-buffer ov) (let* ((ov-start (overlay-start ov)) (ov-line-bol (org-remark-line-pos-bol ov-start))) (unless (= ov-start ov-line-bol) (move-overlay ov ov-line-bol ov-line-bol))))) (cl-defmethod org-remark-icon-overlay-put (ov icon-string (_org-remark-type (eql 'line))) "Add ICON-STRING to OV. Each overlay is a highlight. Return nil when no window is created for current buffer." (when (get-buffer-window) (org-remark-line-highlight-propertize ov icon-string))) (cl-defmethod org-remark-icon-highlight-get-face (highlight (_org-remark-type (eql 'line))) "Return the face of HIGHLIGHT in margin for line-highlight." (let* ((before-string (overlay-get highlight 'before-string)) (face (get-text-property 0 'face before-string))) ;; When the highlight already is an SVG icon, face is in the display ;; property of before-string (unless face (let ((display-string (cadr (get-text-property 0 'display before-string)))) (when (stringp display-string) (setq face (get-text-property 0 'face display-string))))) face)) (provide 'org-remark-line) ;;; org-remark-line.el ends here ================================================ FILE: org-remark-nov.el ================================================ ;;; org-remark-nov.el --- Compatibility with nov-mode -*- lexical-binding: t; -*- ;; Copyright (C) 2021-2025 Free Software Foundation, Inc. ;; Author: Noboru Ota ;; URL: https://github.com/nobiot/org-remark ;; Created: 9 January 2023 ;; Last modified: 23 January 2025 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp ;; This file is not part of GNU Emacs. ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;; This feature would not have been possible without the collaboration ;; with Tan Yin Hoe (GitHub user sati-bodhi). ;; ;; This file is an Org-remark extension to add highlights and ;; annotation support for EPUB books rendered by nov.el [1]. Org-remark ;; does not automatically install nov.el. Users are expected to obtain ;; it separately, for example, via MELPA. ;; ;; The extension can be enabled globally with `org-remark-nov-mode'. ;; You will need to use it in conjunction with ;; `org-remark-global-tracking-mode' and `org-remark-mode'. For more, ;; refer to the following Info node: ;; ;; - Info node `(org-remark) Installation' ;; - Info node `(org-remark) Getting Started' ;; ;; [1]: ;;; Code: (if (locate-library "nov") (require 'nov) (error "Org-remark: package `nov' is missing")) (require 'org-remark-global-tracking) (declare-function org-remark-highlights-load "org-remark") (declare-function org-store-link "ol") (defvar org-remark-prop-source-file) ;; To silence flymake (defvar nov-file-name) (defvar nov-documents) (defvar nov-documents-index) (defvar nov-metadata) ;;;###autoload (define-minor-mode org-remark-nov-mode "Enable Org-remark to work with `nov-mode' for eub." :global t :group 'org-remark-nov (if org-remark-nov-mode ;; Enable (progn (add-hook 'org-remark-source-find-file-name-functions #'org-remark-nov-get-epub-source) (add-hook 'org-remark-highlight-link-to-source-functions #'org-remark-nov-link) ;; When users turn the page (document in nov-mode's terminology) ;; `nov-mode' will erase the current buffer and render the new ;; document content in the same buffer. This means the ;; highlights currently displayed get removed; the ones for the ;; new document need to be loaded document after `nov-mode' ;; renders the new document. (add-hook 'nov-post-html-render-hook #'org-remark-highlights-load)) ;; Disable (remove-hook 'org-remark-source-find-file-name-functions #'org-remark-nov-get-epub-source) (remove-hook 'org-remark-highlight-link-to-source-functions #'org-remark-nov-link) (remove-hook 'nov-post-html-render-hook #'org-remark-highlights-load))) (cl-defmethod org-remark-notes-get-file-name (&context (major-mode nov-mode)) "Return the name of marginal notes file for current buffer. This method is for `nov-mode' MAJOR-MODE." (let ((filename (cond (;; if `org-remark-notes-file-name' is a user's custom function, use it as is. (and (functionp org-remark-notes-file-name) (not (eq org-remark-notes-file-name #'org-remark-notes-file-name-function))) (funcall org-remark-notes-file-name)) ;; if it is a default function, then do something different for nov.el. ((functionp org-remark-notes-file-name) (concat (file-name-sans-extension nov-file-name) "-notes.org")) ;; the only other case is a string. Assume the default ;; marginalia.org but it should be the same for custom ;; string. (t org-remark-notes-file-name)))) ;; Even if `org-remark-notes-file-name' is a user-defined custom ;; function, check if it is relative. If so, make it absolute by ;; adding the directory path to the epub file. The purpose is to ;; avoid the directory to be the temp file that nov.el creates for ;; the html file to be rendered. (unless (file-name-absolute-p filename) ;; major mode is nov and in the document buffer. (setq filename (expand-file-name filename (file-name-directory nov-file-name)))) filename)) (defun org-remark-nov-get-epub-source () "Return the path of the epub source from which the present session is initiated." (when (eq major-mode 'nov-mode) (concat (file-name-nondirectory nov-file-name) "/" (file-name-base (cdr (aref nov-documents nov-documents-index)))))) (defun org-remark-nov-get-epub-document-title () "Return the path of the epub source from which the present session is initiated." (when (eq major-mode 'nov-mode) (let ((temp-filename (cdr (aref nov-documents nov-documents-index)))) (file-name-base temp-filename)))) (defun org-remark-nov-link (_filname _point) "Return \"nov:\" link with current point in `nov-mode' buffer. This function only works when the mode is `nov-mode'. Assume the point is on the highlight in source epub document buffer." (when (eq major-mode 'nov-mode) (org-store-link nil))) (cl-defmethod org-remark-highlight-get-constructors (&context (major-mode nov-mode)) "Construct lists for creating MAJOR-MODE specific hierarchy. Return the value in a alist like this: (SOURCE-FILENAME-FN TITLE-FN PROP-TO-FIND)" (let* ((headline-1 (list ;; SOURCE-FILENAME-FN (lambda () nov-file-name) ;; TITLE-FN (lambda () (cdr (assoc 'title nov-metadata))) ;; PROP-TO-FIND "org-remark-nov-file")) (headline-2 (list ;; SOURCE-FILENAME-FN #'org-remark-nov-get-epub-source ;; TITLE-FN #'org-remark-nov-get-epub-document-title ;; PROP-TO-FIND org-remark-prop-source-file)) (headline-constructors (list headline-1 headline-2))) headline-constructors)) (provide 'org-remark-nov) ;;; org-remark-nov.el ends here ================================================ FILE: org-remark.el ================================================ ;;; org-remark.el --- Highlight & annotate text, Info, EPUB, EWW -*- lexical-binding: t; -*- ;; Copyright (C) 2020-2025 Free Software Foundation, Inc. ;; This program is free software: you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the ;; Free Software Foundation, either version 3 of the License, or (at your ;; option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License along ;; with this program. If not, see . ;; Author: Noboru Ota ;; Created: 22 December 2020 ;; Last modified: 29 January 2025 ;; URL: https://github.com/nobiot/org-remark ;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp, ;; Version: 1.3.0 ;; Package-Requires: ((emacs "27.1") (org "9.4")) ;; This file is not part of GNU Emacs. ;;; Commentary: ;; This package lets you highlight and annotate any text file with using ;; Org mode. For usage, refer to the user manual available as an Info ;; node by evaluating (info "org remark") ;;; Code: ;;;; Requirements (require 'org) (require 'org-id) (require 'org-remark-global-tracking) (declare-function org-remark-convert-legacy-data "org-remark-convert-legacy") ;;;; Customization (defgroup org-remark nil "Highlight and annotate any text files with using Org mode." :group 'org :prefix "org-remark-" :link '(url-link :tag "GitHub" "https://github.com/nobiot/org-remark")) (defface org-remark-highlighter '((((class color) (min-colors 88) (background light)) :underline "#aecf90" :background "#ecf7ed") (((class color) (min-colors 88) (background dark)) :underline "#00422a" :background "#1d3c25") (t :inherit highlight)) "Face for the default highlighter pen.") (defface org-remark-highlighter-warning '((((class color) (min-colors 88) (background light)) :foreground "#604000" :background "#fff29a") (((class color) (min-colors 88) (background dark)) :foreground: "#e2d980" :background "#693200") (t :inherit warning)) "Face for highlighter warning. For example, it is used by the characters that indicate the location of the highlight has been automatically adjusted from its original.") (defcustom org-remark-create-default-pen-set t "When non-nil, Org-remark creates default pen set. Set to nil if you prefer for it not to." :type 'boolean) (defcustom org-remark-notes-display-buffer-action `((display-buffer-in-side-window) (side . left) (slot . 1)) "Buffer display action that Org-remark uses to open marginal notes buffer. The default is to use a side-window on the left. Org-remark uses `pop-to-buffer', which passes this display action list to `display-buffer'. Refer to its documentation for more detail and expected elements of the list." :type display-buffer--action-custom-type) (defcustom org-remark-notes-buffer-name "*marginal notes*" "Buffer name of the marginal notes buffer. `org-remark-open' and `org-remark-visit' create an indirect clone buffer with this name." :type 'string) (defcustom org-remark-notes-auto-delete nil "How Org-remark removes entries when user deletes highlights. This controls the behavior of Org-remark when the user deletes the highlight in the source (for example, when deleting a whole line including a highlight). The default behavior is to remove only the properties in the notes buffer and keeping the headline title and any notes in the entry (with using `org-remark-remove'). If this behavior leads to cluttering the marginal notes org file, you can set this customizing variable to \\=':auto-delete\\='. With this option, Org-remark will delete the entire entry when it contains no notes without a prompt asking for confirmation. This is the same behavior as passing a single `universal-argument' \(\\[universal-argument]) to`org-remark-delete' or double `universal-argument' \(\\[universal-argument] \\[universal-argument]) to `org-remark-remove'." :type '(radio (const :tag "Keep entries (default)" nil) (const :tag "Delete entries automatically when no notes exist" :auto-delete))) (defvaralias 'org-remark-source-path-function 'org-remark-source-file-name) (make-obsolete-variable 'org-remark-source-path-function 'org-remark-source-file-name "0.2.0") (defcustom org-remark-source-file-name #'file-relative-name "Function that returns the file name to point back at the source file. The function is called with a single argument: the absolute file name of source file. The `default-directory' is temporarily set to the directory where the marginal notes file resides. This means that when the \"Relative file name\" option is selected, the source file name recorded in the marginal notes file will be relative to it." :type '(choice (const :tag "Relative file name" file-relative-name) (const :tag "Abbreviated absolute file name" abbreviate-file-name) (function :tag "Other function"))) (defcustom org-remark-use-org-id nil "When non-nil, Org-remark adds an Org-ID link to marginal notes. The link points at the relevant Org-ID in the source file. Org-remark does not create this ID, which needs to be added manually or some other function to either the headline or file." :type 'boolean) (defcustom org-remark-report-no-highlights t "When non-nil, Org-remark reports that there are no highlights in the buffer. If Org-remark finds no highlights or annotations in a buffer it is enabled in, then a non-nil value means a message indicating this will be shown. Otherwise, do not show such a message." :type 'boolean) (defcustom org-remark-open-hook nil "Hook run when a note buffer is opened/visited. The current buffer is the note buffer." :type 'hook) (defcustom org-remark-highlights-after-load-functions '(org-remark-highlights-adjust-positions) "Abnormal hook run after `org-remark-highlights-load'. It is run with OVERLAYS and NOTES-BUF as arguments. OVERLAYS are highlights. It is run with the source buffer as current buffer." :type 'hook) ;;;; Variables (defvar org-remark-default-features '(org-remark-icon org-remark-line) "Extension features to be enabled by default. It is suggested to keep them as the default, but you can choose to disable them") (defvar org-remark-default-feature-modes '() "Extension minor modes to be enabled together with `org-remark-mode'. These minor modes should be registered to this variable by the respective feature where required. As an example, see `org-remark-line'.") (defvar org-remark-find-dwim-functions nil "Functions to find the highlight overlays. These functions should be registered to this variable by the respective feature where required. As an example, see `org-remark-line'.") (defvar org-remark-last-notes-buffer nil "The cloned indirect buffer visiting the notes file. It is meant to exist only one of these in each Emacs session.") (defvar org-remark-available-pens (list #'org-remark-mark) "A list of pens available. Each pen is a function. Users can create a new custom pen with using `org-remark-create', which automatically add a new pen function this list. It is used by `org-remark-change' as a selection list.") (defvar-local org-remark-highlights '() "All the highlights in current source buffer. It is a local variable and is a list of overlays. Each overlay represents a highlighted text region. On `save-buffer' each highlight will be saved in the notes file returned by `org-remark-notes-get-file-name'.") (defvar-local org-remark-highlights-hidden nil "Hidden/shown state of the highlights in current source buffer.") (defvar-local org-remark-notes-source-buffers '() "List of source buffers that have loaded current notes buffer. Each notes buffer locally keeps track of the source buffers that have loaded notes from itself. This list is used when automatic sync is triggered in `after-save-buffer' of the notes buffer, as not all the sources may be open. Buffers in this list may be killed so that this needs to be checked with `buffer-live-p'.") (defvar-local org-remark-source-setup-done nil "Local indicator that sync with notes buffer is set up.") (defvar-local org-remark-highlights-toggle-hide-functions nil "Functions to be called when toggling to hide highlights. Each function is called with one argument HIGHLIGHT, which is an overlay that shows the highlight. It also stores properties to control visibility such as \\=':face\\='. This variable is an abnormal hook and is intended to be used to add additional controls for the overlay properties.") (defvar-local org-remark-highlights-toggle-show-functions nil "Functions to be called when toggling to show highlights. Each function is called with one argument HIGHLIGHT, which is an overlay that shows the highlight. It also stores properties to control visibility such as \\=':face\\='. This variable is an abnormal hook and is intended to be used to add additional controls for the overlay properties") ;; Const for the names of properties in Org Mode (defconst org-remark-prop-id "org-remark-id") (defconst org-remark-prop-source-file "org-remark-file") (defconst org-remark-prop-source-beg "org-remark-beg") (defconst org-remark-prop-source-end "org-remark-end") ;;;; Macros to create user-defined highlighter pen functions (defmacro org-remark-create (label &optional face properties) "Create and register new highlighter pen functions. The newly created pen function will be registered to variable `org-remark-available-pens'. It is used by `org-remark-change' as a selection list. LABEL is the name of the highlighter and mandatory. The function will be named `org-remark-mark-LABEL'. The highlighter pen function will apply FACE to the selected region. FACE can be an anonymous face. When FACE is nil, this macro uses the default face `org-remark-highlighter'. PROPERTIES is a plist of pairs of a symbol and value. Each highlighted text region will have a corresponding Org headline in the notes file, and it can have additional properties in the property drawer from the highlighter pen. To do this, prefix property names with \"org-remark-\" or use \"CATEGORY\"." (if (or (not label) (stringp label) (user-error "org-remark-create: Label is missing or not string")) (let ((org-remark-type `(quote ,(plist-get (eval properties) 'org-remark-type)))) `(progn ;; Define custom pen function (defun ,(intern (format "org-remark-mark-%s" label)) (beg end &optional id mode) ,(format "Apply the following face to the region selected by BEG and END. %s Following overlay properties will be added to the highlighted text region: %S Return the overlay. When this function is used interactively, it will generate a new ID, always assuming it is working on a new highlighted text region, and Org-remark will start tracking the highlight's location in the current buffer. When this function is called from Elisp, ID can be optionally passed, indicating to Org-remark that it is an existing highlight. In this case, no new ID gets generated. When the pen itself defines the help-echo property, it will have the priority over the excerpt of the marginal notes." (or face "`org-remark-highlighter'") properties) (interactive (org-remark-beg-end ,org-remark-type)) (org-remark-highlight-mark beg end id mode ,label ,face ,properties)) ;; Register to `org-remark-available-pens' (add-to-list 'org-remark-available-pens (intern (format "org-remark-mark-%s" ,label))) ;; Add function prop This is for `org-remark-change' to show ;; only the pens of the same type (when 'org-remark-type (function-put (intern (format "org-remark-mark-%s" ,label)) 'org-remark-type ,org-remark-type)) ;; Add the custom pen function to the minor-mode menu (define-key-after org-remark-pen-map [,(intern (format "org-remark-mark-%s" label))] '(menu-item ,(format "%s pen" label) ,(intern (format "org-remark-mark-%s" label)))) ;; Add the custom pen change function to the minor-mode menu (define-key-after org-remark-change-pen-map [,(intern (format "org-remark-change-to-%s" label))] '(menu-item ,(format "%s pen" label) (lambda () (interactive) (org-remark-change #',(intern (format "org-remark-mark-%s" label)))) :enable (org-remark-pen-same-type-at-point-p ,org-remark-type))))))) ;;;; Minor mode ;;;###autoload (define-minor-mode org-remark-mode "Highlight and annotate any text file with using Org mode. This is a local minor-mode. On activation, it loads your saved highlights from the notes file and enables automatic saving of highlights thereafter. The automatic saving is achieved via function `org-remark-save' added to `after-save-hook'. On deactivation, it removes all the overlays and stops tracking the highlights in this buffer by setting variable `org-remark-highlights' to nil. Be careful of behavior, if you still wish to retain the locations of highlights. It is recommended to use `org-remark-toggle' if you wish to temporarily hide highlights in the current buffer. It keeps `org-remark-highlights' unchanged. While the tracking of highlights is stopped, editing the buffer will likely result in mismatch between the saved highlights' locations and the current buffer's text content. Highlights tracked by variable `org-remark-highlights' cannot persist when you kill the buffer or quit Emacs. When you re-launch Emacs and visit the same file, ensure to turn on `org-remark-mode' to load the highlights from the marginalia file. `org-remark-global-tracking-mode' automates this. It is recommended to turn it on as part of Emacs initialization. \\{org-remark-mode-map}" :init-value nil :lighter " ormk" :global nil :keymap (let ((map (make-sparse-keymap))) map) (cond (org-remark-mode ;; Activate (dolist (feature org-remark-default-features) (unless (featurep feature) (require feature nil 'noerror))) (dolist (feature-mode org-remark-default-feature-modes) (when (functionp feature-mode) (funcall feature-mode +1))) (org-remark-highlights-load) (add-hook 'org-remark-find-dwim-functions #'org-remark-find-overlay-at-point nil :local) (add-hook 'after-save-hook #'org-remark-save nil :local) (add-hook 'org-remark-highlight-link-to-source-functions #'org-remark-highlight-link-to-source-default 80) (add-hook 'after-revert-hook #'org-remark-highlights-load 80 :local) (add-hook 'clone-buffer-hook #'org-remark-highlights-load 80 :local)) (t ;; Deactivate (when org-remark-highlights (dolist (highlight org-remark-highlights) (delete-overlay highlight))) (setq org-remark-highlights nil) (dolist (feature-mode org-remark-default-feature-modes) (funcall feature-mode -1)) (remove-hook 'org-remark-find-dwim-functions #'org-remark-find-overlay-at-point :local) (remove-hook 'after-save-hook #'org-remark-save t) (remove-hook 'org-remark-highlight-link-to-source-functions #'org-remark-highlight-link-to-source-default) (remove-hook 'after-revert-hook #'org-remark-highlights-load :local) (remove-hook 'clone-buffer-hook #'org-remark-highlights-load :local)))) ;;;; Org-remark Menu (defvar org-remark-menu-map (make-sparse-keymap "Org-remark")) (define-key-after org-remark-menu-map [org-remark-open] '(menu-item "Open" org-remark-open :help "Display and move to marginal notes for highlight at point" :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-view] '(menu-item "View" org-remark-view :help "Display marginal notes for highlight at point; stay in current buffer" :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-view-next] '(menu-item "View next" org-remark-view-next :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-view-prev] '(menu-item "View previous" org-remark-view-prev :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-toggle] '(menu-item "Toggle" org-remark-toggle :help "Toggle showing/hiding of highlights in current buffer" :enable org-remark-highlights)) (define-key-after org-remark-menu-map [org-remark-remove] '(menu-item "Remove" org-remark-remove :help "Remove highlight at point, keeping the marginal notes entry" :enable (org-remark-find-dwim))) (define-key-after org-remark-menu-map [org-remark-delete] '(menu-item "Delete" org-remark-delete :help "Delete highlight at point and the marginal notes entry" :enable (org-remark-find-dwim))) ;; Make pen functions menu (defvar org-remark-pen-map (make-sparse-keymap "Org-remark-mark")) (define-key-after org-remark-pen-map [org-remark-mark] '(menu-item "default pen" org-remark-mark)) ;; Make change pen menu (defvar org-remark-change-pen-map (make-sparse-keymap "Org-remark-change")) (define-key-after org-remark-change-pen-map [org-remark-change] '(menu-item "default pen" (lambda () (interactive) (org-remark-change #'org-remark-mark)) :enable (org-remark-pen-same-type-at-point-p nil))) ;; Add change menu to the parent menu (define-key-after org-remark-menu-map [org-remark-change-pens] `(menu-item "Change to..." ,org-remark-change-pen-map :enable (org-remark-find-dwim) 'org-remark-toggle)) ;; Add pen menu to the parent menu (define-key org-remark-menu-map [org-remark-pens] (list 'menu-item "Highlight with..." org-remark-pen-map)) ;; Add all to the main menu (define-key org-remark-mode-map [menu-bar org-remark] (list 'menu-item "Org-remark" org-remark-menu-map)) (defun org-remark-pen-same-type-at-point-p (org-remark-type) "Return t if the highlight's type is the same as ORG-REMARK-TYPE." (eql org-remark-type (overlay-get (org-remark-find-dwim (point)) 'org-remark-type))) ;;;; Commands ;;;###autoload (defun org-remark-mark (beg end &optional id mode) "Apply face `org-remark-highlighter' to the region between BEG and END. When this function is used interactively, it will generate a new ID, always assuming it is working on a new highlighted text region. Return the highlight overlay. A Org headline entry for the highlight will be created in the marginal notes file specified by `org-remark-notes-get-file-name'. If the file does not exist yet, it will be created. When this function is called from Elisp, ID can be optionally passed, indicating to Org-remark that it is to load an existing highlight. In this case, no new ID gets generated and the highlight saved again, avoiding the unnecessary round-trip back to the database. MODE is also an argument which can be passed from Elisp. It determines whether or not highlight is to be saved in the marginal notes file. The expected values are nil, :load and :change." (interactive (org-remark-beg-end nil)) ;; passing org-remark-type nil ;; FIXME ;; Adding "nil" is different to removing a prop ;; This will do for now (org-remark-highlight-mark beg end id mode nil nil (list 'org-remark-label "nil"))) (when org-remark-create-default-pen-set ;; Create default pen set. (org-remark-create "red-line" `(:underline (:color "dark red" :style wave)) `(CATEGORY "review" help-echo "Review this")) (org-remark-create "yellow" `(:underline "gold2") `(CATEGORY "important"))) (defun org-remark-save () "Save all the highlights tracked in current buffer to notes buffer. This function is automatically called when you save the current buffer via `after-save-hook'. `org-remark-highlights' is the local variable that tracks every highlight in the current buffer. Each highlight is an overlay." (interactive) (org-remark-highlights-housekeep) (org-remark-highlights-sort) (let ((notes-buf (find-file-noselect (org-remark-notes-get-file-name))) (source-buf (or (buffer-base-buffer) (current-buffer)))) (dolist (h org-remark-highlights) (org-remark-highlight-add h source-buf notes-buf)) ;;; Avoid saving the notes buffer if it is the same as the source buffer (if (eq source-buf notes-buf) (set-buffer-modified-p nil) (with-current-buffer notes-buf (save-buffer))))) (defun org-remark-open (point &optional view-only) "Open marginal notes file for highlight at POINT. The marginal notes will be narrowed to the relevant headline to show only the highlight at point. This function creates a cloned indirect buffer for the marginal notes file. You can edit it as a normal Org buffer. Once you have done editing, you can simply save and kill the buffer or keep it around. Org-remark ensures that there is only one cloned buffer for notes file by tracking it. The marginal notes file gets displayed by the action defined by `org-remark-notes-display-buffer-action' (by default in a left side window of the current frame), narrowed to the relevant headline. You can customize the name of the marginal notes buffer with `org-remark-notes-buffer-name'. By default, the cursor will go to the marginal notes buffer for further editing. When VIEW-ONLY is \\=':view-only\\=' \(e.g. Elisp program to pass the value), you can view the marginal notes buffer with the cursor remaining in the current buffer. You can open the marginal notes buffer associated with the current buffer with `find-file' when the notes file exist and if there is no highlight at point. Passing a single universal argument with \\[universal-argument]\) also lets you open the notes buffer in this way. If you pass any other values to VIEW-ONLY, this function behaves in the way as passing \\=':view-only\\=' to it and simply let you view the marginal notes in a cloned indirect buffer in the side-window (as defined by user option `org-remark-notes-display-buffer-action')." (interactive "d\nP") (let ((ov (org-remark-find-dwim point))) ;; If C-u is used or the cursor is not on a highlight, we don't want ;; to open in a normal way but open the margnal notes buffer with ;; find-file. (if (or (eql (prefix-numeric-value current-prefix-arg) 4) ;; :view-only should not open the marginal notes buffer (and (null ov) (not (eql view-only :view-only)))) (let ((notes-file (org-remark-notes-get-file-name))) (when (file-exists-p notes-file) (find-file notes-file))) ;; Open marginal notes normally as an indirect buffer in a side ;; window. (when-let* ((ov ov) ;; OV must be present here. (id (overlay-get ov 'org-remark-id)) (ibuf (org-remark-notes-buffer-get-or-create)) (cbuf (current-buffer))) (pop-to-buffer ibuf org-remark-notes-display-buffer-action) (widen) (when-let (p (org-find-property org-remark-prop-id id)) ;; Somehow recenter is needed when a highlight is deleted and move to a ;; previous highlight. Otherwise, the cursor is too low to show the ;; entire entry. It looks like there is no entry. (goto-char p) (org-narrow-to-subtree) (org-end-of-meta-data t) (recenter)) ;; Run hook with the current-buffer being the note's buffer (run-hooks 'org-remark-open-hook) ;; Avoid error when buffer-action is set to display a new frame (when view-only (select-window (get-buffer-window cbuf))))))) (defun org-remark-view (point) "View marginal notes for highlight at POINT. The marginal notes file gets displayed by the action defined by `org-remark-notes-display-buffer-action' (by default in a side window in the left of the current frame), narrowed to the relevant headline. The cursor remains in the current buffer. Also see the documentation of `org-remark-open'." (interactive "d") (org-remark-open point :view-only)) (defun org-remark-next () "Move to the next highlight, if any. If there is none below the point but there is a highlight in the buffer, cycle back to the first one. After the point has moved to the next highlight, this command lets you move further by re-entering only the last letter like this example: C-n \] \] \] \] \] \(assuming this command is bound to C-n \]\) This is achieved by transient map with `set-transient-map'. If you have the same prefix for `org-remark-prev', you can combine it in the sequence like so: C-n \] \] \] \[ \[" (interactive) (org-remark-next-or-prev :next)) (defun org-remark-prev () "Move to the previous highlight, if any. If there is none above the point, but there is a highlight in the buffer, cycle back to the last one. After the point has moved to the previous highlight, this command lets you move further by re-entering only the last letter like this example: C-n \[ \[ \[ \[ \[ \(assuming this command is bound to C-n \[\) This is achieved by transient map with `set-transient-map'. If you have the same prefix for `org-remark-next', you can combine it in the sequence like so: C-n \] \] \] \[ \[" (interactive) (org-remark-next-or-prev)) (defun org-remark-view-next () "Move the cursor to the next highlight and view its marginal notes." (interactive) (org-remark-next)(org-remark-view (point))) (defun org-remark-view-prev () "Move the cursor to the previous highlight and view its marginal notes." (interactive) (org-remark-prev)(org-remark-view (point))) (defun org-remark-toggle () "Toggle showing/hiding of highlights in current buffer. If you would like to hide/show the highlights in the current buffer, it is recommended to use this command instead of `org-remark-mode'. This command only affects the display of the highlights and their locations are still kept tracked. Toggling off `org-remark-mode' stops this tracking completely, which will likely result in inconsistency between the marginal notes file and the current source buffer." (interactive) (if org-remark-highlights-hidden (org-remark-highlights-show) (org-remark-highlights-hide)) t) (defun org-remark-change (&optional pen) "Change the highlight at point to PEN. This function will show you a list of available pens to choose from." (interactive) (if-let* ((ov (org-remark-find-dwim)) (id (overlay-get ov 'org-remark-id)) (beg (overlay-start ov)) (end (overlay-end ov))) (let* ((available-pens (seq-filter (lambda (pen-fn) (let ((type (overlay-get ov 'org-remark-type))) (eql type (function-get pen-fn 'org-remark-type)))) org-remark-available-pens)) (new-pen (if pen pen (intern ;; To guard against minibuffer quit error when ;; the user quit without selecting any pen. (unwind-protect (completing-read "Which pen?:" available-pens)))))) (org-remark-highlight-clear ov) (funcall new-pen beg end id :change)) ;; if ov or any other variables are not found (message "No highlight here."))) (defun org-remark-remove (point &optional delete) "Remove the highlight at POINT. By default, it will remove the highlight from the source buffer and the properties of entry from the marginal notes buffer, but will keep the headline title and any notes in it. This is to ensure to keep any notes you might have written intact. Optionally, you can let this command delete the entire heading subtree for the highlight along with the notes you have written, by passing universal argument in DELETE. For deletion, this command differentiates a single or double universal arguments as follows: - \\[universal-argument] This is the same behavior as function `org-remark-delete'. Look for notes in the entry. If there is any, the side-window will show them and a prompt will ask the user for confirmation. The function will delete the entry only when the user confirms with \\='y\\='. When \\='n\\=', it will only remove the entry's properties. If there are no notes in the entry, the command will delete the entry without the prompt. - \\[universal-argument] \\[universal-argument] This is automatic deletion. This command will delete the entry without asking the user when there is no notes in the entry. If there are any notes, only the entry's properties will be removed. This is the same behavior as passing a single `universal-argument' to function `org-remark-delete'. If you have removed or deleted a highlight by error, you can still `undo' it in the marginal notes buffer and not in the current buffer. This is because adding and removing overlays are not part of the undo tree. You can undo the deletion in the marginal notes buffer and then save it to sync the highlight back in the source." (interactive "d\nP") (and-let* ((ov (org-remark-find-dwim point)) (id (overlay-get ov 'org-remark-id))) ;; Remove the highlight overlay and id. If there is more than one, ;; remove only one. It should be last-in-first-out in general but ;; overlays functions don't guarantee it (when delete ;; (org-remark-open point :view-only)) (org-remark-highlight-clear ov) ;; Update the notes file accordingly (org-remark-notes-remove id delete) (org-remark-highlights-housekeep) (org-remark-highlights-sort) t)) (defun org-remark-delete (point &optional arg) "Delete the highlight at POINT and marginal notes for it. This function will prompt for confirmation if there is any notes present in the highlight's entry in the marginal notes buffer. When it is not displayed in the current frame, it will be temporarily displayed together with the prompt for the user to see the notes to help with confirmation. If there are no notes, this function will not prompt for confirmation and will remove the highlight in the source buffer and delete the entry in the marginal notes buffer. This is the same behavior as passing a single `universal-argument' to function `org-remark-remove'. Optionally, you can pass `universal-argument' to this function with ARG and it will behave as follows. - \\[universal-argument] This is automatic deletion. Delete the entry without asking the user when there is no notes in the entry. If there are any notes, remove the entry's properties only. This is the same behavior as passing double universal-arguments to function `org-remark-remove'. If you have removed or deleted a highlight by error, you can still `undo' it in the marginal notes buffer and not in the current buffer. This is because adding and removing overlays are not part of the undo tree. You can undo the deletion in the marginal notes buffer and then save it to sync the highlight back in the source." (interactive "d\nP") (let ((delete (if (eql 4 (prefix-numeric-value arg)) '(16) ;; make it universal-arg x 2 :delete))) (org-remark-remove point delete))) ;;;; Private Functions ;;;;; org-remark-find ;; Find a highlight (e.g. next/prev or overlay) (defun org-remark-next-or-prev (&optional next) "Move cursor to the next or previous highlight if any. When NEXT is non-nil, move to the next; for nil, to the previous. This function is internal only and meant to be used by interactive commands such as `org-remark-next' and `org-remark-prev'. Return t if the cursor has moved to next/prev. Return nil if not and outputs a message in the echo." (org-remark-highlights-housekeep) (if (not org-remark-highlights) (progn (message "No highlights present in the buffer") nil) (let ((p (if next (org-remark-find-next-highlight) (org-remark-find-prev-highlight)))) (if p (progn (goto-char p) ;; Setup the overriding keymap. (unless overriding-terminal-local-map (let ((prefix-keys (substring (this-single-command-keys) 0 -1)) (map (cdr org-remark-mode-map))) (when (< 0 (length prefix-keys)) (mapc (lambda (k) (setq map (assq k map))) prefix-keys) (setq map (cdr-safe map)) (when (keymapp map) (set-transient-map map t))))) t) (message "No visible highlights present in the buffer") nil)))) (defun org-remark-find-next-highlight () "Return the beg point of the next highlight. Look through `org-remark-highlights' list." (when-let ((points (org-remark-highlights-get-positions))) ;; Find the first occurrence of p > (point). If none, this means all the ;; points occur before the current point. Take the first one. Assume ;; `org-remark-highlights' is sorted in the ascending order (it is). (seq-find (lambda (p) (> p (point))) points (nth 0 points)))) (defun org-remark-find-prev-highlight () "Return the beg point of the previous highlight. Look through `org-remark-highlights' list (in descending order)." (when-let ((points (org-remark-highlights-get-positions 'reverse))) ;; Find the first occurrence of p < (point). If none, this means all the ;; points occur before the current point. Take the first one. Assume ;; `org-remark-highlights' is sorted in the descending order . (seq-find (lambda (p) (< p (point))) points (nth 0 points)))) (defun org-remark-find-dwim (&optional point) "Return one highlight overlay for the context. It is a generic wrapper function to get and return as what the context requires. This is achieved via abnormal hook that passed the POINT as a single argument. The highligh to be returned can be the range-highlight at point. POINT is optional and if not passed, the current point is used. It can also be a line-highlight for the line, which is a zero length overlay put to the beginning of the line. For the latter, the user's point can be anywhere." (or (run-hook-with-args-until-success 'org-remark-find-dwim-functions point) ;; Fallback (org-remark-find-overlay-at-point point))) (defun org-remark-find-overlay-at-point (&optional point) "Return one org-remark overlay at POINT. When point is nil, use the current point. If there are more than one, return CAR of the list." (let* ((pt (or point (point))) (overlays (overlays-at pt)) found) (while overlays (let ((overlay (car overlays))) (if (overlay-get overlay 'org-remark-id) (setq found (cons overlay found)))) (setq overlays (cdr overlays))) (car found))) (defun org-remark-find-overlay-in (beg end &optional id) "Return one org-remark overlay between BEG and END. If there are more than one, return CAR of the list. Optionally ID can be passed to find the exact ID match." (let* ((overlays (overlays-in beg end)) found) (while overlays (let ((overlay (car overlays))) (if (overlay-get overlay 'org-remark-id) (setq found (cons overlay found)))) (setq overlays (cdr overlays))) (when id (setq found (seq-filter (lambda (ov) (equal (overlay-get ov 'org-remark-id) id)) found))) (car found))) ;;;;; org-remark-highlight ;; Private functions that work on a single highlight. A highlight is an ;; overlay placed on a a part of text. With using an analogy of pens ;; and books, a highlight is the mark you make over a part of a book ;; with a highlighter pen or marker. ;; ;; As highlights are overlays placed on the source buffer, the ;; functions here mostly assume the current buffer is the source ;; buffer. (cl-defgeneric org-remark-highlight-make-overlay (_beg _end _face _org-remark-type) "Make overlay and return it. Put FACE and other necessary properties to the highlight OV" (ignore)) (cl-defmethod org-remark-highlight-make-overlay (beg end face (_org-remark-type (eql nil))) "Make overlay BEG END and add FACE to it. If FACE is nil, this function uses default face `org-remark-highlighter'. This is a method for highlights of default ORG-REMARK-TYPE, that is for a character range." (let ((ov (make-overlay beg end nil :front-advance))) (overlay-put ov 'face (if face face 'org-remark-highlighter)) ov)) (defun org-remark-highlight-mark (beg end &optional id mode label face properties) "Apply the FACE to the region selected by BEG and END. This function will apply FACE to the selected region. When it is nil, this function will use the default face `org-remark-highlighter' This function will add LABEL and PROPERTIES as overlay properties. PROPERTIES is a plist of pairs of a symbol and value. Return the highlight overlay. When this function is used interactively, it will generate a new ID, always assuming it is working on a new highlighted text region, and Org-remark will start tracking the highlight's location in the current buffer. MODE determines whether or not highlight is to be saved in the marginal notes file. The expected values are nil, :load and :change. An Org headline entry for the highlight will be created in the marginal notes file specified by `org-remark-notes-get-file-name'. If the file does not exist yet, it will be created. When this function is called from Elisp, ID can be optionally passed, indicating to Org-remark that it is to load an existing highlight. In this case, no new ID gets generated and the highlight will not be saved again, avoiding the unnecessary round-trip back to the notes file." ;; Ensure to turn on the local minor mode (unless org-remark-mode (org-remark-mode +1)) ;; When highlights are toggled hidden, only the new one gets highlighted in ;; the wrong toggle state. (when org-remark-highlights-hidden (org-remark-highlights-show)) (org-with-wide-buffer (let* ((org-remark-type (plist-get properties 'org-remark-type)) ;;(make-overlay beg end nil :front-advance)) ;; UUID is too long; does not have to be the full length (id (if id id (substring (org-id-uuid) 0 8))) (filename (org-remark-source-find-file-name)) ;; Add highlight overlay only when filename is assigned. (ov (when filename (org-remark-highlight-make-overlay beg end face org-remark-type)))) (if (not filename) (message (format "org-remark: Highlights not saved.\ This buffer (%s) is not supported" (symbol-name major-mode))) ;; OV may not be created for line-highlights when the user opens ;; the buffer for the first time, as the window may not have been ;; created to display the buffer yet. This is necessary for the ;; margin width to be calculated. (when ov (while properties (let ((prop (pop properties)) (val (pop properties))) (overlay-put ov prop val))) (when label (overlay-put ov 'org-remark-label label)) (overlay-put ov 'org-remark-id id) ;; Keep track of the overlay in a local variable. It's a list that is ;; guaranteed to contain only org-remark overlays as opposed to the one ;; returned by `overlay-lists' that lists all overlays. (push ov org-remark-highlights) ;; for mode, nil and :change result in saving the highlight. :load ;; bypasses save. (unless (eq mode :load) (let* ((notes-buf (find-file-noselect (org-remark-notes-get-file-name))) (source-buf (current-buffer)) ;; Get props for create and change modes (notes-props (org-remark-highlight-add ov source-buf notes-buf))) (when notes-props (org-remark-highlight-put-props ov notes-props)) ;; Save the notes buffer when not loading (unless (eq notes-buf (current-buffer)) ;; Force tiggering the update save for :change:operation. ;; The line-icons do not get updated because :change: to ;; the same pen does not involve buffer modificaiton and ;; thus the sync does not get triggered to update icons. (with-current-buffer notes-buf (unless (buffer-modified-p) (restore-buffer-modified-p t)) (save-buffer)))))) (deactivate-mark) (org-remark-highlights-housekeep) (org-remark-highlights-sort) (setq org-remark-source-setup-done t) ;; Return overlay ov)))) (defun org-remark-highlight-get-title () "Return the title of the source buffer. The title is either the title keyword for an Org buffer, or the file name of the source buffer. When the source is not a file (e.g. a website), it is its file name equivalent, such as the URL for a website. This function assumes the current buffer is the source buffer. Utility function to work with a single highlight overlay." (or (and (derived-mode-p 'org-mode) ;; `org-collect' gives an warning if the current buffer is not an ;; org-mode (cadr (assoc "TITLE" (org-collect-keywords '("TITLE"))))) (let* ((full-name (org-remark-source-find-file-name)) (filename (if (and (string= "" (file-name-nondirectory full-name)) (string-match "[\/]+\\'" full-name)) ;; The name ends with a / (possibly a URL). ;; Trim all the slashes at the end of the ;; name. (replace-match "" t t full-name) full-name))) (if (or (null filename) (string= "" filename)) (error "Could not extract highlight title") (file-name-sans-extension (file-name-nondirectory filename)))))) (defun org-remark-highlight-get-org-id (point) "Return Org-ID closest to POINT of the source buffer. This function does this only when `org-remark-use-org-id' is non-nil. Returns nil otherwise, or when no Org-ID is found. This function assumes the current buffer is the source buffer." (and org-remark-use-org-id (derived-mode-p 'org-mode) (org-entry-get point "ID" :inherit))) (define-obsolete-function-alias 'org-remark-highlight-save 'org-remark-highlight-add "1.2.0" "Save a single HIGHLIGHT in the marginal notes file. We no longer save the notes file to disk; hence the name change") (cl-defgeneric org-remark-highlight-get-constructors () "Construct lists for creating MAJOR-MODE specific hierarchy. This is the default one. Return the value in a alist like this: (SOURCE-FILENAME-FN TITLE-FN PROP-TO-FIND)" (let* ((headline-1 (list ;; SOURCE-FILENAME-FN (lambda () (org-remark-source-get-file-name (org-remark-source-find-file-name))) ;; TITLE-FN #'org-remark-highlight-get-title ;; PROP-TO-FIND org-remark-prop-source-file)) (headline-constructors (list headline-1))) headline-constructors)) (defun org-remark-highlight-add (overlay source-buf notes-buf) "Add a single HIGHLIGHT in the marginal notes file. Return the highlight's data properties list (TODO refer to ...). FILENAME is the name of source file with which the marginal notes buffer is associated. When the source buffer does not visit a file (e.g. a website), it is the source buffer's file name equivalent, such as the URL. OVERLAY is the highlight being saved. SOURCE-BUF is the buffer of the source. NOTES-BUF is the notes buffer for the source. For the first highlight of the source buffer, this function will create a new H1 headline for it at the bottom of the marginal notes buffer with TITLE as its headline text. When called for a new highlight that is unsaved in the marginal notes file, this function will create a new H2 headline with the highlighted text as its headline text at the end of the H1 headline for the source buffer. If a headline with the same ID already exists, update its position and properties named \"org-remark-*\" and CATEGORY from the highlight overlay. For update, the headline text will be kept intact, because the user might have changed it to their needs. This function will also add a normal file link as property \"org-remark-link\" of the H2 headline entry, pointing back to the source file with search option \"::line-number\", or for non-file sources, calls `run-hook-with-args-until-success' for `org-remark-highlight-link-to-source-functions' with FILENAME as the argument. ORGID can be passed to this function. If user option `org-remark-use-org-id' is non-nil, this function will add an Org-ID link in the body text of the headline, linking back to the source with using ORGID. When the current source buffer is not set up for sync with notes, this function calls `org-remark-notes-setup' to prepare the notes buffer for automatic sync." (let ((notes-props nil) ;; Does this have to be explicitly in with-current buffer clause? (headline-constructors (with-current-buffer source-buf (org-remark-highlight-get-constructors)))) (with-current-buffer notes-buf (org-with-wide-buffer ;; Different major-mode extension may have different structure of notes file ;; e.g. nov.el file: 1. source file; 2. book; 3 highlight ;; text file: 1. source file; 2. highlight ;; Note the lowest level is always the highlight (common). And ;; the top level is the "source" -- the file or URL, etc. (cl-loop for index from 1 for (filename-fn title-fn prop-to-find) in headline-constructors ;; This variable "point" is set in order to be returned at ;; the end of the loop. with point = 1 do (let (filename title) (with-current-buffer source-buf (setq filename (funcall filename-fn)) (setq title (funcall title-fn))) (with-current-buffer notes-buf (goto-char point) (setq point (or (org-find-property prop-to-find filename) (org-remark-notes-new-headline index title (list prop-to-find filename)))))) ;; Add the hightlight/note nodes after the headline loop. finally (progn ;; need to move to the point at the end ;; of loop (goto-char point) ;; Highlight Headline is common to all major-mode extensions (setq notes-props (org-remark-highlight-add-or-update-highlight-headline overlay source-buf notes-buf)))))) ;;; Set up notes buffer for sync for the source buffer (with-current-buffer source-buf (unless org-remark-source-setup-done (org-remark-notes-setup notes-buf source-buf))) ;;; Return notes-props notes-props)) (cl-defgeneric org-remark-highlight-headline-text (_ov _org-remark-type) "Return title text of highlight.") (cl-defmethod org-remark-highlight-headline-text (ov (_org-remark-type (eql nil))) "Return title text of highlight OV of default type. Assume it is called within `org-with-wide-buffer' of the source." (replace-regexp-in-string "\n" " " (buffer-substring-no-properties (overlay-start ov) (overlay-end ov)))) (defvar org-remark-highlight-other-props-functions nil "Abnormal hook to be run when adding or updating headline. It is called with one argument HIGHLIGHT, which is the overlay that represents the current highlight being worked on. The function is run with source buffer as the current buffer.") (defun org-remark-highlight-collect-other-props (highlight) "Return other properties for HIGHLIGHT. Assume to be run in the source buffer." (let ((props nil)) (dolist (fn org-remark-highlight-other-props-functions props) (let ((plist (funcall fn highlight))) (when plist (setq props (append props plist))))))) (defun org-remark-highlight-add-or-update-highlight-headline (highlight source-buf notes-buf) "Add a new HIGHLIGHT headlne to the NOTES-BUF or update it. Return notes-props as a property list. HIGHLIGHT is an overlay from the SOURCE-BUF. Assume the current buffer is NOTES-BUF and point is placed on the beginning of source-headline, which should be one level up." ;; Add org-remark-link with updated line-num as a property (let (title beg end props id text filename link orgid org-remark-type other-props) (with-current-buffer source-buf (org-with-wide-buffer (setq title (org-remark-highlight-get-title) beg (overlay-start highlight) end (overlay-end highlight) props (overlay-properties highlight) id (plist-get props 'org-remark-id) org-remark-type (overlay-get highlight 'org-remark-type) text (org-with-wide-buffer ;; BUG #79. When the notes-buffer = source-buffer, the ;; point is now at the end of notes headline, which is ;; incorrect to get the title text. We need to temporarily ;; move the point back to the start of the highlight. (save-excursion (goto-char beg) (org-remark-highlight-headline-text highlight org-remark-type))) filename (org-remark-source-get-file-name (org-remark-source-find-file-name)) link (run-hook-with-args-until-success 'org-remark-highlight-link-to-source-functions filename beg) orgid (org-remark-highlight-get-org-id beg) other-props (org-remark-highlight-collect-other-props highlight)) ;; TODO ugly to add the beg end after setq above (plist-put props org-remark-prop-source-beg (number-to-string beg)) (plist-put props org-remark-prop-source-end (number-to-string end)) (when link (plist-put props "org-remark-link" link)) (when other-props (setq props (append props other-props))))) ;;; Make it explicit that we are now in the notes-buf, though it is ;;; functionally redundant. (with-current-buffer notes-buf (let ((highlight-headline (org-find-property org-remark-prop-id id)) ;; Assume point is at the beginning of the parent headline (level (1+ (org-current-level)))) (if highlight-headline (progn (goto-char highlight-headline) ;; Update the existing headline and position properties ;; Don't update the headline text when it already exists. ;; Let the user decide how to manage the headlines ;; (org-edit-headline text) (org-remark-notes-set-properties props)) ;; No headline with the marginal notes ID property. Create a new one ;; at the end of the file's entry (org-narrow-to-subtree) (goto-char (point-max)) ;; Ensure to be in the beginning of line to add a new headline (when (eolp) (open-line 1) (forward-line 1) (beginning-of-line)) ;; Create a headline ;; Add a properties (insert (concat (insert-char (string-to-char "*") level) " " text "\n")) ;; org-remark-original-text should be added only when this ;; headline is created. No update afterwards (plist-put props "org-remark-original-text" text) (org-remark-notes-set-properties props) (when (and orgid org-remark-use-org-id) (insert (concat "[[id:" orgid "]" "[" title "]]")))) (list :body (org-remark-notes-get-body) :original-text text))))) (defun org-remark-highlight-load (highlight) "Load a single HIGHLIGHT to the source buffer. Return highlight overlay that has been loaded on the source buffer. Assume the current buffer is the source buffer." (let* ((id (plist-get highlight :id)) (location (plist-get highlight :location)) (beg (car location)) (end (cdr location)) (label (plist-get highlight :label)) (ov nil) (props (plist-get highlight :props))) (let ((fn (intern (concat "org-remark-mark-" label)))) (unless (functionp fn) (setq fn #'org-remark-mark)) (setq ov (funcall fn beg end id :load)) (when ov (org-remark-highlight-put-props ov props)) ;; Return highlight overlay ov))) (defun org-remark-highlight-put-props (highlight plist) "Put PLIST from notes Org props to HIGHLIGHT overlay properties." ;; TODO Generalize the part that updates properties. ;; :body should not be the fixed property. ;; '(:text (val . fn) :prop1 (val . fn) :prop2 (val .fn)) ;; (dolist list) (unless (overlay-get highlight 'help-echo) (overlay-put highlight 'help-echo (plist-get plist :body))) (overlay-put highlight '*org-remark-note-body (plist-get plist :body)) (overlay-put highlight '*org-remark-original-text (plist-get plist :original-text))) (defun org-remark-highlight-clear (overlay) "Clear a single highlight OVERLAY. It is a utility function to take care of both variabel `org-remark-highlights' and a highlight OVERLAY at the same time." (setq org-remark-highlights (delete overlay org-remark-highlights)) (delete-overlay overlay)) (defun org-remark-highlight-adjust-position-after-load (highlight text) "Adjust the position of a HIGHLIGHT overlay after loaded. It searches for TEXT, which should be the original text of the highlight." ;; Load works. but need one for sync. Need to re-think ;; ' and ’ are different in regex of course. ;; This is probably not very good for text that you change; and change the highlights. ;; if you change it, this will bring it back to the "original". (let* ((beg (overlay-start highlight)) (end (overlay-end highlight)) (paragraph-beg)(paragraph-end)) (org-with-wide-buffer (unless (org-remark-string= (buffer-substring-no-properties beg end) text) ;; Look at one paragraph ahead as it is possible that the ;; position has been displaced across a paragraph (goto-char beg) (backward-paragraph 2) (setq paragraph-beg (point)) (goto-char beg) (forward-paragraph 2) (setq paragraph-end (point)) (goto-char paragraph-beg) ;; Search from the beginning of the previous paragraph to the end ;; of next paragraph relative to the begining of the highlight ;; overlay; this way, you don't need to look forward and backward ;; separately. (when (re-search-forward text paragraph-end :noerror) (move-overlay highlight (match-beginning 0) (match-end 0))) ;; Add property to indicate that the position has somehow been ;; adjusted. Even if the new location could not be found, ;; indicate that the fact that string should have moved. (overlay-put highlight '*org-remark-position-adjusted t))))) (defun org-remark-highlight-link-to-source-default (filename point) "Return Org link string for FILENAME & POINT for a highlight. POINT is used to compute the line number. Default function for `org-remark-highlight-link-to-source-functions'." (if buffer-file-name (let ((line-num (org-current-line point))) (concat "[[file:" filename (when line-num (format "::%d" line-num)) "]]")))) ;;;;; org-remark-notes ;; Private functions that work on marginal notes buffer (notes ;; buffer). Notes buffer visits an Org file, which serves as plain ;; text database whose main purpose is to persist the location of ;; highlights and body text for them if any. Each highlight can also ;; hold properties related to Org-remark. Their names are prefixed ;; with "org-remark". The exception to this is the Org's standard ;; CATEGORY, which can be set as a property for Org-remark's custom ;; highlighter pens. ;; The tree structure of the Org file database can be flexible and ;; defined per major mode by their respective extension. Examples ;; include `org-remark-nov' and `org-remark-info'. Org-remark search ;; specific Org properties to determine where to store newly created ;; highlights. :org-remark-file: and :org-remark-id: are the most ;; important properties that Org-remark search. ;; - The default tree structure: ;; H1: File (:org-remark-file:) for non-file visiting buffer, file ;; name equivalent such as URL for a website ;; H2: Highlight (:org-remark-id:) each one has a dedicated H2 ;; subtree ;; - The tree structure for `org-remark-nov' ;; H1: Book (:org-remark-nov-file:) The EPUB file, which ;; is the zip file. ;; H2: Chapter (:org-remark-file:) Each HTML file contained in ;; the EPUB file ;; H3: Highlight (:org-remark-id:) ;; The highlight (:org-remark-id:) is the lowest level of the tree, ;; whose parent/ancestor must be a node that has :org-remark-file: ;; property. ;; In general, -notes-* functions assume the current buffer is the ;; notes buffer. One remark on a subtlety: Org-remark clones an ;; indirect buffer of notes buffer; this is meant to be user ;; convenience. Users might interact with either the indirect buffer ;; or directly with the base buffer. For automatic sync ;; functionality, Org-remark interacts directly with the base buffer. (defun org-remark-notes-new-headline (level title props) "Add a new headline in the note buffer. This function assumes that the point is in the notes buffer. LEVEL is the headline level to be added. TITLE is the headline title. PROPS is the alist of properties to be added to the headline. Return the point of begining of current heading." ;; If file-headline does not exist, create one at the bottom (unless (= level 1) ;; If top node, narrowing headline results in level 2 being ;; prepended. By not narrowing at level 1, the new level 2 ;; headings will be appended at the bottom of the buffer. (org-narrow-to-subtree)) (goto-char (point-max)) ;; Ensure to be in the beginning of line to add a new headline (when (eolp) (open-line 1) (forward-line 1) (beginning-of-line)) (insert-char (string-to-char "*") level) (insert (concat " " title "\n")) (org-remark-notes-set-properties props) (org-back-to-heading) (point)) (defun org-remark-notes-remove (id &optional delete) "Remove the note entry for highlight ID. Return t. By default, this function only removes the properties of the entry, keeping the headline title and any notes in it intact. You can pass DELETE to delete the entire entry. Elisp can pass the following value to differentiate the deletion behavior (for example, with commands `org-remark-remove' or `org-remark-delete'): - :auto-delete or a list that has a single element 16, that is \\='(16)\\='. The latter value is generated when the user uses a command with \\[universal-argument] \\[universal-argument] :: Delete the entry without asking the user when there is no notes in the entry. If there are any notes, remove the entry's properties only. - Any other non-nil value :: Look for notes in the entry. If there is any, ask the user for confirmation. Delete the entire entry only when the user confirms with \\='y\\='. When \\='n\\=', remove the entry's properties only. If there are no notes, do not prompt for confirmation and delete the entry in the marginal notes buffer." (let* ((ibuf (org-remark-notes-buffer-get-or-create)) (window (get-buffer-window ibuf))) (with-current-buffer ibuf (org-with-wide-buffer (when-let ((id-headline (org-find-property org-remark-prop-id id))) (goto-char id-headline) (org-narrow-to-subtree) (dolist (prop (org-entry-properties)) (when (string-prefix-p "org-remark-" (downcase (car prop))) (org-delete-property (car prop)))) (when delete ;; CATEGORY prop won't be deleted. Move to line after props (org-end-of-meta-data t) (let ((delete (if (eql 16 (prefix-numeric-value delete)) :auto-delete delete)) (notes-exist-p (looking-at ".")) (ok-to-delete-p nil)) (cond ;; Deletion Case 1. No notes. Auto-delete. OK to Delete ((and (not notes-exist-p) (eql delete :auto-delete)) (setq ok-to-delete-p t)) ;; Deletion Case 2. No notes. Normal delete. OK to Delete ((and (not notes-exist-p) (not (eql delete :auto-delete))) (setq ok-to-delete-p t)) ;; Deletion Case 3. Notes exist. Auto-delete. Keep. ((and notes-exist-p (eql delete :auto-delete)) (setq ok-to-delete-p nil)) ;; Deletion Case 4. Notes exist. Normal delete. Prompt Y/N ((and notes-exist-p (not (eql delete :auto-delete))) ;; default behavior: when notes exist, ask the user (display-buffer ibuf org-remark-notes-display-buffer-action) (setq ok-to-delete-p (y-or-n-p "Highlight removed but notes exist. \ Do you also want to delete the notes?")))) (when ok-to-delete-p (delete-region (point-min)(point-max)) (message "Deleted the marginal notes entry")))))) (when (buffer-modified-p) (save-buffer)) ;; Quit the marginal notes indirect buffer if it was not there ;; before the remove/delete -- go back to the original state. (when-let (ibuf-window (get-buffer-window ibuf)) (unless window (quit-window nil ibuf-window )))) t)) (defun org-remark-notes-buffer-get-or-create () "Return marginal notes buffer. Create one if it does not exist. It's a cloned indirect buffer of a buffer visiting the marginal notes file of the current buffer. This function ensures there is only one of the marginal notes buffer per session." ;; Compare the target marginal notes buffer and current marginal notes buffer. ;; For the latter, we need the base buffer of an indirect buffer. (let ((cbuf (find-file-noselect (org-remark-notes-get-file-name))) (ibuf (when (buffer-live-p org-remark-last-notes-buffer) org-remark-last-notes-buffer))) (unless (eq (buffer-base-buffer ibuf) cbuf) ;; Fixed the issue of killing the main buffer when there is no ;; indirect buffer created yet (when ibuf (kill-buffer ibuf)) (setq ibuf (make-indirect-buffer cbuf org-remark-notes-buffer-name :clone))) ;; set the variable and return the indirect buffer (setq org-remark-last-notes-buffer ibuf))) (defun org-remark-notes-set-properties (props) "Set properties for the headline in the notes file. Return t. Minimal properties are: - org-remark-id :: ID - org-remark-source-beg :: BEG - org-remark-source-end :: END And the following are also reserved for Org-remark: - org-remark-link For PROPS, if the property name is CATEGORY \(case-sensitive\) or prefixed with \"org-remark-\" set them to to headline's property drawer. In order to avoid adding org-remark-* overlay properties to Org properties, add prefix \"*\"." ;; Delete property. Prefer `org-entry-delete' over ;; `org-delete-property' as the former is silent. (org-entry-delete nil "CATEGORY") ;; TODO generalize org-entry-delete for other props so that they can ;; be deleted when the value previously existed and now being deleted. (while props (let ((p (pop props)) (v (pop props))) (when (symbolp p) (setq p (symbol-name p))) (when (symbolp v) (setq v (symbol-name v))) (when (or (string-equal "CATEGORY" (upcase p)) (and (> (length p) 11) (string-equal "org-remark-" (downcase (substring p 0 11))))) (org-set-property p v)))) t) (defun org-remark-notes-get-body () "Return the text body of a highlight in the notes buffer." (let ((full-text (save-excursion (org-end-of-meta-data :full) (if ;; handle empty annotation ;; (org-end-of-meta-data :full) took us to next org heading): (or (looking-at org-heading-regexp) (eobp)) ;; end of buffer nil ;; no body text for the annotation (buffer-substring-no-properties (point) (org-end-of-subtree)))))) ;; TODO Consider customizing var for the max length 200 (if (< 200 (length full-text)) (substring-no-properties full-text 0 200) full-text))) (defun org-remark-notes-setup (notes-buf source-buf) "Set up NOTES-BUF and SOURCE-BUF for sync. Note that this function adds some local variables only to the base-buffer of the notes and not to the indirect buffer." (let ((base-buf (or (buffer-base-buffer notes-buf) notes-buf))) (with-current-buffer base-buf (unless (member source-buf org-remark-notes-source-buffers) (cl-pushnew source-buf org-remark-notes-source-buffers) (add-hook 'after-save-hook #'org-remark-notes-sync-with-source nil :local)))) (with-current-buffer source-buf (setq org-remark-source-setup-done t))) (defun org-remark-notes-housekeep () "Remove killed buffers from `org-remark-notes-source-buffers'." (setq org-remark-notes-source-buffers (seq-filter #'buffer-live-p org-remark-notes-source-buffers))) (defun org-remark-notes-sync-with-source () "Update sources from the current notes buffer. This function iterates through `org-remark-notes-source-buffers' in the base buffer of the notes. It is meant to be used in `after-save-hook'." ;;; Assume the current buffer is either the indirect or notes buffer ;;; in question. In order for the `after-save-hook' to correctly ;;; triggers notes sync, we need to get the base buffer if the note ;;; buffer being saved is an indirect one. (let ((notes-buffer (or (buffer-base-buffer) (current-buffer)))) (with-current-buffer notes-buffer (org-remark-notes-housekeep) (dolist (source-buf org-remark-notes-source-buffers) (with-current-buffer source-buf (org-remark-highlights-load :update)))) t)) ;;;;; org-remark-highlights ;; Work on all the highlights in the current buffer (defun org-remark-highlights-get (notes-buf) "Return a list of highlights from NOTES-BUF. The file name is returned by `org-remark-notes-get-file-name'. It is assumed that the current buffer is source buffer. Each highlight is a property list in the following properties: (:id ID :location (BEG . END) :label LABEL :props (PROPERTIES)" ;; Set source-file-name first, as `find-file-noselect' will set the ;; current-buffer to source-file-name. Issue #39 FIXME: A way to make ;; this sequence agnostic is preferred, if there is a function that ;; visit file but not set the current buffer (when-let ((source-file-name (org-remark-source-get-file-name (org-remark-source-find-file-name))) (notes-buf notes-buf)) (let ((highlights)) (with-current-buffer notes-buf (when (featurep 'org-remark-convert-legacy) (org-remark-convert-legacy-data)) (org-with-wide-buffer (let ((heading (org-find-property org-remark-prop-source-file source-file-name))) (if (not heading) (when org-remark-report-no-highlights (message "No highlights or annotations found for %s." source-file-name)) (goto-char heading) ;; Narrow to only subtree for a single file. `org-find-property' ;; ensures that it is the beginning of a headline (org-narrow-to-subtree) (org-show-children) ;; Headline levels now can be dynamically changed via ;; highlight-constructors. (while (org-at-heading-p (org-next-visible-heading 1)) (let ((id (org-entry-get (point) org-remark-prop-id)) (beg (org-entry-get (point) org-remark-prop-source-beg)) (end (org-entry-get (point) org-remark-prop-source-end)) (body (org-remark-notes-get-body))) ;; beg and end must exist. If either is nil ;; `string-to-number' errors (when (and id beg end) (setq beg (string-to-number beg)) (setq end (string-to-number end)) (push (list :id id :location (cons beg end) :label (org-entry-get (point) "org-remark-label") :props (list :original-text (org-entry-get (point) "org-remark-original-text") :body body)) highlights))))) highlights)))))) (defun org-remark-highlights-delay-load () "Delay load until window for current buffer is created." (when (get-buffer-window) (remove-hook 'post-command-hook #'org-remark-highlights-delay-load 'local) (org-remark-highlights-load))) ;;;###autoload (defun org-remark-highlights-load (&optional update) "Visit notes file & load the saved highlights onto current buffer. If there is no highlights or annotations for current buffer, output a message in the echo. Non-nil value for UPDATE is passed for the notes-source sync process." (if (not (get-buffer-window)) (add-hook 'post-command-hook #'org-remark-highlights-delay-load 95 'local) ;; Some major modes such as nov.el reuse the current buffer, deleting ;; the buffer content and insert a different file's content. In this ;; case, obsolete highlight overlays linger when you switch from one ;; file to another. Thus, in order to update the highlight overlays we ;; need to begin loading by clearing them first. This way, we avoid ;; duplicate of the same highlight. (org-remark-highlights-clear) ;; Loop highlights and add them to the current buffer (let (overlays) ;; highlight overlays (when-let* ((notes-filename (org-remark-notes-get-file-name)) (default-dir default-directory) (notes-buf (or (find-buffer-visiting notes-filename) (find-file-noselect notes-filename))) (source-buf (current-buffer))) (with-demoted-errors "Org-remark: error during loading highlights: %S" ;; Load highlights with demoted errors -- this makes the loading ;; robust against errors in loading. (org-with-wide-buffer (dolist (highlight (org-remark-highlights-get notes-buf)) (let ((ov (org-remark-highlight-load highlight))) (when ov (push ov overlays)))) (unless update (org-remark-notes-setup notes-buf source-buf)) (if overlays (progn (run-hook-with-args 'org-remark-highlights-after-load-functions overlays notes-buf) ;; Return t t) ;; if there is no overlays loaded, return nil nil))))))) (defun org-remark-highlights-clear () "Delete all highlights in the buffer. This function also set `org-remark-highlights' to nil." (setq org-remark-highlights nil) (org-with-wide-buffer (dolist (ov (overlays-in (point-min) (point-max))) (when (overlay-get ov 'org-remark-id) (delete-overlay ov))))) (defun org-remark-highlights-get-positions (&optional reverse) "Return list of the beginning point of all visible highlights in this buffer. By default, the list is in ascending order. If REVERSE is non-nil, return list in the descending order. This function also checks if the position is visible or not. Return only visible ones. If none, return nil." (when org-remark-highlights (let ((list org-remark-highlights)) (setq list (mapcar (lambda (h) (let ((p (overlay-start h))) ;; Checking if the p is visible or not (if (or (> p (point-max)) (< p (point-min)) ;; When the highlight is within a visible folded ;; area, this function returns 'outline (org-invisible-p p)) nil p))) list)) (setq list (remove nil list)) (when list (if reverse (reverse list) list))))) (defun org-remark-highlights-sort () "Utility function to sort `org-remark-highlights'. It checks if there is any element exists for `org-remark-highlights'. Instead of receiving it as an arg, it assumes its existence. It also destructively updates `org-remark-highlights'. It returns t when sorting is done." (when org-remark-highlights (setq org-remark-highlights (seq-sort-by (lambda (ov) (overlay-start ov)) #'< org-remark-highlights)) t)) (defun org-remark-highlights-hide () "Hide highlights when toggling their visibility. This function removes the font-lock-face of all the highlights, and add *org-remark-hidden property with value t. It does not check the current hidden state, thus not interactive. Use `org-remark-toggle' command to manually toggle the show/hide state." (when-let ((highlights org-remark-highlights)) (dolist (highlight highlights) ;; Faces (overlay-put highlight '*org-remark-face (overlay-get highlight 'face)) (overlay-put highlight 'face nil) (overlay-put highlight '*org-remark-hidden t) (run-hook-with-args 'org-remark-highlights-toggle-hide-functions highlight)) (setq org-remark-highlights-hidden t))) (defun org-remark-highlights-show () "Show highlights when toggling their visibility. This function adds the font-lock-face to all the highlighted text regions. It does not check the current hidden state, thus not interactive. Use `org-remark-toggle' command to manually toggle the show/hide state." (when-let ((highlights org-remark-highlights)) (dolist (highlight highlights) ;; Faces (overlay-put highlight '*org-remark-hidden nil) (overlay-put highlight 'face (overlay-get highlight '*org-remark-face)) (run-hook-with-args 'org-remark-highlights-toggle-show-functions highlight)) (setq org-remark-highlights-hidden nil))) (defun org-remark-highlights-housekeep () "House keep the internal variable `org-remark-highlights'. Return t. This is a private function; house keep is automatically done on mark, save, and remove -- before sort-highlights. Case 1. Both start and end of an overlay are identical _and_ it's not a line-highlight, which is designed to be zero length with the start and end identical This should not happen when you manually mark a text region. A typical cause of this case is when you delete a region that contains a highlight overlay. This also happens when EWW reloads the buffer or re-renders any part of the buffer. This is because it removes overlays on re-render by calling `remove-overlays'. Case 2. The overlay points to no buffer This case happens when overlay is deleted by `overlay-delete' but the variable not cleared." (dolist (ov org-remark-highlights) ;; Both start and end of an overlay are identical; this should not ;; happen when you manually mark a text region. A typical cause of ;; this case is when you delete a region that contains a highlight ;; overlay. This also happens when EWW reloads the buffer or ;; re-renders any part of the buffer. This is because it removes ;; overlays on re-render by calling `remove-overlays', which edits ;; the overlay-start and overlay-end properties. To guard against ;; this, we check if the buffer is write-able and only remove the ;; annotation when it is. (let ((org-remark-type (overlay-get ov 'org-remark-type))) (when (and (overlay-buffer ov) (= (overlay-start ov) (overlay-end ov)) (org-remark-highlights-housekeep-delete-p ov org-remark-type)) ;; When the buffer is writable and visitnig a file to change it. ;; That is, a "normal" buffer. If it is writable and yet derived ;; from a special mode, we consider the case to be in the ;; rendering process of the mode, and thus do not want to put into ;; the bin as part of housekeeping. (when (and (not buffer-read-only) (not (derived-mode-p 'special-mode))) ;; Buffer-size 0 happens for a package like nov.el. It erases ;; the buffer (size 0) and renders a new page in the same ;; buffer. In this case, buffer is writable. ;; ;; TODO Relying on the current major mode being derived from ;; special-mode may not be the best. ;; Removing the notes here is meant to be to automatically remove ;; notes when you delete a region that contains a higlight ;; overlay. (let ((id (overlay-get ov 'org-remark-id)) (arg org-remark-notes-auto-delete)) (org-remark-notes-remove id arg))) (delete-overlay ov)) ;; Before deleting `org-remark-highlights', add a handler per ;; org-remark-type (org-with-wide-buffer (org-remark-highlights-housekeep-per-type ov org-remark-type)) ;; Update `org-remark-highlights' by removing the deleted overlays (unless (overlay-buffer ov) (setq org-remark-highlights (delete ov org-remark-highlights))))) t) (cl-defgeneric org-remark-highlights-housekeep-delete-p (_ov _org-remark-type) "Additional predicate to delete during housekeep. Default is always t. Implement method specific to \\='\org-remark-type\=' and return nil the highlight must be kept. The current buffer is source buffer." t) (cl-defgeneric org-remark-highlights-housekeep-per-type (_ov _org-remark-type) "Housekeep highlights per type." (ignore)) (defun org-remark-highlights-adjust-positions (overlays _notes-buf) "Run dolist and delgate the actual adjustment to another function. OVERLAYS are highlights. Check the original text property exits and not the same as the current highlighted text. Meant to be set to `org-remark-highlights-after-load-functions' by mode-specific extensions." (dolist (ov overlays) (let ((highlight-text (overlay-get ov '*org-remark-original-text))) ;; Check that the original text exists AND it is different to the ;; current text (when (and (org-remark-highlights-adjust-positions-p (overlay-get ov 'org-remark-type)) highlight-text (not (org-remark-string= highlight-text (buffer-substring-no-properties (overlay-start ov) (overlay-end ov))))) (org-remark-highlight-adjust-position-after-load ov highlight-text))))) (cl-defgeneric org-remark-highlights-adjust-positions-p (_org-remark-type) "Return t if adjust-positions feature is relevant. Default is t and evaluated per ORG-REMARK-TYPE." t) ;;;;; Other utilities (defun org-remark-source-get-file-name (filename) "Convert FILENAME either to absolute or relative for marginal notes files. Returns the standardized filename. The current buffer is assumed to be visiting the source file. FILENAME should be an absolute file name of the source file. If FILENAME is nil, return nil." ;; Get the default-directory of the notes (when filename ; fix #23 (with-current-buffer (find-file-noselect (org-remark-notes-get-file-name)) (funcall org-remark-source-file-name filename)))) (cl-defgeneric org-remark-beg-end (_org-remark-type) "Return beg and end for default ORG-REMARK-TYPE." (org-remark-region-or-word)) (defun org-remark-region-or-word () "Return beg and end of the active region or of the word at point. It is meant to be used within `interactive' in place for \"r\" key. The \"r\" key outputs an error when no mark is set. This function extends the behavior and looks for the word at point" (let ((beg (mark)) (end (point)) (word (bounds-of-thing-at-point 'word))) ;; Use word's bounds when there is no active mark or one of beg/end is ;; missing. The latter can happen when there is no mark is set yet. (unless mark-active (setq beg (car word) end (cdr word))) ;; Check beg end is required as the cursor may be on an empty point with no ;; word under it. (if (and beg end) (progn (when (> beg end) (let ((large beg)) (setq beg end end large))) (list beg end)) (user-error "No region selected and the cursor is not on a word")))) (defun org-remark-string= (s1 s2) "Like `string=' but remove newlines and spaces before compare. Return t if S1 and S2 are an identical string." (string= ;; Cater to the case when the text is divided by a newline ;; character \n. Remove all spaces and newline chars ;; before comparing the strings. (replace-regexp-in-string "[\n ]" "" s1) (replace-regexp-in-string "[\n ]" "" s2))) ;;;; Footer (provide 'org-remark) ;;; org-remark.el ends here