diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 32949e9..0adc50b 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -595,16 +595,30 @@ 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-to-id (&optional id) +;; TODO: expand: let the user choose the item that is to be linked to +;; interactively +(defun db/org-find-items-linking-by-id (&optional 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'. If ID is not -given, use the ID of the current item, if in Org Mode." - (interactive (list (when (derived-mode-p 'org-mode) - (org-id-get)))) - (if id - (org-search-view nil (format "[id:%s]" id)) - (user-error "No ID given and not in Org Mode."))) +a UUID as generated by, e.g., `org-id-get-create', and CUSTOM-ID +must consist of ASCII letters, numbers, and hyphens only. If ID +and CUSTOM-ID are not given, use the values of the current item +if in Org Mode." + (interactive (when (derived-mode-p 'org-mode) + (list (org-id-get) (org-entry-get nil "CUSTOM_ID")))) + + (unless (string-match-p "^[a-f0-9]\\{8\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{4\\}-[a-f0-9]\\{12\\}$" id) + (user-error "Given ID is not a valid UUID: %s" id)) + (unless (string-match-p "[-a-zA-Z0-9]" custom-id) + ;; sorry, only ASCII right now … + (user-error "CUSTOM_ID must consist of alphanumeric charaters only")) + + (let ((query (cond + ((and id custom-id) (format "{\\[\\[id:%s\\]\\|\\[\\[#%s\\]}" id custom-id)) + (id (format "[[id:%s]" id)) + (custom-id (format "[[#%s]" custom-id)) + (t (user-error "No ID given and not in Org Mode."))))) + (org-search-view nil query))) ;;; End