org-gtd.el icon indicating copy to clipboard operation
org-gtd.el copied to clipboard

Explore the org-roam-captures and templates re: "archive this"

Open Trevoke opened this issue 2 years ago • 2 comments

How much work can and should be done automatically for the user when it comes to archiving an inbox item as knowledge?

Trevoke avatar Feb 15 '23 15:02 Trevoke

I recently found some time and updated to org-gtd v3.0.0. I used to have a workflow where something could be refiled to org-roam (with or without an ID) by using a custom function and changing what comes after transient-define-prefix org-gtd-organize ()

I'm trying to re-create such a worklfow with org-roam in org-gtd v3.0.0 but there are some hurdles. Here is what I have so far:

(defun my/org-gtd-roam-knowledge-func ()
  (setq-local org-gtd--organize-type 'knowledge)
  (org-gtd-organize-apply-hooks)
  (org-roam-refile))

(setq org-gtd-knowledge-func #'my/org-gtd-roam-knowledge-func)

The first problem is that it doesn't work and errors out with find-buffer-visiting: Wrong type argument: arrayp, nil. The second problem is that even if it did work, the way that org-gtd gives the heading an ID automatically is undesirable as:

  1. Not everything I refile to org-roam might not need to be ID'd
  2. ID's generated using org-id-get-create are guaranteed to be unique (this is not the case with the ID's generated by org-gtd)

How much work can and should be done automatically for the user when it comes to archiving an inbox item as knowledge?

@Trevoke As such it seems that it would require work around reformatting the ID creation of org-gtd as well :/

Edit: apologies, I think the ID generation of org-gtd won't result in dupicates, but I still think point 1 is valid

Sabicool avatar Jul 16 '23 10:07 Sabicool

I managed to get something that somewhat works.

I initially tried to do it in a similar way that org-gtd-archive-item-at-point works but it errors out with save-current-buffer: Wrong type argument: stringp, nil. Here is what I tried:

(defun my/org-gtd-roam-knowledge-func ()
  (setq-local org-gtd--organize-type 'knowledge)
  (org-gtd-organize-apply-hooks)
  (org-delete-property "ID")
  (when (yes-or-no-p "Does this need to be ID'd? ")
    (org-set-property "ID" (org-id-new)))
  (with-temp-message ""
    (let* ((last-command nil)
           (temp-file (make-temp-file org-gtd-directory nil ".org"))
           (buffer (find-file-noselect temp-file)))
      (org-copy-subtree)
      (org-gtd-core-prepare-buffer buffer)
      (with-current-buffer buffer
        (org-paste-subtree)
        (goto-char (point-min))
        ;; Tried to do below but did not work
        ;; Works with`(with-org-gtd-context (org-archive-subtree))
        (with-org-gtd-context (org-roam-refile))
        (basic-save-buffer)
        (kill-buffer))
      (delete-file temp-file))))

(setq org-gtd-knowledge-func #'my/org-gtd-roam-knowledge-func)

I did however manage to get this to work reasonably well provided you don't exit out at the point at which org-roam-refile is called:

(defun my/org-gtd-roam-knowledge-func ()
  (setq-local org-gtd--organize-type 'knowledge)
  (org-gtd-organize-apply-hooks)
  (org-delete-property "ID")
  (when (yes-or-no-p "Does this need to be ID'd? ")
    (org-set-property "ID" (org-id-new)))
  (org-copy-subtree)
  (org-paste-subtree)
  (goto-char (point-min))
  ;; Do not cancel out here (otherwise double up headings)
  (org-roam-refile))

(setq org-gtd-knowledge-func #'my/org-gtd-roam-knowledge-func)

Sabicool avatar Jul 17 '23 11:07 Sabicool