From f7ddab7696f6587efc9134f933f8117a0250c300 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 26 Sep 2020 16:29:50 +0200 Subject: [PATCH 1/4] Fix error message --- site-lisp/db-org.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 7a57158..75a1214 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) From 1c065bb46ba47cc24c8962ed6e71f680f75e66c4 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 26 Sep 2020 16:44:11 +0200 Subject: [PATCH 2/4] Add simple function to insert links to other items at point --- init.el | 3 ++- site-lisp/db-org.el | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index d026bc0..6a578f4 100644 --- a/init.el +++ b/init.el @@ -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 75a1214..499036c 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -635,6 +635,21 @@ 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) + (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 From 9994a3ac82b525255b9a6f0212dae56b4245197f Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 26 Sep 2020 16:46:34 +0200 Subject: [PATCH 3/4] Update key bindings for handling Org Mode links F9 is a comparably prominent key binding, and we now bind it to the more important `db/org-add-link-to-other-item'. The formar binding to `db/org-find-links-to-current-item' is bound to F11 now, since it will still be used often, but not more often then inserting links (I think). The old binding for F11 to `org-capture' has not been used much, and so we can dispense of it. --- init.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.el b/init.el index 6a578f4..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) From ff184ec47aed2fd80d7ecb62335b7e20d00ea5e7 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 26 Sep 2020 16:48:02 +0200 Subject: [PATCH 4/4] Check whether we are in Org Mode before inserting remote link --- site-lisp/db-org.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 499036c..354c914 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -640,6 +640,8 @@ prompt for an item." 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")