diff --git a/init.el b/init.el index d026bc0..bc6d16c 100644 --- a/init.el +++ b/init.el @@ -175,7 +175,7 @@ (bind-key "" #'winner-undo) (bind-key "" #'winner-redo) (bind-key "" #'magit-status) - (bind-key "" #'org-capture) + (bind-key "" #'db/org-find-links-to-current-item) (bind-key "" #'db/helm-shortcuts) (bind-key "" #'db/run-or-hide-eshell) (bind-key "" #'hydra-feature-shortcuts/body) @@ -183,9 +183,9 @@ (bind-key "" #'hydra-zoom/body) (bind-key "" #'dictcc) (bind-key "" #'bm-toggle) + (bind-key "" #'db/org-add-link-to-other-item) (bind-key "" #'bm-next) (bind-key "" #'bm-previous) - (bind-key "" #'db/org-find-links-to-current-item) (bind-key "C-," #'mc/skip-to-previous-like-this) (bind-key "C-." #'mc/skip-to-next-like-this) (bind-key "C-;" #'iedit-mode) @@ -716,7 +716,8 @@ db/org-mark-current-default-task db/export-diary db/org-copy-template-for-periodic-task - db/org-find-links-to-current-item)) + db/org-find-links-to-current-item + db/org-add-link-to-other-item)) (use-package org :pin "gnu" diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 7a57158..354c914 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -616,7 +616,7 @@ not." ((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."))))) + (t (user-error "Neither ID nor CUSTOM_ID given"))))) (org-search-view nil query))) (defun db/org-find-links-to-current-item (arg) @@ -635,6 +635,23 @@ prompt for an item." (org-with-point-at pom (list (org-id-get) (org-entry-get nil "CUSTOM_ID")))))))) +(defun db/org-add-link-to-other-item () + "Interactively query for item and add link to it at point. +Uses `org-id-get-create' to get the ID or CUSTOM_ID propery of +the target headline." + (interactive) + (unless (derived-mode-p 'org-mode) + (user-error "Not in Org Mode")) + (let ((pom (nth 3 (org-refile-get-location nil (get-file-buffer db/org-default-org-file))))) + (if (not pom) + (user-error "Invalid location") + (let (id item) + (save-mark-and-excursion + (org-with-point-at pom + (setq item (org-entry-get nil "ITEM") + id (org-id-get-create))) + (insert (format "[[id:%s][%s]]" id item))))))) + ;;; End