I started from this post and now have code that already works for the following, for each level 2 heading:
- Add properties drawer
:ANKI_NOTE_TYPE: Basic
to the level 2 heading. - Add two level 3 headings (
Front
andBack
) with empty content.
#+BEGIN_SRC emacs-lisp :results org raw
(let ((MATCH t)
(SCOPE 'file)
(SKIP nil)
(spacing nil))
(org-map-entries
(lambda ()
(let ((level (nth 1 (org-heading-components))))
(if (= level 2)
(save-restriction
(org-narrow-to-subtree)
;; (org-copy-visible)
(org-entry-put (point) "ANKI_NOTE_TYPE" "Basic")
(goto-char (point-max))
(org-insert-heading)
(insert "Front \n")
;; now cut tree and paste at level 3
(org-cut-subtree)
(org-paste-subtree 3)
(org-insert-heading)
(insert "Back \n")
;; (yank)
;; now cut tree and paste at level 3
(org-cut-subtree)
(org-paste-subtree 3)
)))) MATCH SCOPE SKIP))
#+END_SRC
The above is working as expected for my input org chunk:
* Rand
** What is marketing?
** What are the four Ps?
which returns
* Rand
** What's marketing?
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
*** Back
*** Front
** What are the four Ps?
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
*** Back
*** Front
I'm now trying to copy the visible level 2 heading into the contents of the newly created level 3 heading, i.e. trying to get:
* Rand
** What is marketing?
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
*** Back
*** Front
What is marketing?
** What are the four Ps?
:PROPERTIES:
:ANKI_NOTE_TYPE: Basic
:END:
*** Back
*** Front
What are the four Ps?
In my code chunk, I've tried using org-copy-visible
at line 12 then yanking at line 24 (as above, after uncommenting).
However org-copy-visible
seems to be failing with:
save-restriction: Wrong number of arguments: (2 . 2), 0
How should I copy the visible level 2 heading into the contents of the newly created level 3 heading?
EDIT 1: updated example to show behaviour with 2 level 2 headings.
(info "(org) Capture")
%i
,%c
(and to a lesser extent%x
) are your friends. 2.%(sexp "%i")
works as you'd hope. 3. In this casefile+function
is probably the right target type. 4. I might consider (ab)using the clock functionality (clock
target,%k
element) in this case.