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:
parent
efe454f642
commit
a6c116b737
1 changed files with 29 additions and 28 deletions
|
@ -628,36 +628,37 @@ Where the subtree is created depends on PREFIX."
|
||||||
;; get contents before first subheading (skipping drawers and planning)
|
;; get contents before first subheading (skipping drawers and planning)
|
||||||
;; FIXME refactor
|
;; FIXME refactor
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let* ((begin (cl-loop for eoh = (org-element-property :contents-begin (org-element-at-point))
|
(let* ((element (org-element-at-point))
|
||||||
then (org-element-property :end subelem)
|
(begin (cl-loop for eoh = (org-element-property :contents-begin element)
|
||||||
for subelem = (progn
|
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 (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)
|
(goto-char eoh)
|
||||||
(org-element-context))
|
(org-element-at-point))
|
||||||
while (memq (org-element-type subelem)
|
while (not (memq (org-element-type nextelem) '(headline)))
|
||||||
'(drawer planning property-drawer))
|
finally return (and eoh (org-element-property :begin nextelem))))
|
||||||
finally return (org-element-property :begin subelem)))
|
|
||||||
(end (cl-loop for eoh = (org-element-property :end (org-element-at-point))
|
|
||||||
then (org-element-property :end nextelem)
|
|
||||||
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)
|
|
||||||
))
|
|
||||||
(raw (or (and begin
|
(raw (or (and begin
|
||||||
end
|
end
|
||||||
(buffer-substring-no-properties
|
(buffer-substring-no-properties
|
||||||
begin
|
begin
|
||||||
;; in case the buffer is narrowed,
|
;; in case the buffer is narrowed,
|
||||||
;; e.g. by `org-map-entries' when
|
;; e.g. by `org-map-entries' when
|
||||||
;; scope is `tree'
|
;; scope is `tree'
|
||||||
(min (point-max) end)))
|
(min (point-max) end)))
|
||||||
""))
|
""))
|
||||||
(content (anki-editor--export-string raw (anki-editor-entry-format))))
|
(content (anki-editor--export-string raw (anki-editor-entry-format))))
|
||||||
|
|
||||||
(setq content-before-subheading content)
|
(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
|
(anki-editor--with-collection-data-updated
|
||||||
(when-let ((missing (cl-set-difference
|
(when-let ((missing (cl-set-difference
|
||||||
|
@ -686,7 +687,6 @@ Where the subtree is created depends on PREFIX."
|
||||||
(substring-no-properties (org-get-heading t t t))
|
(substring-no-properties (org-get-heading t t t))
|
||||||
format))
|
format))
|
||||||
fields))))))
|
fields))))))
|
||||||
|
|
||||||
|
|
||||||
(unless deck (error "Missing deck"))
|
(unless deck (error "Missing deck"))
|
||||||
(unless note-type (error "Missing note type"))
|
(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.
|
;; elements and reset contents-begin.
|
||||||
for begin = (cl-loop for eoh = (org-element-property :contents-begin element)
|
for begin = (cl-loop for eoh = (org-element-property :contents-begin element)
|
||||||
then (org-element-property :end subelem)
|
then (org-element-property :end subelem)
|
||||||
|
while eoh
|
||||||
for subelem = (progn
|
for subelem = (progn
|
||||||
(goto-char eoh)
|
(goto-char eoh)
|
||||||
(org-element-context))
|
(org-element-context))
|
||||||
while (memq (org-element-type subelem)
|
while (memq (org-element-type subelem)
|
||||||
'(drawer planning property-drawer))
|
'(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 end = (org-element-property :contents-end element)
|
||||||
for raw = (or (and begin
|
for raw = (or (and begin
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue