Simplify code searching for backlinks

Reduce the conditional parts and extract common code.
This commit is contained in:
dbo 2022-04-16 10:10:49 +02:00
parent b670ee57f6
commit 341dec6a6a
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
1 changed files with 15 additions and 11 deletions

View File

@ -860,19 +860,23 @@ Only links using the ID or CUSTOM_ID property are considered.
If ARG is given, or if neither in an Org Mode buffer nor on a If ARG is given, or if neither in an Org Mode buffer nor on a
headline in an Org Agenda buffer, interactively prompt for an headline in an Org Agenda buffer, interactively prompt for an
item." item using `db/org-get-location', which see."
(interactive "P") (interactive "P")
(apply #'db/org-find-items-linking-by-id (apply #'db/org-find-items-linking-by-id
(cond ((and (not arg) (derived-mode-p 'org-mode)) ;; Determine the current item interactively based on where we are: when
(list (org-id-get) (org-entry-get nil "CUSTOM_ID"))) ;; in an Org buffer or in Org agenda view, indeed use the item at
((and (not arg) ;; point; otherwise, and when ARG is given, query the user for the item
(derived-mode-p 'org-agenda-mode) ;; to look for.
(org-get-at-bol 'org-hd-marker)) (org-with-point-at (cond ((and (not arg)
(org-with-point-at (org-get-at-bol 'org-hd-marker) (derived-mode-p 'org-mode))
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))) (point))
(t ((and (not arg)
(org-with-point-at (db/org-get-location) (derived-mode-p 'org-agenda-mode)
(list (org-id-get) (org-entry-get nil "CUSTOM_ID"))))))) (org-get-at-bol 'org-hd-marker))
(org-get-at-bol 'org-hd-marker))
(t
(db/org-get-location)))
(list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))
(defun db/org-insert-link-to-pom (pom) (defun db/org-insert-link-to-pom (pom)
"Insert an Org link to headline at POM. "Insert an Org link to headline at POM.