diff --git a/init.el b/init.el index 642ab9f..cd86938 100644 --- a/init.el +++ b/init.el @@ -716,7 +716,7 @@ db/org-mark-current-default-task db/export-diary db/org-copy-template-for-periodic-task - db/org-find-items-linking-to-id)) + db/org-find-links-to-current-item)) (use-package org :pin "gnu" diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 11f87c6..73df062 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -595,22 +595,13 @@ This is done only if the value of this variable is not null." ;;; Find items by link to current headline -(defun db/org-find-items-linking-by-id (&optional id custom-id) +(defun db/org-find-items-linking-by-id (id custom-id) "List all Org Mode items that link to ID. Uses `org-search-view' to conduct the actual search. ID must be a UUID as generated by, e.g., `org-id-get-create', and CUSTOM-ID -must consist of ASCII letters, numbers, and hyphens only. When -called interactively in Org Mode, use the values ID and CUSTOM_ID -of the current item. When called interactively outside of Org -Mode, prompt the user for the user for a headline." - (interactive (if (derived-mode-p 'org-mode) - (list (org-id-get) (org-entry-get nil "CUSTOM_ID")) - (let ((pom (nth 3 (org-refile-get-location)))) - (if (not pom) - (user-error "Invalid location") - (org-with-point-at pom - (list (org-id-get) (org-entry-get nil "CUSTOM_ID"))))))) - +must consist of ASCII letters, numbers, and hyphens only. Each +of ID and CUSTOM-ID may be nil, but at least one of them must be +not." (unless (or (not id) (and (stringp id) (string-match-p "^[a-f0-9]\\{8\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{12\\}$" id))) @@ -628,6 +619,22 @@ Mode, prompt the user for the user for a headline." (t (user-error "No ID given and not in Org Mode."))))) (org-search-view nil query))) +(defun db/org-find-links-to-current-item (arg) + "Find links to current item. +Only links using the ID or CUSTOM_ID property are considered. + +If ARG is given, or if not in an Org Mode buffer, interactively +prompt for an item." + (interactive "P") + (apply #'db/org-find-items-linking-by-id + (if (and (derived-mode-p 'org-mode) (not arg)) + (list (org-id-get) (org-entry-get nil "CUSTOM_ID")) + (let ((pom (nth 3 (org-refile-get-location)))) + (if (not pom) + (user-error "Invalid location") + (org-with-point-at pom + (list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))))) + ;;; End