emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote f58efb7000 1/4: Fix my-denote-org-extract-subtre


From: ELPA Syncer
Subject: [elpa] externals/denote f58efb7000 1/4: Fix my-denote-org-extract-subtree section of the README
Date: Thu, 1 Jun 2023 15:57:41 -0400 (EDT)

branch: externals/denote
commit f58efb7000d2f72e14df6d049aa208431188c972
Author: Vedang Manerikar <ved.manerikar@gmail.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Fix my-denote-org-extract-subtree section of the README
    
    The provided function did not work correctly. This commit fixes the
    following issues:
    
    1. Fix: Extract tags before deleting the region from the source file.
    2. Fix: Use `org-end-of-subtree` to calculate the point we should
       delete upto. `org-entry-end-position` ends at the first sub-heading
       under the tree, which is not what we want. Instead, we want to cut
       the whole subtree.
    3. Enhance: Retain the date information available in the subtree. We
       look for three common places for this information -- The CREATED or
       DATE properties in the PROPERTIES drawer, and the CLOSED cookie at
       the element level itself.
---
 README.org | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/README.org b/README.org
index 85b0558d54..1a5c7458b2 100644
--- a/README.org
+++ b/README.org
@@ -2304,23 +2304,35 @@ file.  The contents of the subtree become the contents 
of the new note
 and are removed from the old one.
 
 #+begin_src emacs-lisp
-(defun my-denote-org-extract-subtree ()
-  "Create new Denote note using current Org subtree.
-Make the new note use the Org file type, regardless of the value
-of `denote-file-type'.
-
-Use the subtree title as the note's title.  If available, use the
-tags of the heading are used as note keywords.
-
-Delete the original subtree."
-  (interactive)
-  (if-let ((text (org-get-entry))
-           (heading (org-get-heading :no-tags :no-todo :no-priority 
:no-comment)))
-      (progn
-        (delete-region (org-entry-beginning-position) (org-entry-end-position))
-        (denote heading (org-get-tags) 'org)
-        (insert text))
-    (user-error "No subtree to extract; aborting")))
+  (defun my-denote-org-extract-subtree ()
+    "Create new Denote note using current Org subtree.
+  Make the new note use the Org file type, regardless of the value
+  of `denote-file-type'.
+
+  Use the subtree title as the note's title.  If available, use the
+  tags of the heading are used as note keywords.
+
+  Delete the original subtree."
+    (interactive)
+    (if-let ((text (org-get-entry))
+             (heading (org-get-heading :no-tags :no-todo :no-priority 
:no-comment)))
+        (let ((element (org-element-at-point))
+              (tags (org-get-tags)))
+          (delete-region (org-entry-beginning-position)
+                         (save-excursion (org-end-of-subtree t) (point)))
+          (denote heading
+                  tags
+                  'org
+                  nil
+                  (or
+                   ;; Check PROPERTIES drawer for :created: or :date:
+                   (org-element-property :CREATED element)
+                   (org-element-property :DATE element)
+                   ;; Check the subtree for CLOSED
+                   (org-element-property :raw-value
+                                         (org-element-property :closed 
element))))
+          (insert text))
+      (user-error "No subtree to extract; aborting")))
 #+end_src
 
 Have a different workflow?  Feel welcome to discuss it in any of our



reply via email to

[Prev in Thread] Current Thread [Next in Thread]