Allow empty fields

Implements the fix from leoc/anki-editor#1 as suggested in
orgtre/anki-editor#9. Closes orgtre/anki-editor#7.
This commit is contained in:
orgtre 2022-10-31 18:59:52 +01:00
parent efe454f642
commit a6c116b737

View file

@ -628,22 +628,24 @@ Where the subtree is created depends on PREFIX."
;; get contents before first subheading (skipping drawers and planning)
;; FIXME refactor
(save-excursion
(let* ((begin (cl-loop for eoh = (org-element-property :contents-begin (org-element-at-point))
(let* ((element (org-element-at-point))
(begin (cl-loop for eoh = (org-element-property :contents-begin element)
then (org-element-property :end subelem)
while eoh
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 (cl-loop for eoh = (org-element-property :end (org-element-at-point))
finally return (and eoh (org-element-property :begin subelem))))
(end (cl-loop for eoh = (org-element-property :contents-begin element)
then (org-element-property :end nextelem)
while eoh
for nextelem = (progn
(goto-char eoh)
(org-element-at-point))
while (not (memq (org-element-type nextelem) '(headline)))
finally return (org-element-property :begin nextelem)
))
finally return (and eoh (org-element-property :begin nextelem))))
(raw (or (and begin
end
(buffer-substring-no-properties
@ -656,8 +658,7 @@ Where the subtree is created depends on PREFIX."
(content (anki-editor--export-string raw (anki-editor-entry-format))))
(setq content-before-subheading content)
(setq content-before-subheading-raw (string-trim raw))
))
(setq content-before-subheading-raw (string-trim raw))))
(anki-editor--with-collection-data-updated
(when-let ((missing (cl-set-difference
@ -687,7 +688,6 @@ Where the subtree is created depends on PREFIX."
format))
fields))))))
(unless deck (error "Missing deck"))
(unless note-type (error "Missing note type"))
@ -729,12 +729,13 @@ Return a list of cons of (FIELD-NAME . FIELD-CONTENT)."
;; elements and reset contents-begin.
for begin = (cl-loop for eoh = (org-element-property :contents-begin element)
then (org-element-property :end subelem)
while eoh
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))
finally return (and eoh (org-element-property :begin subelem)))
for end = (org-element-property :contents-end element)
for raw = (or (and begin
end