Extend backward link searching function
Now support CUSTOM_ID as well, and check arguments for plausibility.
This commit is contained in:
parent
a6f77f8d71
commit
cde56c819e
|
@ -595,16 +595,30 @@ This is done only if the value of this variable is not null."
|
||||||
|
|
||||||
;;; Find items by link to current headline
|
;;; 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.
|
"List all Org Mode items that link to ID.
|
||||||
Uses `org-search-view' to conduct the actual search. ID must be
|
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
|
a UUID as generated by, e.g., `org-id-get-create', and CUSTOM-ID
|
||||||
given, use the ID of the current item, if in Org Mode."
|
must consist of ASCII letters, numbers, and hyphens only. If ID
|
||||||
(interactive (list (when (derived-mode-p 'org-mode)
|
and CUSTOM-ID are not given, use the values of the current item
|
||||||
(org-id-get))))
|
if in Org Mode."
|
||||||
(if id
|
(interactive (when (derived-mode-p 'org-mode)
|
||||||
(org-search-view nil (format "[id:%s]" id))
|
(list (org-id-get) (org-entry-get nil "CUSTOM_ID"))))
|
||||||
(user-error "No ID given and not in Org Mode.")))
|
|
||||||
|
(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
|
;;; End
|
||||||
|
|
Loading…
Reference in New Issue
Block a user