├── TEST ├── .gitignore └── org-clones-ert.el ├── IMAGES ├── output-2020-09-01-15:12:55.gif ├── output-2020-09-01-15:13:35.gif ├── output-2020-09-01-15:15:40.gif └── output-2020-09-01-15:37:39.gif ├── .gitignore ├── README.org ├── LICENSE └── org-clones.el /TEST/.gitignore: -------------------------------------------------------------------------------- 1 | TEST/#* 2 | -------------------------------------------------------------------------------- /IMAGES/output-2020-09-01-15:12:55.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/legalnonsense/org-clones/HEAD/IMAGES/output-2020-09-01-15:12:55.gif -------------------------------------------------------------------------------- /IMAGES/output-2020-09-01-15:13:35.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/legalnonsense/org-clones/HEAD/IMAGES/output-2020-09-01-15:13:35.gif -------------------------------------------------------------------------------- /IMAGES/output-2020-09-01-15:15:40.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/legalnonsense/org-clones/HEAD/IMAGES/output-2020-09-01-15:15:40.gif -------------------------------------------------------------------------------- /IMAGES/output-2020-09-01-15:37:39.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/legalnonsense/org-clones/HEAD/IMAGES/output-2020-09-01-15:37:39.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /org-clones-past.el 2 | org-clones-edit.el 3 | /#org-clones-edit.el# 4 | /#org-clones-ert.org# 5 | /#README.org# 6 | /#org-clones-ert-2.org# 7 | /#org-clones-ert.el# 8 | /#org-clones.el# 9 | /#test.org# 10 | /#test1.org# 11 | /#test2.org# 12 | /org-clones-ert-2.org 13 | /org-clones-ert.el 14 | /org-clones-ert.org 15 | /org-clones.elc 16 | /test2.org 17 | /#test3.org# 18 | /#test4.org# 19 | /test.org~ 20 | /test1.org~ 21 | /test3.org 22 | /test4.org 23 | /org-clones-scratch.el 24 | test.org 25 | test1.org 26 | /#speed-test-sample.org# 27 | /#speed-test.org# 28 | /speed-test-sample.org 29 | /speed-test.org 30 | /#test666.org# 31 | /#test999.org# 32 | /clones.el 33 | /temp.el 34 | /test666.org 35 | /test999.org 36 | /#clones.el# 37 | /#test5.org# 38 | /test5.org 39 | /#asdfasdf.org# 40 | /#qq.org# 41 | /#test444.org# 42 | /#test6.org# 43 | /#test667.org# 44 | /#test777.org# 45 | /#xxxxx.org# 46 | /.#qq.org 47 | /.#xxxxx.org 48 | /asdfasdf.org 49 | /asdfasdfasdf.org 50 | /asdfasdfasdf.org~ 51 | /llllllllll.org 52 | /llllllllll.org~ 53 | /qq.org 54 | /test222.org 55 | /test444.org 56 | /test6.org 57 | /test667.org 58 | /xxxxx.org 59 | /TEST/#org-clones-ert.el# 60 | /TEST/#org-clones-ert.org# 61 | /TEST/#test.org# 62 | /TEST/#test1.org# 63 | /TEST/org-clones-ert.org 64 | /TEST/#org-clones-ert-tests.org# 65 | /TEST/org-clones-ert-tests.org 66 | /new.el 67 | /new.org 68 | -------------------------------------------------------------------------------- /TEST/org-clones-ert.el: -------------------------------------------------------------------------------- 1 | ;;; org-clones-ert.el --- Testing -*- lexical-binding: t; -*- 2 | 3 | (defun org-clones-ert--replace-buffer-text (text) 4 | (erase-buffer) 5 | (insert text) 6 | (goto-char (point-min))) 7 | 8 | (setq org-clones-ert--body-test-text 9 | "* done [#A] COMMENT Parent node [0%] [0/0] :tags: 10 | SCHEDULED: <2020-09-04 Fri> DEADLINE: <2020-09-04 Fri> 11 | :PROPERTIES: 12 | :ID: b2b87a7a-a80e-4ca7-bbc8-5de56b7a1729 13 | :ORG-CLONES: 3c4195b4-8762-48ff-8dd7-adb6988d4020 14 | :END: 15 | - CLOSING NOTE [2020-09-04 Fri 10:23] \\ 16 | asdfasdfasdf 17 | akkdsf 18 | 19 | ** done [#B] Parent node :more:tags: 20 | :PROPERTIES: 21 | :ID: 3c4195b4-8762-48ff-8dd7-adb6988d4020 22 | :ORG-CLONES: b2b87a7a-a80e-4ca7-bbc8-5de56b7a1729 23 | :END: 24 | akkdsf 25 | 26 | ** another headline ") 27 | 28 | (ert-deftest org-clones--body-functions-test () 29 | (with-current-buffer (get-buffer-create "org-clones-ert-tests.org") 30 | (org-mode) 31 | (org-clones-ert--replace-buffer-text 32 | "* done [#A] COMMENT Parent node [0%] [0/0] :tags: 33 | SCHEDULED: <2020-09-04 Fri> DEADLINE: <2020-09-04 Fri> 34 | :PROPERTIES: 35 | :ID: b2b87a7a-a80e-4ca7-bbc8-5de56b7a1729 36 | :ORG-CLONES: 3c4195b4-8762-48ff-8dd7-adb6988d4020 37 | :END: 38 | - CLOSING NOTE [2020-09-04 Fri 10:23] \\ 39 | asdfasdfasdf 40 | akkdsf 41 | 42 | ** done [#B] Parent node :more:tags: 43 | :PROPERTIES: 44 | :ID: 3c4195b4-8762-48ff-8dd7-adb6988d4020 45 | :ORG-CLONES: b2b87a7a-a80e-4ca7-bbc8-5de56b7a1729 46 | :END: 47 | akkdsf 48 | 49 | ** another headline ") 50 | (org-clones--replace-body "12345") 51 | (should (string= (org-clones--get-body-string) 52 | "12345\n")) 53 | (outline-next-heading) 54 | (should (string= (org-clones--get-body-string) 55 | "akkdsf\n")) 56 | (outline-next-heading) 57 | (should (string= (org-clones--get-body-string) 58 | "")) 59 | (goto-char (point-min)) 60 | (org-add-note) 61 | 62 | 63 | (ert 'org-clones--body-functions-test) 64 | 65 | (ert-deftest org-clones--headline-functions-test () 66 | (with-current-buffer (get-buffer-create "org-clones-ert-tests.org") 67 | (org-mode) 68 | ;; Node with children 69 | (org-clones-ert--replace-buffer-text "* Parent node\n** Child node1\n** Child node2") 70 | (should (string= (org-clones--get-headline-string) "Parent node")) 71 | (outline-next-heading) 72 | (should (string= (org-clones--get-headline-string) "Child node1")) 73 | 74 | ;; Node with TODO, progress cookie, and tags 75 | (org-clones-ert--replace-buffer-text "* TODO Parent [0/0] node :tags1:tags2:") 76 | (org-clones--normalize-headline) 77 | (should (string= (org-clones--get-headline-string) "Parent node")) 78 | 79 | (org-clones--replace-headline "some new text [4/5]") 80 | (org-clones--normalize-headline) 81 | (should (string= (buffer-substring-no-properties (point-at-bol) (point-at-eol)) 82 | "* TODO some new text [4/5] [0/0] :tags1:tags2:")) 83 | 84 | ;; COMMENT, progress cookie, tags, and stray colons 85 | (org-clones-ert--replace-buffer-text "*** COMMENT [55%] Parent: node :tags:") 86 | ;;(org-clones--normalize-headline) 87 | (should (string= (org-clones--get-headline-string) " ")) 88 | 89 | (org-clones-ert--replace-buffer-text "*** COMMENT [55%] Parent :node :tags:") 90 | (org-clones--normalize-headline) 91 | (should (string= (org-clones--get-headline-string) "Parent :node")) 92 | 93 | ;; Multiple progress cookies 94 | (org-clones-ert--replace-buffer-text "*** COMMENT [55%] Parent: [4/5] node :tags:") 95 | (org-clones--normalize-headline) 96 | (should (string= (org-clones--get-headline-string) 97 | "Parent: node")) 98 | 99 | (org-clones-ert--replace-buffer-text "* TODO [#C] COMMENT test src_elisp{(org-entry-get (point) \"ASD\")} [1/2] {{{results(=123=)}}}\n:PROPERTIES:\n\n:ASD: 123\n:ID: c39ce8ba-d96b-49eb-9642-20e2ee9ad045\n:END:\n") 100 | (org-clones--normalize-headline) 101 | (should (string= (org-clones--get-headline-string) "test src_elisp{(org-entry-get (point) \"ASD\")}")) 102 | 103 | (org-clones-ert--replace-buffer-text "* TODO COMMENT test src_elisp{(org-entry-get (point) \"ASD\")} [#C] [1/2] {{{results(=123=)}}} :tags:more_tags:\n:PROPERTIES:\n\n:ASD: 123\n:ID: c39ce8ba-d96b-49eb-9642-20e2ee9ad045\n:END:\n") 104 | (org-clones--normalize-headline) 105 | (should (string= (org-clones--get-headline-string) "test src_elisp{(org-entry-get (point) \"ASD\")}")) 106 | 107 | (org-clones-ert--replace-buffer-text "*** COMMENT [55%] Parent: [4/5] node :tags:") 108 | (org-clones--normalize-headline) 109 | (should (string= (org-clones--get-headline-string) 110 | "Parent: node")) 111 | (org-clones--replace-headline "PARENT NODE!") 112 | (should (string= (buffer-substring-no-properties (point-at-bol) (point-at-eol)) 113 | "*** COMMENT PARENT NODE! [55%] [4/5] :tags:")) 114 | 115 | (org-clones--replace-headline "PARENT COMMENT !") 116 | (should (string= (buffer-substring-no-properties (point-at-bol) (point-at-eol)) 117 | "*** COMMENT PARENT COMMENT ! [55%] [4/5] :tags:")) 118 | 119 | (org-clones-ert--replace-buffer-text "* TODO [#A] COMMENT Parent [50%] node :tags2:tags3:") 120 | (org-clones--normalize-headline) 121 | (should (string= (org-clones--get-headline-string) 122 | "Parent node")) 123 | 124 | (org-clones-ert--replace-buffer-text "* TODO [#A] Parent COMMENT [50%] node :tags2:") 125 | (org-clones--normalize-headline) 126 | (should (string= (org-clones--get-headline-string) 127 | "Parent COMMENT node")) 128 | 129 | (org-clones-ert--replace-buffer-text "*** [#A] COMMENT [55%] Parent: [4/5] node :tags:") 130 | (org-clones--normalize-headline) 131 | (should (string= (org-clones--get-headline-string) 132 | "Parent: node")))) 133 | 134 | (ert 'org-clones--headline-functions-test) 135 | 136 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * Org-clones 2 | +This package is still being developed and tested. Feedback and bug reports are welcome. Use at your own risk.+ 3 | This package is abandoned. The ideas are being translated to a new package. I am keeping this up in the event anyone finds the approach used here interesting. Otherwise, please don’t plan to use this. 4 | 5 | Clone Orgmode headings so they appear in multiple locations, and sync edits between clones. 6 | 7 | [[file:IMAGES/output-2020-09-01-15:37:39.gif]] 8 | 9 | * Why clones? 10 | Anyone who has made an outline has run into the problem that an entry belongs in two places. For example: 11 | #+begin_src org 12 | * Animals 13 | ** Dogs 14 | ** Cats 15 | * Things with four legs that I don’t like very much 16 | ** Tables 17 | ** Dogs 18 | #+end_src 19 | Oh no. The Dogs header belongs in two places. Now suppose that the Dogs header contains everything you know about dogs. 20 | 21 | You could handle this with links, so that you have a source Dog header and subsequent headers simply link back to it. I do not like that solution. I want to clone the header so that it appears in different places in an outline, including in different files. When I edit one of these clones, I want the changes to sync to all the other clones automatically. 22 | 23 | Clones are a type of [[https://en.wikipedia.org/wiki/Transclusion][transclusion]], meaning that text from one file appears in another place, with edits synced back to the original source. It is a prominent featuree of Leo Editor, /see/ https://leoeditor.com/tutorial-pim.html, which I wish I could use but it’s not in Emacs so it is dead to me. 24 | 25 | My use case is that I maintain one org file with ongoing research. This file is full of well-written and researched academic work, half-thoughts, notes, links, etc. Sometimes I need to use that research in a paper I am writing. When I do so, I inevitably edit and expand (or contract) the work I have already done. I want this new work—even though it is being written in a different file—to be synced back to my source research file. Before now, there did not appear to be a good and simply way to do this. 26 | 27 | I do not use [[https://www.orgroam.com/][org-roam]] or any other package involving the Zettlekasten, or other, note taking method. My brain is simple. I like outlines and only outlines. Anything beyond a simple outline results in diministed productivity. 28 | 29 | * Terminology 30 | I use the following teminology in the package: 31 | 32 | - Node :: an entry in an org outline 33 | - Headline :: the headline text of the node, but does not include the headline's todo state or tags 34 | - Body :: everything after the headline, planning line, and property drawers until the next node 35 | 36 | * Basics 37 | 1. Only the headline and body of a node are cloned. 38 | 2. Tags, TODO states, priorities, planning lines, property drawers, logbooks, and closing note logs, are not cloned and remain independent. You can change these properties on an individual basis without affecting any clones. (See [[https://raw.githubusercontent.com/legalnonsense/org-clones/master/IMAGES/output-2020-09-01-15%3A15%3A40.gif][here]] for a demonstration in a "busy" file.) 39 | 3. Anything in the body of a clone (e.g., text, source blocks, tabes, etc.) will be cloned. Only the items listed above aree ignored. 40 | 4. Child nodes of clones are not cloned. Only the node itself is cloned. If you want the children to be cloned, you must clone them separately. 41 | 5. Clones can be reordered, promoted, demoted, and appear anywhere in an org outline or in a different org file. All that matters is that =org-id= can find it. 42 | 43 | * Installation 44 | There are no outside dependencies. Place =org-clones.el= in your load path and =(require 'org-clones)=. You can then activate =(org-clones-mode)=. If you create a clone without turning on the mode first, =org-clones-mode= will be enabled automatically. 45 | 46 | In the alternative, this use-package declaration includes all customizable variables, commands, faces, and my own keymap, which you can easily customize: 47 | #+begin_src emacs-lisp :results silent 48 | (use-package org-clones 49 | :hook 50 | ;; Note: `org-clones-mode' will only activate 51 | ;; `cursor-sensor-mode' if there are cursor-sensor-properties 52 | ;; in the buffer. Therefore, you can safely add `org-clones-mode' 53 | ;; to `orgmode-hook' even if you don't plan to use it in every file. 54 | (orgmode . org-clones-mode) 55 | :custom 56 | (org-clones-commit-edit-shortcut "C-c C-c") 57 | (org-clones-abort-edit-shortcut "C-c C-k") 58 | (org-clones-start-edit-shortcut "C-c C-c") 59 | (org-clones-jump-to-next-clone-shortcut "n") 60 | (org-clones-clone-prefix-icon "◈ ") 61 | (org-clones-empty-body-string "[empty clone body]") 62 | (org-clones-empty-headling-string "[empty clone headline]") 63 | (org-clones-prompt-before-syncing nil) 64 | (org-clones-use-popup-prompt nil) 65 | :custom-face 66 | (org-clones-current-clone ((t (:background "orchid" :foreground "black")))) 67 | (org-clones-clone ((t (:background "black")))) 68 | :bind 69 | (("C-; C-c C-m" . org-clones-store-marker) 70 | ("C-; C-c C-c" . org-clones-create-clone-dwim) 71 | ("C-; C-c C-d" . org-clones-delete-this-clone) 72 | ("C-; C-c C-j" . org-clones-jump-to-clones) 73 | ("C-; C-c C-u" . org-clones-unclone-this-clone))) 74 | #+end_src 75 | 76 | * Usage 77 | ** Clone creation 78 | 1. Put the cursor at the place you want to create a heading, run =org-clones-create-clone=, which will prompt the user to select a source node with =(org-goto)= and create a new heading at point. 79 | 2. Run =org-clones-store-marker=, then place the point at a new location (which can be a different org file) and run =org-clones-create-clone-from-marker=. 80 | 3. Run =org-clones-create-clone-dwim= creates a clone from a stored marker if there is one, and otherwise prompts the user for the source. 81 | ** Display 82 | Clones are marked by placing an icon in front of the clone’s headline. This icon can be customized by changing =org-clones-clone-prefix-icon=. The headline and body of a cloned node receive the =org-clones-clone= face. 83 | 84 | When the cursor moves into the headline or body of a cloned node, an overlay is applied which includes the face =org-clones-current-clone=. At that point, the text in that field becomes read-only, and the user must press =C-c C-c= to begin to edit the clone. (=C-c C-c= continues to work in the usual orgmode way so long as the cursor is not inside a headline field.) 85 | ** Viewing clones 86 | To cycle through clones of the current node, run =org-clones-jump-to-clones=. Then, press =n= to jump from one clone to another in a loop. Exit with =C-g= or any other key. 87 | ** Editing clones 88 | 1. When the cursor enters a cloned headline or body, the text becomes read only. To edit the text, type =C-c C-c=. 89 | 2. To complete an edit, type =C-c C-c= again. To discard the edit, type =C-c C-k=. 90 | 3. After the edit is completed, all clones will be updated automatically. (If you want an additional prompt before syncing, set =org-clones-prompt-before-sync= to non-nil.) 91 | ** Uncloning a clone 92 | If you do not want a clone to be synced, run =org-clones-unclone-this-clone=. The node's ID will removed from all other clones, and the node's =:ORG-CLONES:= property will be set to nil. The node will not otherwise be affected. 93 | ** Caveats 94 | 1. =Org-clones= does not (currently) check for conflicts before syncing clones. Sync at your own risk. 95 | 2. =Org-clones= relies on =cursor-sensor-mode=. I have not profiled to see what type of slowdown one might experience in a large file due to =cursor-sensor-mode=. My files are not large enough for this to be a concern. 96 | 3. =Org-clones= currently relies on =org-id=. =Org-id= sometimes has problems finding the location of an id, especially in a file that has just been created. Before you blame =org-clones= for a clone not syncing, make sure the file you are using appears in =org-id-locations=. Make use of =org-id-update-id-locations= if you must. You can test whether =org-id= is working as it should by manually trying =(org-id-goto "INSERT ID HERE")=. If that does not work, =org-clones= will not work. I find that saving the file and creating a few ids with =(org-id-get-create)= in some dummy headers, and re-saving the file, eventually solves the problem. (I have used =org-id= for years before noticing this issue and only discovered it when testing this package. Perhaps you will not encouter it.) 97 | 4. If =org-clones= cannot find a clone, it does not remove the clone from the clone list automatically (due to the issues with =org-id=, supra, or other issues involving multiple files/computers). 98 | 5. If you try to create a new node while editing the body of a clone, you are asking for trouble. =Org-clones= will be confused, and make a mess of everything. I will figure out a good way to prevent this in the future. For now, don't do it. 99 | 100 | * Custom variables, faces, and commands 101 | Most of this is laid out above, but just in case: 102 | ** Faces 103 | | Face | Usage | 104 | |--------------------------+-----------------------------------------------------------------------------------------------------------| 105 | | org-clones-current-clone | Applied to the headline or body of a clone, depending on whether the point is within the headline or body | 106 | | org-clones-clone | Applied to the headline and body of every clone, regardless of whether the point is on the clone | 107 | ** Custom Variables 108 | | Variable | Behavior | Default value | 109 | |----------------------------------------+---------------------------------------------------------------------------------------------------------------+--------------------------| 110 | | =org-clones-commit-edit-shortcut= | Shortcut to commit an edit to a clone and sync all clones | "C-c C-c" | 111 | | =org-clones-abort-edit-shortcut= | Shortcut to abort an edit and return the clone to its previos state | "C-c C-k" | 112 | | =org-clones-start-edit-shortcut= | Shortcut to start editing a clone, when the cursor is in a cloned region | "C-c C-c" | 113 | | =org-clones-jump-to-next-clone-shortcut= | Shortcut to cycle to the next clone after running =(org-clones-cycle-through-clones)= | "n" | 114 | | =org-clones-clone-prefix-icon= | Icon which precedes the headline of any cloned node | "◈ " | 115 | | =org-clones-empty-body-string= | You're not allowed to have a blank body in a clone. If you clone a node without a body, use this place holder | "[empty clone body]" | 116 | | =org-clones-empty-headling-string= | I don't know why anyone would clone a node without a headline, but in case you try, use this place holder | "[empty clone headline]" | 117 | | =org-clones-prompt-before-syncing= | Do you want an extra warning before syncing clones? | nil | 118 | | =org-clones-use-popup-prompt= | If you do want an extra warning, do you want it in the minibuffer (default) or a pop up window? | nil | 119 | ** Commands 120 | =Org-clones= provides the following interactive commands: 121 | | Command | Effect | 122 | |-------------------------------------+--------------------------------------------------------------------------------------------------------| 123 | | =org-clones-create-clone= | Create a clone of the node at point, directly below the current node. | 124 | | =org-clones-store-marker= | Store the current mode to create a clone in a different place | 125 | | =org-clones-create-clone-from-marker= | After storing a node with =org-clones-store-marker=, create a clone of that node at point | 126 | | =org-clones-create-clone-dwim= | Create a clone from the stored marker if one is stored; otherwise, prompt the user for the source node | 127 | 128 | * How it works 129 | ** Defining a headline 130 | Org-clones automatically moves and progress cookie to the and of a headline, before the tags. It also assumes that the {{{results}}} of an inline source block will appear at the end of a heading, but before the tags and before any progress cookies. With those adjustment, the format of a headline is: 131 | 132 | Todo Priority-cookie Comment *Headline-text* Inline-results Progress-cookie Tags 133 | 134 | The only thing org-clones will sync is the headline-text. 135 | 136 | ** Functionality 137 | - 138 | - Clones are tracked via the Orgmode property =:ORG-CLONES:= which contains a list of IDs which correspond to other cloned nodes. 139 | - A cursor-sensor-function property is placed on each headline and body of each node. 140 | - When the cursor enters that field, =org-clones= places a transient overlay over the field to alert the user that they are on a cloned node. 141 | - =Org-clones= also makes the field read-only. This prevents inadvertent edits. Because clones only become read-only when the cursor is within the field, you can still kill and yank headlines, etc., without running into issues with the text being read only. 142 | - The transient overlay has a keymap which uses =org-clones-start-edit-shortcut=, bound to =C-c C-c= by default. 143 | - Once the edit mode is invoked, the read-only text property is removed, the header-line appears to remind the user they are editing a clone and showing the shortcuts to commit or abandon the edit. These shortcuts are set with =org-clones-start-edit-shortcut= (=C-c C-c= by default) and =org-clones-abort-edit-shortcut= (=C-c C-k= by default). 144 | - When the user terminates the edit, the read-only text properties are replaced, the header-line is reset to its previous value, and the transient overlay is replaced. Other variables (recording the state of the node before the edit, etc.) are reset to nil). If the user has committed the edit, all other clones are synced automatically. 145 | - When the cursor exits a cloned field without edits, the transient overlay (and its read-only property) is removed. 146 | * Other transclusion efforts 147 | Here are other Emacs transclusion efforts (or discussions of such efforts): 148 | 149 | https://github.com/alphapapa/transclusion-in-emacs 150 | 151 | https://github.com/justintaft/emacs-transclusion 152 | 153 | https://github.com/gregdetre/emacs-freex 154 | * Change log 155 | - [2020-09-03 Thu] Add org-capture hook to capture and sync edits to a clone via org-capture 156 | - [2020-09-02 Wed] Fix progress cookies and unrelated issue concerning org-clones improperly placing the body of a parent node inside a child node when syncing clones 157 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /org-clones.el: -------------------------------------------------------------------------------- 1 | ;;; org-clones.el --- Clone Orgmode headings -*- lexical-binding: t; -*- 2 | 3 | 4 | ;; Copyright (C) 2020 Jeff Filipovits 5 | 6 | ;; Author: Jeff Filipovits 7 | ;; URL: http://www.github.com/legalnonsense/org-clones 8 | ;; Version: 0.1-pre 9 | ;; Package-Requires: ((emacs "25.2")) 10 | ;; Keywords: org transclusion clones outline 11 | 12 | ;; This file is not part of GNU Emacs. 13 | 14 | ;;; Commentary: 15 | 16 | ;; This package creates clones org headings. It uses the following 17 | ;; terminology: 18 | 19 | ;; "Node" means an entry in an org outline 20 | ;; 21 | ;; "Headline" means the headline text of the entry, but does 22 | ;; not include the headline's todo state or tags 23 | ;; 24 | ;; "Body" means everything after the headline, planning line, 25 | ;; and property drawers until the next node. 26 | 27 | ;; This package allows the user to clone a node, which duplicates 28 | ;; the node's headline and body. An overlay is then placed over each clone. 29 | ;; If the user attempts to edit the clone, they are prompted to either enter 30 | ;; an edit-mode, which will sync all changes to other clones upon completion, 31 | ;; or to unlink the clone. 32 | 33 | ;;;; Installation 34 | 35 | ;;;;; Manual 36 | 37 | ;; Put this file in your load-path, and put this in your init 38 | ;; file: 39 | 40 | ;; (require 'org-clones) 41 | 42 | ;;;; Usage 43 | 44 | ;; M-x `org-clones-mode' (or add it to your org-mode hook). 45 | ;; With the cursor on an org heading, run 46 | ;; `org-clones-create-clone'. You have created a clone. 47 | ;; Edit the clone, and your edits will sync. 48 | ;; You can also create clones across files with 49 | ;; `org-clones-store-marker' at an org heading and 50 | ;; running `org-clones-create-clone-from-marker' 51 | ;; at the location (of any file) where you want the 52 | ;; clone. 53 | 54 | ;; See http://www.github.com/legalnonsense/org-clones for more 55 | ;; information. 56 | 57 | ;;;; Tips 58 | 59 | ;; + You can customize settings in the `org-clones' group. 60 | 61 | ;;; License: 62 | 63 | ;; This program is free software; you can redistribute it and/or modify 64 | ;; it under the terms of the GNU General Public License as published by 65 | ;; the Free Software Foundation, either version 3 of the License, or 66 | ;; (at your option) any later version. 67 | 68 | ;; This program is distributed in the hope that it will be useful, 69 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 70 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 71 | ;; GNU General Public License for more details. 72 | 73 | ;; You should have received a copy of the GNU General Public License 74 | ;; along with this program. If not, see . 75 | 76 | ;;; Code: 77 | 78 | ;;;; Requirements 79 | 80 | (require 'org) 81 | (require 'org-id) 82 | (require 'org-element) 83 | 84 | ;;;; Customization 85 | 86 | (defgroup org-clones () 87 | "Heading transclusion for Orgmode files." 88 | :group 'org 89 | :prefix "org-clones-") 90 | 91 | (defcustom org-clones-commit-edit-shortcut "C-c C-c" 92 | "Shortcut to commit edits when in `org-clones-edit-mode' 93 | Accepts any string acceptable to `kbd'." 94 | :group 'org-clones 95 | :type 'string) 96 | 97 | (defcustom org-clones-abort-edit-shortcut "C-c C-k" 98 | "Shortcut to abort edits when in `org-clones-edit-mode' 99 | Accepts any string acceptable to `kbd'." 100 | :group 'org-clones 101 | :type 'string) 102 | 103 | (defcustom org-clones-start-edit-shortcut "C-c C-c" 104 | "Shortcut to initiate `org-clones-edit-mode' 105 | Accepts any string acceptable to `kbd'." 106 | :group 'org-clones 107 | :type 'string) 108 | 109 | (defcustom org-clones-jump-to-next-clone-shortcut "n" 110 | "Shortcut to jump to next clone via `org-clones-jump-to-clones' 111 | Accepts any string acceptable to `kbd'." 112 | :group 'org-clones 113 | :type 'string) 114 | 115 | (defcustom org-clones-clone-prefix-icon "◈ " 116 | "String prepended to the headline of a cloned node." 117 | :group 'org-clones 118 | :type 'string) 119 | 120 | (defcustom org-clones-empty-body-string "[empty clone body]" 121 | "Place holder inserted into clones with empty bodies. 122 | Can be any string other than whitespace. Must end with a newline. 123 | Must be a string other than whitespace." 124 | :group 'org-clones 125 | :type 'string) 126 | 127 | (defcustom org-clones-empty-headling-string "[empty clone headline]" 128 | "Place holder inserted into clones with empty headlines. 129 | Must be a string other than whitespace." 130 | :group 'org-clones 131 | :type 'string) 132 | 133 | (defcustom org-clones-use-popup-prompt nil 134 | "Whether to use a dialog box to prompt before syncing clones." 135 | :group 'org-clones 136 | :type 'boolean) 137 | 138 | (defcustom org-clones-prompt-before-syncing nil 139 | "Whether to prompt the user before syncing changes to all clones." 140 | :group 'org-clones 141 | :type 'boolean) 142 | 143 | ;;;; Keymaps 144 | 145 | (defvar org-clones--clone-cycle-map 146 | (let ((map (make-sparse-keymap))) 147 | (define-key map (kbd org-clones-jump-to-next-clone-shortcut) 148 | #'org-clones-jump-to-clones) 149 | map) 150 | "Transient keymap for clone cycling.") 151 | 152 | (defvar org-clones--transient-clone-overlay-map 153 | (let ((map (make-sparse-keymap))) 154 | (define-key map (kbd org-clones-start-edit-shortcut) 155 | #'org-clones--begin-edit) 156 | map) 157 | "Keymap for transient overlays.") 158 | 159 | ;;;; Faces 160 | 161 | (defgroup org-clones-faces () 162 | "Faces for org-clones." 163 | :group 'org-clones) 164 | 165 | (defface org-clones-current-clone 166 | '((t (:background "orchid" :foreground "black"))) 167 | "Face applied when the point is inside a cloned 168 | node (i.e., headline or body)." 169 | :group 'org-clones-faces) 170 | 171 | (defface org-clones-clone 172 | '((t (:background "black"))) 173 | "Face applied to the headline and body of each cloned node." 174 | :group 'org-clones-faces) 175 | 176 | ;;;; Variables 177 | 178 | (defvar org-clones--cursor-sensor-functions '(org-clones--text-watcher) 179 | "List of cursor-sensor-functions to apply to the headline 180 | and body of cloned nodes.") 181 | 182 | (defvar org-clones--temp-marker nil 183 | "Temporary storage for a marker for clone creation.") 184 | 185 | (defvar org-clones--clone-cycle-list nil 186 | "Temporary storage when cycling through clones.") 187 | 188 | (defvar org-clones--clone-cycle-buffer-list nil 189 | "Temporary storage for the buffer name and `header-line-format' 190 | list when cycling through clones.") 191 | 192 | (defvar org-clones--clone-cycle-header-msg 193 | "Press 'n' to jump to next clone; any key to quit." 194 | "Message displayed in the header-line when cycling 195 | through clones.") 196 | 197 | (defvar org-clones--transient-overlay-properties 198 | `(face org-clones-current-clone 199 | keymap ,org-clones--transient-clone-overlay-map 200 | priority 1000 201 | evaporate t) 202 | "Properties to be added to the transient overlay.") 203 | 204 | (defvar org-clones--clone-headline-overlay-props 205 | `(before-string ,org-clones-clone-prefix-icon 206 | evaporate t) 207 | "Overlays placed on each clone, regardless of whether the 208 | cursor is on the cloned node. Must be a plist of overlay properties. 209 | By default, this only displays `org-clones-clone-prefix-icon'.") 210 | 211 | (defvar org-clones--edit-mode-header-line 212 | '(:eval 213 | (format 214 | "Edit cloned node. '%s' to finish and update. '%s' to abandon." 215 | org-clones-commit-edit-shortcut 216 | org-clones-abort-edit-shortcut)) 217 | "The value of header-line-format when `org-clones-edit-mode' is 218 | invoked.") 219 | 220 | (defvar org-clones--node-text-properties nil 221 | "Text properties to place on the headline and body of each node. 222 | Note: If you want to chage the cursor-sensor-functions property, 223 | (perhaps for use with a different package) use 224 | `org-clones--put-clone-cursor-sensor-props'. This variable is for other 225 | text properties (e.g., a face, keymap, etc.). 226 | 227 | Note: 'face does not work with org-mode. Use 'font-lock-face. 228 | 'keymap does not work with org-mode. Use a keymap in an 229 | overlay instead." ) 230 | 231 | (defvar org-clones--node-overlay-properties 232 | '(face org-clones-clone) 233 | "Overlay properties placed at the headline and body of each node.") 234 | 235 | (defvar-local org-clones--previous-header-line nil 236 | "Temporary storage for the value of `header-line-format'.") 237 | 238 | (defvar-local org-clones--transient-overlay nil 239 | "Temporary holder for the transient headline 240 | or body overlay.") 241 | 242 | (defvar-local org-clones--restore-state nil 243 | "When editing a clone, save the current headline and body 244 | to restore if the edit is abandoned.") 245 | 246 | (defvar org-clones--org-headline-re org-outline-regexp 247 | "Org headline regexp.") 248 | 249 | (defvar org-clones--not-whitespace-re "[^[:space:]]" 250 | "Regexp matching any non-whitespace charcter.") 251 | 252 | (defvar org-clones--progress-cookie-re "\\[[[:digit:]]*/[[:digit:]]*\\]\\|\\[[[:digit:]]*\\%\\]" 253 | "Regexp for org progress cookies, e.g., [2/3] or [55%].") 254 | 255 | (defvar org-clones--inline-code-result-re "{{{.*}}}" 256 | "Regexp for incline org-babel code results") 257 | 258 | (defvar org-clones--headline-comment-re (concat " " org-comment-string " ") 259 | "Regexp for COMMENT prefix for org headlines.") 260 | 261 | (defvar org-clones--priority-cookie-re ".*?\\(\\[#\\([A-Z0-9]\\)\\] ?\\)" 262 | "Regexp for priority cookies for org headlines.") 263 | 264 | (defvar org-clones--tag-re (concat ":" org-tag-re ":") 265 | "Regexp for headline tags.") 266 | 267 | ;;;; Macros 268 | 269 | (defmacro org-clones--iterate-over-clones (&rest body) 270 | "Execute BODY at each clone of node at point." 271 | `(save-excursion 272 | (when-let ((clone-ids (org-clones--get-clone-ids))) 273 | (cl-loop for clone-id in clone-ids 274 | do (org-clones--with-point-at-id clone-id 275 | ,@body))))) 276 | 277 | (defmacro org-clones--iterate-over-all-clones-in-buffer (&rest body) 278 | "Execute BODY at any clone which has a non-nil :ORG-CLONES: property, 279 | in the buffer (but do not iterate over clones outside the buffer)." 280 | `(save-excursion 281 | (goto-char (point-min)) 282 | (while (re-search-forward org-property-drawer-re nil t) 283 | (goto-char (match-beginning 0)) 284 | (when (re-search-forward ":ORG-CLONES:" nil (match-end 0)) 285 | (when (org-entry-get (point) "ORG-CLONES") 286 | ,@body))))) 287 | 288 | (defmacro org-clones--with-point-at-id (id &rest body) 289 | "Switch to the buffer containing the entry with `org-id' ID. 290 | Move the cursor to that entry in that buffer, execute BODY, 291 | move back." 292 | (declare (indent defun)) 293 | `(when-let ((marker (org-id-find ,id 'marker))) 294 | (with-current-buffer (marker-buffer marker) 295 | (goto-char marker) 296 | (org-show-entry) 297 | ,@body))) 298 | 299 | ;;;; Cursor movement functions 300 | 301 | (defun org-clones--goto-previous-non-whitespace-char () 302 | "Move the point back to the nearest non-whitespace character in 303 | the buffer." 304 | (when (re-search-backward org-clones--not-whitespace-re 305 | nil'no-error) 306 | (goto-char (match-end 0)))) 307 | 308 | ;;;; Headline functions 309 | 310 | (defun org-clones--goto-headline-start () 311 | "Goto the first point of the headline, after the 312 | leading stars, TODO state, or COMMENT." 313 | (org-back-to-heading) 314 | ;; Apparently priority cookies can be anywhere in the headline, so 315 | ;; I am just going to do this by comparing the end results of the 316 | ;; appropriate regexp searches. 317 | (let ((new-point 0)) ;; If it stays 0, thow an error later. 318 | (cl-flet ((new-point-p (candidate) 319 | (pcase candidate 320 | ((and (pred numberp) 321 | (pred (< new-point))) 322 | (setq new-point candidate))))) 323 | 324 | ;; Since these fuckers can be in any order, I am just going to 325 | ;; test each of them. This is also already fixed by normalizing 326 | ;; the headline so they are in a predictable order, but that is 327 | ;; not stable yet. 328 | (mapc #'new-point-p `(,(org-clones--goto-after-todo-state) 329 | ,(org-clones--goto-after-priority-cookie) 330 | ,(org-clones--goto-after-leading-stars) 331 | ,(org-clones--goto-after-comment-indicator))) 332 | (if (= new-point 0) 333 | (error "No headline detected.") 334 | (goto-char new-point))))) 335 | 336 | (defun org-clones--goto-after-todo-state () 337 | "Go to the next non-whitespace point after the TODO state. 338 | Return nil if there is no point." 339 | (org-back-to-heading) 340 | (when (org-get-todo-state) 341 | (when (re-search-forward (org-get-todo-state) (point-at-eol) t) 342 | (forward-char 1) 343 | (point)))) 344 | 345 | (defun org-clones--goto-after-priority-cookie () 346 | "Go to the next non-whitespace point after the priority cookie. 347 | Return nil if there is no point." 348 | (org-back-to-heading) 349 | (when (re-search-forward org-clones--priority-cookie-re (point-at-eol) t) 350 | (point))) 351 | 352 | (defun org-clones--goto-after-comment-indicator () 353 | "Go to the next non-whitespace point after the comment indicator. 354 | Return nil if there is no point." 355 | (org-back-to-heading) 356 | (when (org-in-commented-heading-p) 357 | (re-search-forward org-clones--headline-comment-re 358 | (point-at-eol) t))) 359 | 360 | (defun org-clones--goto-after-leading-stars () 361 | "Go to the next non-whitespace point after the leading stars. 362 | Return nil if there is no point." 363 | (org-back-to-heading) 364 | (re-search-forward org-clones--org-headline-re 365 | (point-at-eol) t)) 366 | 367 | (defun org-clones--get-headline-start () 368 | "Get the point at the start of the headling, after 369 | the leading stars." 370 | (save-excursion 371 | (org-clones--goto-headline-start))) 372 | 373 | (defun org-clones--normalize-headline () 374 | "Move any progress tracking cookie to the end of the headline." 375 | (org-clones--fix-progress-cookie-location) 376 | (org-clones--fix-priority-cookie-location)) 377 | 378 | (defun org-clones--fix-priority-cookie-location () 379 | "Move any priority cookie in the headline to appear 380 | after the TODO keyword or at the start of the headline 381 | if there is no TODO keyword." 382 | (org-back-to-heading) 383 | (let (match) 384 | (when (re-search-forward org-clones--priority-cookie-re 385 | nil (point-at-eol)) 386 | (setq match (match-string 1)) 387 | (delete-region (match-beginning 1) (match-end 1)) 388 | 389 | ;; If there is a TODO, go after it. 390 | (unless (org-clones--goto-after-todo) 391 | ;; Otherwise, the priority comes first 392 | (org-clones--goto-after-leading-stars)) 393 | (insert match) 394 | (org-back-to-heading)))) 395 | 396 | (defun org-clones--fix-progress-cookie-location () 397 | ;; Move the progress cookies to the end of the headline 398 | (org-back-to-heading) 399 | (let (match cookies) 400 | (while (re-search-forward org-clones--progress-cookie-re 401 | (point-at-eol) 402 | 'no-error) 403 | (setq match (match-string 0)) 404 | (replace-match "") 405 | (when (looking-at " ") 406 | (delete-char 1)) 407 | (push match cookies)) 408 | (unless 409 | (re-search-forward org-clones--tag-re (point-at-eol) t) 410 | (org-end-of-line)) 411 | (cl-loop for cookie in (reverse cookies) 412 | do (insert " " cookie)))) 413 | 414 | (defun org-clones--goto-headline-end () 415 | "Goto the last point of the headline (i.e., before the progress cookie 416 | and tag line." 417 | (org-back-to-heading t) 418 | (cond 419 | ;; We assume that the headline is in this position: 420 | ;; TODO headline babel-results progress-cookie tags 421 | ((re-search-forward org-clones--inline-code-result-re (point-at-eol) t) 422 | (goto-char (match-beginning 0)) 423 | (org-clones--goto-previous-non-whitespace-char)) 424 | ((re-search-forward org-clones--progress-cookie-re (point-at-eol) t) 425 | (goto-char (match-beginning 0)) 426 | (org-clones--goto-previous-non-whitespace-char)) 427 | ((re-search-forward 428 | org-clones--tag-re (point-at-eol) t) 429 | (goto-char (match-beginning 0)) 430 | (org-clones--goto-previous-non-whitespace-char)) 431 | (t (end-of-line))) 432 | (when (re-search-backward org-clones--not-whitespace-re) 433 | (goto-char (match-end 0))) 434 | (point)) 435 | 436 | (defun org-clones--get-headline-end () 437 | "Get the point at the end of the headline, but 438 | before the ellipsis." 439 | (save-excursion (org-clones--goto-headline-end))) 440 | 441 | (defun org-clones--at-headline-p () 442 | "Is the point inside a headline?" 443 | (and (outline-on-heading-p t) 444 | (<= (point) (org-clones--get-headline-end)) 445 | (>= (point) (org-clones--get-headline-start)))) 446 | 447 | (defun org-clones--get-headline-string () 448 | "Get the full text of a headline at point, but excluding: 449 | - leading stars 450 | - TODO state 451 | - COMMENT prefix 452 | - org-babel inline results 453 | - tags 454 | - priority cookies 455 | - progress cookies." 456 | (buffer-substring-no-properties (org-clones--get-headline-start) 457 | (org-clones--get-headline-end))) 458 | 459 | (defun org-clones--delete-headline () 460 | "Delete the headline of the heading at point." 461 | (let ((inhibit-read-only t)) 462 | (unless (string= 463 | (plist-get (cadr (org-element-at-point)) :raw-value) 464 | "") 465 | (delete-region (org-clones--get-headline-start) 466 | (org-clones--get-headline-end))))) 467 | 468 | (defun org-clones--replace-headline (headline) 469 | "Replace the headline text at point with HEADLINE." 470 | (when (string-match "\n" headline) 471 | (error "You can't have a newline in a headline string.")) 472 | (let ((inhibit-read-only t)) 473 | (save-excursion 474 | (org-clones--normalize-headline) 475 | (org-clones--delete-headline) 476 | (org-clones--goto-headline-start) 477 | (insert headline) 478 | (org-align-tags)))) 479 | 480 | ;;;; Body functions 481 | 482 | (defun org-clones--node-body-p () 483 | "Does this node have a body (i.e., a 'section' in org-element 484 | parlance)?" 485 | (org-back-to-heading) 486 | (org-clones--parse-body)) 487 | 488 | (defun org-clones--goto-body-end () 489 | "Goto the end of the body of the current node, 490 | and return the point. The end of the body is defined 491 | as the last non-whitespace character before the next heading." 492 | (goto-char (org-entry-end-position)) 493 | (re-search-backward org-clones--not-whitespace-re nil t) 494 | (goto-char (match-end 0)) 495 | (point)) 496 | 497 | (defun org-clones--get-body-end () 498 | "Get the end point of the body of the current node." 499 | (save-excursion (org-clones--goto-body-end))) 500 | 501 | (defun org-clones--goto-body-start () 502 | "Go to the start of the body of the current node, 503 | and return the point. The start of the body is defined as 504 | the point after the planning line, drawers immediately following 505 | the planning line, and any closing note." 506 | (org-end-of-meta-data t) 507 | (let ((section (org-clones--get-section-elements))) 508 | ;; This is a ridiculous way to check if there is a note! 509 | (if (and section 510 | (eq (caar section) 'plain-list) 511 | (eq (car (caddar section)) 'item) 512 | (eq (caaddr (caddar section)) 'paragraph) 513 | ;; I don't think there is a variable to control 514 | ;; the prefix of the closing note, so using "CLOSING NOTE " 515 | ;; and assuming it is static. 516 | (string= (caddr (caddr (caddar section))) "CLOSING NOTE ")) 517 | (goto-char (plist-get (cadar section) :end)) 518 | (point)))) 519 | 520 | (defun org-clones--get-body-start () 521 | "Get the start point of the body of the current node." 522 | (save-excursion (org-clones--goto-body-start))) 523 | 524 | (defun org-clones--at-body-p () 525 | "Is the point inside the body of a node?" 526 | (when-let ((start (org-clones--get-body-start)) 527 | (end (org-clones--get-body-end))) 528 | (and (<= (point) end) 529 | (>= (point) start)))) 530 | 531 | (defun org-clones--normalize-body () 532 | "Placeholder for normalizing the format of a node." 533 | (save-excursion 534 | (org-end-of-meta-data t) 535 | (when (looking-at org-clones--org-headline-re) 536 | (backward-char) 537 | (unless (looking-at "^[[:space:]]") 538 | (insert "\norg-clones-empty-body-string\n"))))) 539 | 540 | (defun org-clones--replace-body (body) 541 | "Replace the body of the current node with 542 | BODY. If BODY is nil, then use `org-clones-empty-body-string'." 543 | (let ((inhibit-read-only t)) 544 | (org-back-to-heading) 545 | (save-excursion 546 | (org-clones--delete-body)) 547 | (org-clones--goto-body-start) 548 | (save-excursion 549 | (insert (or body 550 | org-clones-empty-body-string) 551 | "\n")) 552 | (org-clones--normalize-body))) 553 | 554 | (defun org-clones--parse-body () 555 | "Parse all elements from the start of the body to the next node. 556 | and return the tree beginning with the section element." 557 | (org-element--parse-elements (save-excursion (org-back-to-heading) 558 | (org-end-of-meta-data t) 559 | (point)) 560 | (or (save-excursion (outline-next-heading)) 561 | (point-max)) 562 | 'first-section nil nil nil nil)) 563 | 564 | (defun org-clones--remove-closing-note-from-section-elements (section) 565 | "If there is a closing note in the section, remove it and return the section list." 566 | (if (and (eq (caar section) 'plain-list) 567 | (eq (car (caddar section)) 'item) 568 | (eq (caaddr (caddar section)) 'paragraph) 569 | (string= (caddr (caddr (caddar section))) "CLOSING NOTE ")) 570 | (cdr section) 571 | section)) 572 | 573 | (defun org-clones--get-body-string () 574 | "Get the body of the current node as a string." 575 | (org-no-properties 576 | (org-element-interpret-data 577 | (org-clones--remove-closing-note-from-section-elements 578 | (org-clones--get-section-elements))))) 579 | 580 | (defun org-clones--get-section-elements () 581 | "Reduce the section data to the component elements, 582 | e.g., '((paragraph (...)) 583 | (src-block (...)) ...)." 584 | (cddar (org-clones--parse-body))) 585 | 586 | (defun org-clones--get-body-section-plist () 587 | "Get the plist associated with the section element, 588 | e.g. (:begin 1 :end 10 :contents-begin ...)." 589 | (cadar (org-clones--parse-body))) 590 | 591 | (defun org-clones--delete-body () 592 | (let ((inhibit-read-only t)) 593 | (delete-region (org-clones--get-body-start) 594 | (save-excursion 595 | (outline-next-heading) (point))))) 596 | 597 | (defun org-clones--fold-property-drawer (&optional unfold) 598 | "Fold the property drawer for the heading at point. If 599 | UNFOLD is non-nil, then unfold the drawer." 600 | (save-excursion 601 | (org-back-to-heading t) 602 | (when (re-search-forward 603 | org-property-drawer-re 604 | (save-excursion (or (outline-next-heading) 605 | (point-max))) 606 | 'no-error) 607 | (org-flag-drawer (not unfold))))) 608 | 609 | ;;;; Clone functions 610 | 611 | (defun org-clones--at-clone-p (&optional pos) 612 | "Is the current point (or POS) in a cloned node?" 613 | (org-entry-get (or pos (point)) "ORG-CLONES")) 614 | 615 | (defun org-clones--get-clone-ids () 616 | "Get the org-ids of this node's clones. Return 617 | nil if there are none." 618 | (org-entry-get-multivalued-property 619 | (point) 620 | "ORG-CLONES")) 621 | 622 | (defun org-clones--get-range-of-field-at-point () 623 | "Return a cons cell with the car being the start point and 624 | cdr being the end point of the of the headline or body of the node, 625 | depending on the location of the point." 626 | (cond ((org-clones--at-headline-p) 627 | (cons (org-clones--get-headline-start) 628 | (org-clones--get-headline-end))) 629 | ((org-clones--at-body-p) 630 | (cons (org-clones--get-body-start) 631 | (org-clones--get-body-end))))) 632 | 633 | (defun org-clones--last-node-p () 634 | "Is this the last node in the file?" 635 | (not (or (save-excursion (org-get-next-sibling)) 636 | (save-excursion (org-goto-first-child))))) 637 | 638 | (defun org-clones--prompt-for-source-node-and-move () 639 | "Prompt user for a node and move to it." 640 | (org-goto)) 641 | 642 | (defun org-clones--sync-clones (&optional no-prompt) 643 | "Update all clones of the current node to match 644 | the headline and body of the current node and 645 | place text properties and overlays in the cloned nodes. 646 | If NO-PROMPT is non-nil, do not prompt the user 647 | regardless of the value of `org-clones-prompt-before-syncing'." 648 | (interactive) 649 | (if (and (not no-prompt) 650 | org-clones-prompt-before-syncing) 651 | (org-clones--prompt-before-syncing) 652 | (org-clones--remove-clone-effects) 653 | (org-clones--normalize-headline) 654 | (org-clones--normalize-body) 655 | (let ((inhibit-read-only t) 656 | (headline (org-clones--get-headline-string)) 657 | (body (if (string= "" (org-clones--get-body-string)) 658 | org-clones-empty-body-string 659 | (org-clones--get-body-string)))) 660 | ;; Replace the body in the current node to 661 | ;; normalize whitespace 662 | (org-clones--replace-headline headline) 663 | (org-clones--replace-body body) 664 | (org-clones--put-clone-effects) 665 | (org-clones--iterate-over-clones 666 | (org-clones--remove-clone-effects) 667 | (org-clones--replace-headline headline) 668 | (org-clones--replace-body body) 669 | (org-clones--put-clone-effects)))) 670 | (when org-clones-edit-mode 671 | (org-clones-edit-mode -1)) 672 | (org-clones--put-transient-overlay) 673 | (message "Clones synced.")) 674 | 675 | ;;; Overlays 676 | 677 | (defun org-clones--put-overlay-props (overlay props) 678 | "Add PROPS to OVERLAY and return OVERLAY." 679 | (cl-loop for x from 0 to (1- (length props)) by 2 680 | do (overlay-put overlay 681 | (nth x props) 682 | (nth (1+ x) props)) 683 | finally return overlay)) 684 | 685 | (defun org-clones--put-node-overlay (&optional remove) 686 | "Put `org-clones--node-overlay-properties' in the headline and body of 687 | the node at point. If REMOVE is non-nil, remove the overlays." 688 | (when org-clones--node-overlay-properties 689 | (if remove 690 | (progn 691 | (remove-overlays (org-clones--get-headline-start) 692 | (org-clones--get-headline-end) 693 | 'org-clones-user-overlay t) 694 | (remove-overlays (org-clones--get-body-start) 695 | (org-clones--get-body-end) 696 | 'org-clones-user-overlay t)) 697 | (let* ((headline-overlay (make-overlay (org-clones--get-headline-start) 698 | (org-clones--get-headline-end))) 699 | (body-overlay (make-overlay (org-clones--get-body-start) 700 | (org-clones--get-body-end))) 701 | (props (append org-clones--node-overlay-properties '(org-clones-user-overlay t)))) 702 | (cons (org-clones--put-overlay-props headline-overlay props) 703 | (org-clones--put-overlay-props body-overlay props)))))) 704 | 705 | (defun org-clones--remove-node-overlays () 706 | "Remove `org-clones--node-overlay-properties' from the current node." 707 | (org-clones--put-node-overlay 'remove)) 708 | 709 | (defun org-clones--put-headline-overlay (&optional remove) 710 | "Put overlays in `org-clones--clone-headline-overlay-props' on the 711 | current node. If REMOVE is non-nil, remove the the overlay." 712 | (if remove 713 | (remove-overlays (org-clones--get-headline-start) 714 | (org-clones--get-headline-end) 715 | 'org-clones-clone-headline-overlay t) 716 | (org-clones--remove-headline-overlay) 717 | (let ((headline-overlay (make-overlay (org-clones--get-headline-start) 718 | (org-clones--get-headline-end))) 719 | (props (append org-clones--clone-headline-overlay-props 720 | '(org-clones-clone-headline-overlay t)))) 721 | (org-clones--put-overlay-props headline-overlay props)))) 722 | 723 | (defun org-clones--remove-headline-overlay () 724 | "Remove the overlays in `org-clones--clone-headline-overlay-props' from the 725 | current node." 726 | (org-clones--put-headline-overlay 'remove)) 727 | 728 | (defun org-clones--put-transient-overlay () 729 | "Put the `org-clones--transient-overlay' in the cursor field 730 | at point." 731 | (when-let* ((points (org-clones--get-range-of-field-at-point)) 732 | (beg (car points)) 733 | (end (cdr points))) 734 | (put-text-property beg end 'read-only t) 735 | (move-overlay org-clones--transient-overlay beg end))) 736 | 737 | ;;;; Text properties 738 | 739 | (defun org-clones--put-node-text-properties (&optional remove) 740 | "Put `org-clones--node-text-properties' in the headline and body of 741 | the node at point. If REMOVE is non-nil, remove the properties." 742 | (when org-clones--node-text-properties 743 | (cl-loop for start in `(,(org-clones--get-headline-start) 744 | ,(org-clones--get-body-start)) 745 | for end in `(,(org-clones--get-headline-end) 746 | ,(org-clones--get-body-end)) 747 | do (if remove 748 | (remove-list-of-text-properties 749 | start 750 | end 751 | org-clones--node-text-properties) 752 | (add-text-properties 753 | start 754 | end 755 | org-clones--node-text-properties))))) 756 | 757 | (defun org-clones--remove-node-text-properties () 758 | "Remove `org-clones--node-text-properties' from the current node." 759 | (org-clones--put-node-text-properties 'remove)) 760 | 761 | (defun org-clones--put-clone-effects () 762 | "Put overlay and text properties at the current 763 | node. 'Clone effects' means: cursor sensor properties, 764 | text properties, headline overlay, node overlay, and 765 | automatically folding the property drawer." 766 | (let ((inhibit-read-only t)) 767 | (org-clones--normalize-body) 768 | (org-clones--put-clone-cursor-sensor-props) 769 | (org-clones--put-headline-overlay) 770 | (org-clones--put-node-overlay) 771 | (org-clones--put-node-text-properties) 772 | (org-clones--fold-property-drawer))) 773 | 774 | (defun org-clones--remove-clone-effects () 775 | "Remove overlay and text properties at the current 776 | node." 777 | (let ((inhibit-read-only t)) 778 | (org-clones--remove-node-text-properties) 779 | (org-clones--remove-cursor-sensor-props) 780 | (org-clones--remove-node-overlays) 781 | (org-clones--remove-headline-overlay))) 782 | 783 | (defun org-clones--reset-clone-effects () 784 | "Remove and replace all clone effects for the current 785 | node." 786 | (let ((inhibit-read-only t)) 787 | (org-clones--remove-clone-effects) 788 | (org-clones--put-clone-effects))) 789 | 790 | ;;;; Developement functions 791 | 792 | (defun org-clones--remove-all-cursor-sensors-in-buffer () 793 | "Remove all cursor sensor text properties in the buffer." 794 | (when (y-or-n-p 795 | (concat 796 | "This will remove all cursor-sensor-functions, even " 797 | "those that are not associated with org-clones. Continue?")) 798 | (let ((inhibit-read-only t)) 799 | (set-text-properties 800 | (point-min) 801 | (point-max) 802 | '(cursor-sensor-functions nil))))) 803 | 804 | (defun org-clones--highlight-cursor-sensor-props () 805 | "Highlight any points in the buffer with a non-nil cursor-sensor-functions 806 | text property." 807 | (ov-clear 'org-clones-testing 'any) 808 | (save-excursion 809 | (goto-char (point-min)) 810 | (cl-loop for points being the intervals of (current-buffer) 811 | property 'cursor-sensor-functions 812 | do (when (get-text-property (car points) 813 | 'cursor-sensor-functions) 814 | (ov 815 | (car points) 816 | (cdr points) 817 | 'font-lock-face 818 | '(:background "yellow" :foreground "black") 819 | 'org-clones-testing t))))) 820 | 821 | ;;;; Buffer preparation functions 822 | 823 | (defun org-clones--reset-all-clone-effects-in-buffer () 824 | "Reset all clone effets on all clones in buffer." 825 | (org-clones--iterate-over-all-clones-in-buffer 826 | (org-clones--remove-clone-effects) 827 | (org-clones--put-clone-effects))) 828 | 829 | (defun org-clones--remove-all-clone-effects-in-buffer () 830 | "Remove all clone effets on all clones in buffer." 831 | (org-clones--iterate-over-all-clones-in-buffer 832 | (org-clones--remove-clone-effects))) 833 | 834 | ;;;; Cursor-sensor-functions 835 | 836 | (defun org-clones--change-cursor-sensor-prop (beg end func &optional remove) 837 | "Add FUNC to the list of cursor-sensor-functions from BEG to END. If REMOVE 838 | is non-nil, then remove FUNC from the cursor-sensor-functions property. This 839 | preserves any other functions already stored in the cursor-sensor-fucntions 840 | text property, so it will not interfere with other modes using that text property." 841 | (cl-loop 842 | for pos from beg to end 843 | do (let ((func-list (get-text-property pos 'cursor-sensor-functions))) 844 | (put-text-property 845 | pos (1+ pos) 'cursor-sensor-functions 846 | (if remove 847 | (pcase func-list 848 | ((pred listp) 849 | (remq func func-list)) 850 | ((guard (equal func func-list)) nil) 851 | (_ func-list)) 852 | (pcase func-list 853 | ((pred null) (list func)) 854 | ((pred listp) (cl-pushnew func func-list)) 855 | (_ (if (equal func-list func) 856 | func 857 | (list func func-list))))))))) 858 | 859 | (defun org-clones--put-clone-cursor-sensor-props (&optional remove) 860 | "Put `org-clones--cursor-sensor-functions' on the headline and body 861 | of the current node. Note: these are treated differently than other 862 | text properties because the value is a list and we need to preserve 863 | and pre-existing values." 864 | (cl-loop for start in `(,(org-clones--get-headline-start) 865 | ,(org-clones--get-body-start)) 866 | for end in `(,(org-clones--get-headline-end) 867 | ,(org-clones--get-body-end)) 868 | do (cl-loop for func in org-clones--cursor-sensor-functions 869 | do (org-clones--change-cursor-sensor-prop 870 | start end func remove)))) 871 | 872 | (defun org-clones--remove-cursor-sensor-props () 873 | "Remove `org-clones--cursor-sensor-functions' from the headline and 874 | body of the current node." 875 | (org-clones--put-clone-cursor-sensor-props 'remove)) 876 | 877 | (defun org-clones--text-watcher (_window last-pos entered-or-left) 878 | "If ENTERED-OR-LEFT is eq to 'enter, then place the transient 879 | overlay in the headline or body (as appropriate) and make the text 880 | read only. If the value is 'left, then delete the transient overlay 881 | and remove the read-only text property. See `cursor-sensor-mode' for 882 | details on the arguments." 883 | (pcase entered-or-left 884 | (`entered 885 | (org-clones--put-transient-overlay) 886 | (message "Entered cloned node. Type '%s' to edit." 887 | org-clones-start-edit-shortcut)) 888 | (`left 889 | (when-let* ((points 890 | (save-excursion (goto-char last-pos) 891 | (org-clones--get-range-of-field-at-point))) 892 | (beg (car points)) 893 | (end (cdr points))) 894 | (let ((inhibit-read-only t)) 895 | (put-text-property beg end 'read-only nil) 896 | (delete-overlay org-clones--transient-overlay)))))) 897 | 898 | ;;;; Editing clones 899 | 900 | (defun org-clones--begin-edit () 901 | "Invoke `org-clones-edit-mode'." 902 | (interactive) 903 | (org-clones-edit-mode 1)) 904 | 905 | (defun org-clones--prompt-before-syncing () 906 | "Ask the user if they want to edit the node 907 | without syncing the clones. If so, unlink the current 908 | clone." 909 | (interactive) 910 | ;; Without this let, y-or-n-p pops a dialog box 911 | ;; by default due to something involving `cursor-sensor-mode' 912 | (let ((last-nonmenu-event 913 | (not org-clones-use-popup-prompt))) 914 | (if (y-or-n-p "Sync your changes to all clones?") 915 | (org-clones--sync-clones t) 916 | (if (y-or-n-p "Unsync this clone?") 917 | (org-clones-unclone-this-clone) 918 | (if (y-or-n-p "Discard this edit?") 919 | (org-clones--discard-edit) 920 | ;; If the user takes an impossible path, 921 | ;; send them back to the beginning. 922 | (org-clones--prompt-before-syncing))))) 923 | (org-clones-edit-mode -1)) 924 | 925 | (defun org-clones--discard-edit () 926 | "Discard the current edit and restore the node 927 | to its previous state, and turn off the minor mode." 928 | (interactive) 929 | (org-clones--replace-headline 930 | (car org-clones--restore-state)) 931 | (org-clones--replace-body 932 | (cdr org-clones--restore-state)) 933 | (org-clones--put-clone-effects) 934 | (org-clones-edit-mode -1) 935 | (message "Org-clones: Discarded edit.")) 936 | 937 | (define-minor-mode org-clones-edit-mode 938 | "Mode to edit clones." 939 | nil 940 | " EDIT-CLONE" 941 | (let ((map (make-sparse-keymap))) 942 | (define-key map (kbd org-clones-commit-edit-shortcut) 943 | #'org-clones--sync-clones) 944 | (define-key map (kbd org-clones-abort-edit-shortcut) 945 | #'org-clones--discard-edit) 946 | map) 947 | (if org-clones-edit-mode 948 | (progn 949 | (setq cursor-sensor-inhibit nil) 950 | (setq org-clones--previous-header-line header-line-format) 951 | (setq header-line-format org-clones--edit-mode-header-line) 952 | (setq org-clones--restore-state 953 | (cons (org-clones--get-headline-string) 954 | (org-clones--get-body-string))) 955 | (overlay-put org-clones--transient-overlay 'keymap nil) 956 | (let ((inhibit-read-only t) 957 | (bounds (org-clones--get-range-of-field-at-point))) 958 | (put-text-property (car bounds) (cdr bounds) 'read-only nil))) 959 | (setq header-line-format org-clones--previous-header-line) 960 | (when (equal header-line-format 961 | org-clones--previous-header-line) 962 | (setq header-line-format nil)) 963 | (overlay-put org-clones--transient-overlay 964 | 'keymap 965 | org-clones--transient-clone-overlay-map) 966 | (setq org-clones--restore-state nil))) 967 | 968 | ;;;; Initialization 969 | 970 | (defun org-clones--initialize-transient-overlay () 971 | "Initialize `org-clones--transient-overlay' 972 | used to highlight the clone at point. This overlay is reused 973 | each time the point is in the headline or body of a cloned node." 974 | (setq org-clones--transient-overlay 975 | (make-overlay 1 2 nil nil t)) 976 | (org-clones--put-overlay-props 977 | org-clones--transient-overlay 978 | org-clones--transient-overlay-properties) 979 | (delete-overlay org-clones--transient-overlay)) 980 | 981 | (defun org-clones--initialize-overlays-in-buffer () 982 | "Put overlays on all clones in current buffer." 983 | (org-clones--iterate-over-all-clones-in-buffer 984 | (org-clones--put-headline-overlay))) 985 | 986 | (defun org-clones--cursor-sensor-mode-check () 987 | "Turn `cursor-sensor-mode' on or off depending on 988 | whether there are any cursor-sensor-functions text 989 | properties in the buffer." 990 | (if (save-excursion 991 | (save-restriction 992 | (widen) 993 | (next-single-property-change 994 | (point-min) 995 | 'cursor-sensor-functions))) 996 | ;; If so, enable cursor-sensor-mode... 997 | (cursor-sensor-mode 1) 998 | ;; ...otherwise, disable it. 999 | (cursor-sensor-mode -1))) 1000 | 1001 | (defun org-clones--org-id-precheck () 1002 | "Org-id needs a file to be saved and sometimes needs 1003 | to run `org-id-update-id-locations' for it to work property. 1004 | This forces the user to save the buffer, and makes sure 1005 | `org-id' can find the file and id." 1006 | (if (buffer-file-name) 1007 | ;; (unless (member (buffer-file-name) 1008 | ;; (hash-table-values org-id-locations)) 1009 | ;; TODO: I don't think this fixes the problem. It seems 1010 | ;; like a bug in `org-id'. 1011 | (org-id-update-id-locations (list (buffer-file-name)) 'silent) 1012 | (error "You must save this file before creating a clone"))) 1013 | 1014 | ;;;; Commands 1015 | 1016 | (defun org-clones-jump-to-clones () 1017 | "Allow the user to cycle through any clones 1018 | of the node at point by pressing `org-clones-jump-to-next-clone-shortcut'." 1019 | (interactive) 1020 | (when (org-clones--at-clone-p) 1021 | (unless org-clones--clone-cycle-list 1022 | (setq org-clones--clone-cycle-list 1023 | (append (org-clones--get-clone-ids) 1024 | (list (org-id-get))))) 1025 | (when org-clones--clone-cycle-list 1026 | (set-transient-map 1027 | org-clones--clone-cycle-map t 1028 | ;; Cleanup function for the transient keymap 1029 | (lambda () 1030 | (setq org-clones--clone-cycle-list nil) 1031 | (cl-loop for (buffer . header) in 1032 | org-clones--clone-cycle-buffer-list 1033 | do (with-current-buffer buffer 1034 | (setq header-line-format header))) 1035 | (setq org-clones--clone-cycle-buffer-list nil))) 1036 | (let ((last-pop (pop org-clones--clone-cycle-list))) 1037 | (org-id-goto last-pop) 1038 | (cl-pushnew (cons (buffer-name) 1039 | header-line-format) 1040 | org-clones--clone-cycle-buffer-list 1041 | :test 'equal) 1042 | (setq header-line-format 1043 | org-clones--clone-cycle-header-msg) 1044 | (setq org-clones--clone-cycle-list 1045 | (append org-clones--clone-cycle-list 1046 | (list last-pop))))))) 1047 | 1048 | ;;;###autoload 1049 | (define-minor-mode org-clones-mode 1050 | "Org heading transclusion minor mode." 1051 | nil 1052 | " ORG-CLONES" 1053 | (make-sparse-keymap) 1054 | (if org-clones-mode 1055 | (progn 1056 | (org-clones--initialize-transient-overlay) 1057 | (org-clones--reset-all-clone-effects-in-buffer) 1058 | (org-clones--initialize-overlays-in-buffer) 1059 | (org-clones--cursor-sensor-mode-check) 1060 | (add-hook 'org-capture-after-finalize-hook 1061 | #'org-clones--sync-clones nil t)) 1062 | (org-clones--remove-all-clone-effects-in-buffer) 1063 | (org-clones--cursor-sensor-mode-check) 1064 | (remove-hook 'org-capture-after-finalize-hook 1065 | #'org-clones--sync-clones t))) 1066 | 1067 | ;;;###autoload 1068 | (defun org-clones-delete-this-clone () 1069 | "Delete the clone at point and remove references to it from 1070 | other cloned nodes." 1071 | (interactive) 1072 | (org-back-to-heading) 1073 | (org-clones-unclone-this-clone) 1074 | (let* ((element-plist (cadr (org-element-at-point))) 1075 | (beg (plist-get element-plist :begin)) 1076 | (end (plist-get element-plist :end))) 1077 | (delete-region beg end))) 1078 | 1079 | (defun org-clones-unclone-this-clone () 1080 | "Remove the org-clones property from this node, and remove this 1081 | node's id from any nodes which contain it." 1082 | (interactive) 1083 | (let ((this-id (org-id-get)) 1084 | (clone-ids (org-clones--get-clone-ids))) 1085 | (save-excursion 1086 | (cl-loop for clone-id in clone-ids 1087 | do (org-clones--with-point-at-id clone-id 1088 | (org-entry-remove-from-multivalued-property 1089 | (point) "ORG-CLONES" this-id) 1090 | (unless (org-clones--get-clone-ids) 1091 | (org-clones--remove-clone-effects))))) 1092 | (org-clones--remove-clone-effects) 1093 | (org-set-property "ORG-CLONES" "nil") 1094 | (message "This node is no longer synced with other clones."))) 1095 | 1096 | ;;;###autoload 1097 | (defun org-clones-store-marker () 1098 | "Store a marker to create a clone." 1099 | (interactive) 1100 | (setq org-clones--temp-marker (point-marker)) 1101 | (message "Stored %S for clone creation." 1102 | (org-no-properties 1103 | (org-clones--get-headline-string)))) 1104 | 1105 | ;;;###autoload 1106 | (defun org-clones-create-clone-from-marker () 1107 | "Create a clone from the previously stored marker." 1108 | (interactive) 1109 | (if org-clones--temp-marker 1110 | (org-clones-create-clone org-clones--temp-marker) 1111 | (user-error "You have not stored the source node yet.")) 1112 | (setq org-clones--temp-marker nil)) 1113 | 1114 | ;;;###autoload 1115 | (defun org-clones-create-clone-dwim () 1116 | "Create a clone from the stored marker if it exists; 1117 | otherwise, prompt for the source node." 1118 | (interactive) 1119 | (org-clones-create-clone org-clones--temp-marker) 1120 | (when org-clones--temp-marker 1121 | (setq org-clones--temp-marker nil))) 1122 | 1123 | ;;;###autoload 1124 | (defun org-clones-create-clone (&optional source-marker) 1125 | "Insert a new headline, prompt the user for the source node, 1126 | add clone properties to the source, add clone properties to the clone 1127 | and add the headline and body from the source to the clone. 1128 | SOURCE-POINT is a marker for the location of the source node" 1129 | (interactive) 1130 | (org-clones-mode 1) 1131 | (let (source-headline source-body source-id source-clone-list clone-id) 1132 | ;; At the new heading... 1133 | (org-insert-heading-respect-content) 1134 | (org-clones--org-id-precheck) 1135 | (setq clone-id (org-id-get-create)) 1136 | 1137 | ;; At the source heading... 1138 | (cl-flet ((source-node-prep 1139 | nil 1140 | (org-clones--org-id-precheck) 1141 | (org-back-to-heading) 1142 | (org-clones--remove-clone-effects) 1143 | (setq source-headline (org-clones--get-headline-string)) 1144 | (setq source-body (org-clones--get-body-string)) 1145 | (when (string= "" source-body) 1146 | (org-clones--replace-body nil) 1147 | (setq source-body org-clones-empty-body-string)) 1148 | (setq source-id (org-id-get-create)) 1149 | (org-entry-add-to-multivalued-property (point) 1150 | "ORG-CLONES" 1151 | clone-id) 1152 | (setq source-clone-list (org-clones--get-clone-ids)) 1153 | (org-clones--put-clone-effects))) 1154 | (save-excursion 1155 | (if source-marker 1156 | (with-current-buffer (marker-buffer source-marker) 1157 | (goto-char source-marker) 1158 | (source-node-prep)) 1159 | (org-clones--prompt-for-source-node-and-move) 1160 | (source-node-prep)))) 1161 | 1162 | ;; For each clone from the source, add new clone id 1163 | (cl-loop for clone-id in source-clone-list 1164 | do 1165 | (org-clones--with-point-at-id clone-id 1166 | (cl-loop for clone in source-clone-list 1167 | do 1168 | (unless (string= clone (org-id-get-create)) 1169 | (org-entry-add-to-multivalued-property (point) 1170 | "ORG-CLONES" 1171 | clone))))) 1172 | ;; At the new clone... 1173 | (org-entry-add-to-multivalued-property (point) 1174 | "ORG-CLONES" 1175 | source-id) 1176 | (org-clones--replace-headline source-headline) 1177 | (org-clones--replace-body source-body) 1178 | (org-clones--put-clone-effects))) 1179 | 1180 | ;;;; Footer 1181 | 1182 | (provide 'org-clones) 1183 | 1184 | ;;; org-clones.el ends here 1185 | --------------------------------------------------------------------------------