Skip to content

Commit

Permalink
Default content to "Back" field if no other child is found
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Leonard Andersen committed Sep 1, 2020
1 parent ff3230f commit b4f27b5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion anki-editor.el
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,44 @@ Where the subtree is created depends on PREFIX."
(values (and value (split-string value))))
(mapcar #'org-entry-restore-space values)))

(defun anki-editor--build-field-from-content-at-point (name)
""
(let* ((element (org-element-at-point))
(format (anki-editor-entry-format))
(begin (cl-loop for eoh = (org-element-property :contents-begin element)
then (org-element-property :end subelem)
for subelem = (progn
(goto-char eoh)
(org-element-context))
while (memq (org-element-type subelem)
'(drawer planning property-drawer))
finally return (org-element-property :begin subelem)))
(end (org-element-property :contents-end element))
(raw (or (and begin
end
(buffer-substring-no-properties
begin
;; in case the buffer is narrowed,
;; e.g. by `org-map-entries' when
;; scope is `tree'
(min (point-max) end)))
"")))
(cons name (anki-editor--export-string raw format))))


(defun leoc/build-fields ()
""
(interactive)
(message "%S" (anki-editor--build-fields)))

(defun anki-editor--build-fields ()
"Build a list of fields from subheadings of current heading.
Return a list of cons of (FIELD-NAME . FIELD-CONTENT)."
(save-excursion
(cl-loop with inhibit-message = t ; suppress echo message from `org-babel-exp-src-block'
initially (unless (org-goto-first-child)
(cl-return))
(cl-return `(,(anki-editor--build-field-from-content-at-point "Back"))))
for last-pt = (point)
for element = (org-element-at-point)
for heading = (substring-no-properties
Expand Down

0 comments on commit b4f27b5

Please sign in to comment.