Copy complete template for periodic tasks
Previously, we only copied the last element in the subtree, assuming that this encompasses all of the content of the subtree. However, this is not true, and thus we have to do something more elaborate. Now, starting from the end of the subtree, we go up all elements in the subtree until we reach either the headline or a drawer. Everything in between is copied as template to the current location.
This commit is contained in:
parent
b9fe0924f2
commit
03f23b11fb
|
@ -535,15 +535,20 @@ drawers, will be copied to point."
|
||||||
(unless (string-equal (org-element-property :title template-element)
|
(unless (string-equal (org-element-property :title template-element)
|
||||||
"Template")
|
"Template")
|
||||||
(user-error "Template must be first headline in periodic task."))
|
(user-error "Template must be first headline in periodic task."))
|
||||||
;; XXX: trying to get the contents of the current item, without any
|
;; Starting from the end of the last element in the
|
||||||
;; drawers, by going to the end of the template item and marking the
|
;; subtree, we go up until we find a drawer or a
|
||||||
;; element at point, which, incidentally, seems to be the content we are
|
;; headline; everything in between is considered to be the template
|
||||||
;; looking for; this feels hackish, there must be a better way to do it.
|
(let ((content-end (org-element-property :contents-end template-element))
|
||||||
(goto-char (org-element-property :contents-end template-element))
|
content-begin current-element)
|
||||||
(org-mark-element)
|
(goto-char content-end)
|
||||||
(string-trim-right
|
(while (progn
|
||||||
(buffer-substring-no-properties (region-beginning)
|
(setq current-element (org-element-at-point))
|
||||||
(region-end))))))))
|
(not (memq (org-element-type current-element)
|
||||||
|
'(drawer property-drawer headline))))
|
||||||
|
(setq content-begin (org-element-property :begin current-element))
|
||||||
|
(goto-char (1- content-begin)))
|
||||||
|
(string-trim-right
|
||||||
|
(buffer-substring-no-properties content-begin content-end))))))))
|
||||||
(insert template)
|
(insert template)
|
||||||
(org-update-statistics-cookies nil)))
|
(org-update-statistics-cookies nil)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue