Allow to jump to template checklist instead of inserting it
This is a convenience shortcut. Maybe the code to insert the complete checklist also needs to go into another function, for implementatio clarity. Do this as soon as it seems appropriate or necessary.
This commit is contained in:
parent
4e10c06799
commit
ddbcfee3d9
|
@ -875,7 +875,7 @@ determined."
|
||||||
;; Return `template-marker', which is either `nil' or a marker.
|
;; Return `template-marker', which is either `nil' or a marker.
|
||||||
template-marker))
|
template-marker))
|
||||||
|
|
||||||
(defun db/org-insert-checklist ()
|
(defun db/org-insert-checklist (arg)
|
||||||
"Insert checklist for Org Mode item at point.
|
"Insert checklist for Org Mode item at point.
|
||||||
|
|
||||||
The checklist consists of a listing of relevant backlinks of the
|
The checklist consists of a listing of relevant backlinks of the
|
||||||
|
@ -917,51 +917,61 @@ determined by the TEMPLATE_ID property, which must be an ID
|
||||||
referencing the proper template item. If that property is not
|
referencing the proper template item. If that property is not
|
||||||
set, search for the topmost sibling of the current item is
|
set, search for the topmost sibling of the current item is
|
||||||
conducted to see whether its headline is matching
|
conducted to see whether its headline is matching
|
||||||
\"^Template.*\"; if so, its body is used as template."
|
\"^Template.*\"; if so, its body is used as template.
|
||||||
(interactive)
|
|
||||||
|
When ARG is given, jump to the current template instead of
|
||||||
|
inserting the checklist."
|
||||||
|
(interactive "P")
|
||||||
|
|
||||||
(unless (derived-mode-p 'org-mode)
|
(unless (derived-mode-p 'org-mode)
|
||||||
(user-error "Not in Org mode, aborting"))
|
(user-error "Not in Org mode, aborting"))
|
||||||
|
|
||||||
;; Insert relevant backlinks, when available.
|
(cond (arg
|
||||||
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
;; Universal argument given, just jump to the checklist of the item at
|
||||||
(string-to-number it)))
|
;; point.
|
||||||
number-of-backlinks
|
(db/org-goto-checklist-item-of-point))
|
||||||
point-before-backlinks)
|
|
||||||
|
|
||||||
(insert (format "\nRelevant backlinks (%s):\n\n"
|
(t
|
||||||
(if parent-depth
|
;; Default action: insert complete checklist. Start with inserting
|
||||||
(format "parent-depth %d" parent-depth)
|
;; relevant backlinks, when available.
|
||||||
"all parents")))
|
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
||||||
|
(string-to-number it)))
|
||||||
|
number-of-backlinks
|
||||||
|
point-before-backlinks)
|
||||||
|
|
||||||
;; Store where we are (minus the two newlines) so we can delete the
|
(insert (format "\nRelevant backlinks (%s):\n\n"
|
||||||
;; checklist in case it's empty.
|
(if parent-depth
|
||||||
(setq point-before-backlinks (- (point) 2))
|
(format "parent-depth %d" parent-depth)
|
||||||
|
"all parents")))
|
||||||
|
|
||||||
(setq number-of-backlinks
|
;; Store where we are (minus the two newlines) so we can delete the
|
||||||
(org-dblock-write:db/org-backlinks (list
|
;; checklist in case it's empty.
|
||||||
:org-ql-match '(and
|
(setq point-before-backlinks (- (point) 2))
|
||||||
(not (done))
|
|
||||||
(not (ltags "TEMPLATE"))
|
|
||||||
(not (scheduled :from 1))
|
|
||||||
(not (property "CHECKLIST_NO_BACKLINK" "t" :inherit nil)))
|
|
||||||
:parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
|
||||||
(string-to-number it))
|
|
||||||
:archive nil)))
|
|
||||||
|
|
||||||
;; When no backlinks have been found, remove the empty table head and just
|
(setq number-of-backlinks
|
||||||
;; print "none".
|
(org-dblock-write:db/org-backlinks (list
|
||||||
(when (zerop number-of-backlinks)
|
:org-ql-match '(and
|
||||||
(delete-region point-before-backlinks (point))
|
(not (done))
|
||||||
(insert " none.")))
|
(not (ltags "TEMPLATE"))
|
||||||
|
(not (scheduled :from 1))
|
||||||
|
(not (property "CHECKLIST_NO_BACKLINK" "t" :inherit nil)))
|
||||||
|
:parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
|
||||||
|
(string-to-number it))
|
||||||
|
:archive nil)))
|
||||||
|
|
||||||
;; Insert template, when avilable.
|
;; When no backlinks have been found, remove the empty table head and just
|
||||||
(let ((template-marker (db/org--find-template)))
|
;; print "none".
|
||||||
(insert "\n\nTemplate:")
|
(when (zerop number-of-backlinks)
|
||||||
(if (not template-marker)
|
(delete-region point-before-backlinks (point))
|
||||||
(insert " none.")
|
(insert " none.")))
|
||||||
(insert "\n")
|
|
||||||
(db/org-copy-body-from-item-to-point template-marker))))
|
;; Insert template, when avilable.
|
||||||
|
(let ((template-marker (db/org--find-template)))
|
||||||
|
(insert "\n\nTemplate:")
|
||||||
|
(if (not template-marker)
|
||||||
|
(insert " none.")
|
||||||
|
(insert "\n")
|
||||||
|
(db/org-copy-body-from-item-to-point template-marker))))))
|
||||||
|
|
||||||
(define-obsolete-function-alias 'db/org-copy-template
|
(define-obsolete-function-alias 'db/org-copy-template
|
||||||
'db/org-insert-checklist
|
'db/org-insert-checklist
|
||||||
|
|
Loading…
Reference in New Issue