Add function to add link to currently clocked-in task

This might be handy while working on a task and realizing that it's related to
another one.
This commit is contained in:
Daniel - 2021-03-20 12:32:48 +01:00
parent 0946628681
commit eae1590e68
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
2 changed files with 18 additions and 1 deletions

View File

@ -732,7 +732,8 @@
db/export-diary
db/org-copy-template-for-periodic-task
db/org-find-links-to-current-item
db/org-add-link-to-other-item))
db/org-add-link-to-other-item
db/org-add-link-to-current-clock))
(use-package org
:pin "gnu"

View File

@ -717,6 +717,22 @@ Use `org-store-link' to save link to `org-stored-links'."
(org-store-link nil t))
(insert (apply #'format "[[%s][%s]]" (cl-first org-stored-links))))))
(defun db/org-add-link-to-current-clock ()
"Insert link to currently clocked-in item at point.
Uses `org-store-link' and `org-insert-link'. Error out when not
in an Org Mode buffer or when the clock is not active."
(interactive)
(unless (derived-mode-p 'org-mode)
(user-error "Not in Org Mode, aborting"))
(unless org-clock-marker
(user-error "No clocked-in task, aborting"))
(save-mark-and-excursion
(org-with-point-at org-clock-marker
(org-store-link nil t))
(pcase-let ((`(,location ,description) (cl-first org-stored-links)))
(org-insert-link nil location description))))
;;; End