Compare commits
3 Commits
99dbd00e71
...
de314f6ac2
| Author | SHA1 | Date | |
|---|---|---|---|
| de314f6ac2 | |||
| 2c01e1e09c | |||
| c572451c14 |
@ -882,14 +882,20 @@ item using `db/org-get-location', which see."
|
|||||||
(db/org-get-location)))
|
(db/org-get-location)))
|
||||||
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))
|
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))
|
||||||
|
|
||||||
(defun db/org-insert-link-to-pom (pom)
|
(defun db/org--format-link-from-pom (pom)
|
||||||
"Insert an Org link to headline at POM.
|
"Return Org link pointing to Org item at POM.
|
||||||
|
|
||||||
|
POM must be point or mark to a valid Org item. The link will be
|
||||||
|
of the format [[id][item-headline]], where `id' is the value of
|
||||||
|
the ID property of the item. If the item does not have such a
|
||||||
|
property, is is generated automatically.
|
||||||
|
|
||||||
|
If `item-headline' contains any links itself, those will be
|
||||||
|
replaced by the description when available, and otherwise by
|
||||||
|
their plain link part."
|
||||||
|
(unless (or (markerp pom) (integerp pom))
|
||||||
|
(user-error "POM must be point or mark"))
|
||||||
|
|
||||||
If headline consists of a link with description, only the
|
|
||||||
description of that link will be included in the description of
|
|
||||||
the newly inserted link instead of the complete headline. This
|
|
||||||
avoids containing a link in the description of the newly inserted
|
|
||||||
link."
|
|
||||||
(let (item id)
|
(let (item id)
|
||||||
(org-with-point-at pom
|
(org-with-point-at pom
|
||||||
(setq item (org-entry-get (point) "ITEM")
|
(setq item (org-entry-get (point) "ITEM")
|
||||||
@ -905,7 +911,24 @@ link."
|
|||||||
desc
|
desc
|
||||||
(substring item (match-end 0)))))))
|
(substring item (match-end 0)))))))
|
||||||
|
|
||||||
(org-insert-link nil (format "id:%s" id) item)))
|
(org-link-make-string (format "id:%s" id) item)))
|
||||||
|
|
||||||
|
(defun db/org--format-link-from-org-id (id)
|
||||||
|
"Format ID as an Org mode link [[ID][item-headline]].
|
||||||
|
|
||||||
|
If the headline of the item pointed to by ID contains any links,
|
||||||
|
those are replaced by their description before formatting."
|
||||||
|
(db/org--format-link-from-pom (org-id-find id 'marker)))
|
||||||
|
|
||||||
|
(defun db/org-insert-link-to-pom (pom)
|
||||||
|
"Insert an Org link to headline at POM.
|
||||||
|
|
||||||
|
If headline consists of a link with description, only the
|
||||||
|
description of that link will be included in the description of
|
||||||
|
the newly inserted link instead of the complete headline. This
|
||||||
|
avoids containing a link in the description of the newly inserted
|
||||||
|
link."
|
||||||
|
(insert (db/org--format-link-from-pom pom)))
|
||||||
|
|
||||||
(defun db/org-add-link-to-other-item (arg)
|
(defun db/org-add-link-to-other-item (arg)
|
||||||
"Interactively query for item and add link to it at point.
|
"Interactively query for item and add link to it at point.
|
||||||
@ -1012,11 +1035,6 @@ level/position comes first)."
|
|||||||
(push (point-marker) parent-markers))
|
(push (point-marker) parent-markers))
|
||||||
parent-markers))))
|
parent-markers))))
|
||||||
|
|
||||||
(defun db/org--format-link-with-headline (id)
|
|
||||||
"Format ID as an Org mode link [[ID][item headline]]."
|
|
||||||
(org-link-make-string (format "id:%s" id)
|
|
||||||
(org-entry-get (org-id-find id 'marker) "ITEM")))
|
|
||||||
|
|
||||||
(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.
|
||||||
|
|
||||||
@ -1046,16 +1064,16 @@ PARAMS may contain the following values:
|
|||||||
;; Formatting.
|
;; Formatting.
|
||||||
(insert (format "| Item | Backlinks | Priority |\n|---|"))
|
(insert (format "| Item | Backlinks | Priority |\n|---|"))
|
||||||
(dolist (headline headlines)
|
(dolist (headline headlines)
|
||||||
(insert (format "\n| %s |\n|---|" (db/org--format-link-with-headline (car headline))))
|
(when (cdr headline) ; do not print backlinks if there are none
|
||||||
(let ((backlink-lines (-> (mapcar #'(lambda (backlink-id)
|
(insert (format "\n| %s |\n|---|" (db/org--format-link-from-org-id (car headline))))
|
||||||
(list (db/org--format-link-with-headline backlink-id)
|
(let ((backlink-lines (-> (mapcar #'(lambda (backlink-id)
|
||||||
(org-entry-get (org-id-find backlink-id 'marker)
|
(list (db/org--format-link-from-org-id backlink-id)
|
||||||
"PRIORITY")))
|
(org-entry-get (org-id-find backlink-id 'marker)
|
||||||
(cdr headline))
|
"PRIORITY")))
|
||||||
(cl-sort #'string< :key #'cl-second))))
|
(cdr headline))
|
||||||
(dolist (line backlink-lines)
|
(cl-sort #'string< :key #'cl-second))))
|
||||||
(insert (apply #'format "\n| | %s | %s |" line)))
|
(dolist (line backlink-lines)
|
||||||
(when backlink-lines ; only print closing hline when there's something to close
|
(insert (apply #'format "\n| | %s | %s |" line)))
|
||||||
(insert "\n|---|"))))
|
(insert "\n|---|"))))
|
||||||
(org-table-align)))
|
(org-table-align)))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user