Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafaelbeirigo/0bc86c167b9383fd074720c180b79671 to your computer and use it in GitHub Desktop.
Save rafaelbeirigo/0bc86c167b9383fd074720c180b79671 to your computer and use it in GitHub Desktop.
(defun my/org-refile-to-id (id &optional todo)
"Refile current subtree to subtree with ID."
(interactive (list (read-string "ID: ")))
(when todo (org-todo todo))
(org-cut-subtree)
(let ((anchor (ignore-errors (org-id-get-create))))
(org-id-goto id)
(org-insert-heading-respect-content)
(org-demote-subtree)
(org-yank)
(exchange-point-and-mark)
(zap-to-char 1 (string-to-char " "))
(move-beginning-of-line nil)
(if anchor
(org-id-goto anchor)
(message "This was the last one."))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment