Remove checklist entry for relevant backlinks when there are none
The original motivation to keep this entry was to signify that backlinks where searched for, but none where found. However, I now think that it is enough to just rely on the code to search for relevant backlinks, and where there are none, to just print nothing.
This commit is contained in:
parent
2318ffa199
commit
94187697e6
@ -1267,7 +1267,7 @@ inserting the checklist."
|
|||||||
|
|
||||||
;; Checklists are inserted directly before first child, if existent, or
|
;; Checklists are inserted directly before first child, if existent, or
|
||||||
;; at end of subtree
|
;; at end of subtree
|
||||||
(org-show-entry)
|
(org-fold-show-entry)
|
||||||
(or (org-goto-first-child)
|
(or (org-goto-first-child)
|
||||||
(org-end-of-subtree 'invisible-ok 'to-heading))
|
(org-end-of-subtree 'invisible-ok 'to-heading))
|
||||||
;; Move back from heading, unless we are at the end of the buffer
|
;; Move back from heading, unless we are at the end of the buffer
|
||||||
@ -1275,28 +1275,26 @@ inserting the checklist."
|
|||||||
;; Go to end of line before heading
|
;; Go to end of line before heading
|
||||||
(forward-char -1))
|
(forward-char -1))
|
||||||
|
|
||||||
|
;; Insert blank line, but only if the previous line is not blank already.
|
||||||
|
(unless (save-mark-and-excursion
|
||||||
|
(forward-line -1)
|
||||||
|
(looking-at (rx bol (* space) eol)))
|
||||||
|
(insert "\n"))
|
||||||
|
|
||||||
;; Insert relevant backlinks, when available.
|
;; Insert relevant backlinks, when available.
|
||||||
(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
|
number-of-backlinks
|
||||||
point-before-backlinks)
|
point-before-backlinks)
|
||||||
|
|
||||||
;; Insert blank line, but only if the previous line is not blank
|
;; Store where we are so we can delete the checklist in case it's empty.
|
||||||
;; already.
|
(setq point-before-backlinks (point))
|
||||||
(unless (save-mark-and-excursion
|
|
||||||
(forward-line -1)
|
|
||||||
(looking-at (rx bol (* space) eol)))
|
|
||||||
(insert "\n"))
|
|
||||||
|
|
||||||
(insert (format "Relevant backlinks (%s):\n\n"
|
(insert (format "Relevant backlinks (%s):\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
|
(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
|
||||||
@ -1309,15 +1307,14 @@ inserting the checklist."
|
|||||||
(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
|
;; When no backlinks have been found, remove everything inserted so far.
|
||||||
;; print "none".
|
(if (zerop number-of-backlinks)
|
||||||
(when (zerop number-of-backlinks)
|
|
||||||
(delete-region point-before-backlinks (point))
|
(delete-region point-before-backlinks (point))
|
||||||
(insert " none.")))
|
(insert "\n\n")))
|
||||||
|
|
||||||
;; Insert template, when avilable.
|
;; Insert template, when avilable.
|
||||||
(let ((template-marker (db/org--find-template)))
|
(let ((template-marker (db/org--find-template)))
|
||||||
(insert "\n\nTemplate:")
|
(insert "Template:")
|
||||||
(setq point-before-template (point))
|
(setq point-before-template (point))
|
||||||
(if (not template-marker)
|
(if (not template-marker)
|
||||||
(insert " none.\n")
|
(insert " none.\n")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user