emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Bauer <jackb3793@gmail.com>
To: Emacs-orgmode@gnu.org
Subject: org-refile using the ID of the target
Date: Tue, 6 Apr 2021 16:55:13 -0300	[thread overview]
Message-ID: <CAE_mkuF5ppFiDpCXf6+DKcFw17LzEsVbshvD_-G6Kan-uJ3hRQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]

I take a lot of notes using MobileOrg in my phone, and after syncing, they
go into in.org (my gtd "in basket"). From there, I do the capturing process.

Thing is, sometimes there's a *lot* of notes that I just want to refile to
the "Notes" subtree from the corresponding project/context. A quick way to
do that would be nice.

My idea was to use the org-speed-commands-user to have a single key to
press for each category of note. I'd add entries like

("Q" (my/org-refile-to-id <ID of Notes-subtree from project Q> "TODO")

("W" (my/org-refile-to-id <ID of Notes-subtree from project W> "DONE")

("E" (my/org-refile-to-id <ID of Notes-subtree from project E> "")

At first, I tried using org-refile, but couldn't find a way to tell it to
refile to a specific subtree (eg, using its id).

Then I started hackstumbling around. So far, what I could come up with was:

(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."))))

It feels kinda messy, though.

Any advice would be more than welcome!

[-- Attachment #2: Type: text/html, Size: 10043 bytes --]

             reply	other threads:[~2021-04-06 19:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 19:55 Jack Bauer [this message]
2021-04-07 13:51 ` Christian Moe
2021-04-07 14:42   ` Eglur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAE_mkuF5ppFiDpCXf6+DKcFw17LzEsVbshvD_-G6Kan-uJ3hRQ@mail.gmail.com \
    --to=jackb3793@gmail.com \
    --cc=Emacs-orgmode@gnu.org \
    --subject='Re: org-refile using the ID of the target' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).