mirror of
https://github.com/protesilaos/denote.git
synced 2026-09-15 09:46:24 -04:00
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.
This commit is contained in:
parent
90d7b26142
commit
f58efb7000
42
README.org
42
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'.
|
||||
(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.
|
||||
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")))
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue