No not print empty backlink table when inserting checklist
In case there are not backlinks, replace the empty backlink table with a simple "none". I think that's cleaner :)
This commit is contained in:
parent
d8c8e2b272
commit
bba3adef3d
@ -886,12 +886,20 @@ otherwise."
|
|||||||
(user-error "Cannot find template via TEMPLATE_ID property or top-most sibling"))
|
(user-error "Cannot find template via TEMPLATE_ID property or top-most sibling"))
|
||||||
|
|
||||||
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
||||||
(string-to-number it))))
|
(string-to-number it)))
|
||||||
|
number-of-backlinks
|
||||||
|
point-before-backlinks)
|
||||||
|
|
||||||
(insert (format "\nBacklinks (not DONE, no TEMPLATE, %s, no archives, not scheduled in the future):\n\n"
|
(insert (format "\nBacklinks (not DONE, no TEMPLATE, %s, no archives, not scheduled in the future):\n\n"
|
||||||
(if parent-depth
|
(if parent-depth
|
||||||
(format "parent-depth %d" parent-depth)
|
(format "parent-depth %d" parent-depth)
|
||||||
"all parents")))
|
"all parents")))
|
||||||
|
|
||||||
|
;; Store where we are (minus the two newlines) so we can delete the
|
||||||
|
;; checklist in case it's empty.
|
||||||
|
(setq point-before-backlinks (- (point) 2))
|
||||||
|
|
||||||
|
(setq number-of-backlinks
|
||||||
(org-dblock-write:db/org-backlinks (list
|
(org-dblock-write:db/org-backlinks (list
|
||||||
:org-ql-match '(and
|
:org-ql-match '(and
|
||||||
(not (done))
|
(not (done))
|
||||||
@ -900,6 +908,13 @@ otherwise."
|
|||||||
:parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
:parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
||||||
(string-to-number it))
|
(string-to-number it))
|
||||||
:archive nil)))
|
:archive nil)))
|
||||||
|
|
||||||
|
;; When no backlinks have been found, remove the empty table head and just
|
||||||
|
;; print "none".
|
||||||
|
(when (zerop number-of-backlinks)
|
||||||
|
(delete-region point-before-backlinks (point))
|
||||||
|
(insert " none.")))
|
||||||
|
|
||||||
(insert "\n\nTemplate:\n")
|
(insert "\n\nTemplate:\n")
|
||||||
(db/org-copy-body-from-item-to-point template-pom)))
|
(db/org-copy-body-from-item-to-point template-pom)))
|
||||||
|
|
||||||
@ -1313,6 +1328,8 @@ marker pointing to the current headline."
|
|||||||
(defun org-dblock-write:db/org-backlinks (params)
|
(defun org-dblock-write:db/org-backlinks (params)
|
||||||
"Write table of backlinks for current item and its parent items as Org table.
|
"Write table of backlinks for current item and its parent items as Org table.
|
||||||
|
|
||||||
|
Returns the number of backlinks.
|
||||||
|
|
||||||
PARAMS may contain the following values:
|
PARAMS may contain the following values:
|
||||||
|
|
||||||
:org-ql-match An org-ql-match expression in sexp syntax to filter
|
:org-ql-match An org-ql-match expression in sexp syntax to filter
|
||||||
@ -1389,7 +1406,9 @@ PARAMS may contain the following values:
|
|||||||
priority
|
priority
|
||||||
(apply #'concat (-interpose ", " backlink-targets)))))
|
(apply #'concat (-interpose ", " backlink-targets)))))
|
||||||
(insert "\n|---|")))
|
(insert "\n|---|")))
|
||||||
(org-table-align)))
|
(org-table-align)
|
||||||
|
|
||||||
|
(length output-lines)))
|
||||||
|
|
||||||
(defun db/org-insert-backlink-block ()
|
(defun db/org-insert-backlink-block ()
|
||||||
"Create dynamic block of backlinks to current item or any of its parents."
|
"Create dynamic block of backlinks to current item or any of its parents."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user