emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-refile using the ID of the target
@ 2021-04-06 19:55 Jack Bauer
  2021-04-07 13:51 ` Christian Moe
  0 siblings, 1 reply; 3+ messages in thread
From: Jack Bauer @ 2021-04-06 19:55 UTC (permalink / raw)
  To: Emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org-refile using the ID of the target
  2021-04-06 19:55 org-refile using the ID of the target Jack Bauer
@ 2021-04-07 13:51 ` Christian Moe
  2021-04-07 14:42   ` Eglur
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Moe @ 2021-04-07 13:51 UTC (permalink / raw)
  To: Jack Bauer; +Cc: Emacs-orgmode



My approach is to tag the equivalent of your "Notes" subtree of the
various projects in my agenda files with an :INBOX: tag.

The following code in .emacs then makes sure they are presented as
refile targets:

;; Refile
(setq org-refile-targets
      '((org-agenda-files . (:tag . "INBOX")) ;; Inbox subtree in each file
	(nil . (:level . 1))))                ;; and all top headings current buffer
(setq org-refile-use-outline-path t)

It may not be quite as fast as what you have in mind, but it is perhaps
more flexible, and saves having to define or remember those keys.

If you already consistently use "Notes" as the heading for this purpose,
you might not even need to tag them; you could try simply replacing
(:tag . "INBOX") above with (:regexp . "Notes").
(This might cast too wide a net, though.) See the documentation for
org-refile targets.

Yours,
Christian

Jack Bauer writes:

> 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!


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org-refile using the ID of the target
  2021-04-07 13:51 ` Christian Moe
@ 2021-04-07 14:42   ` Eglur
  0 siblings, 0 replies; 3+ messages in thread
From: Eglur @ 2021-04-07 14:42 UTC (permalink / raw)
  To: Christian Moe; +Cc: Emacs-orgmode

Hello, Christian.
Thanks for the tip!
It is indeed a very good solution.

For now, I’m improvising the one-key approach with this

~/.emacs.d/init.el:

(setq org-speed-commands-user
      '(("j" my/org-quick-refile)))

(defun my/org-quick-refile ()
  "Refile subtree using list of predefined targets."
  (interactive)

  (let ((choice (car (read-multiple-choice
                      "Refile where?"
                      '((?j "Journal")
                        (?a "Project 1 Notes")
                        (?s "Project 2 Notes"))))))
    (let ((id
           (cond
            ((= ?a choice) "eb952006-71f4-4fc3-93d0-9f0cb61aed5b")
            ((= ?s choice) "3e444863-a617-414d-97bf-31fdd888b4dc")
            ((= ?j choice) "journal"))))
      (if id
          (if (string= id "journal")
              (my/org-journal-pre-resolve-with-header)
            (my/org-refile-to-id id ""))))))

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

P.S.: Please ignore the ‘my/org-journal-pre-resolve-with-header’---it’s
a /very/ ugly newbie hack that I commited what I would like to believe
ages ago.

Christian Moe <mail@christianmoe.com> writes:

> My approach is to tag the equivalent of your "Notes" subtree of the
> various projects in my agenda files with an :INBOX: tag.
>
> The following code in .emacs then makes sure they are presented as
> refile targets:
>
> ;; Refile
> (setq org-refile-targets
>       '((org-agenda-files . (:tag . "INBOX")) ;; Inbox subtree in each file
> 	(nil . (:level . 1))))                ;; and all top headings current buffer
> (setq org-refile-use-outline-path t)
>
> It may not be quite as fast as what you have in mind, but it is perhaps
> more flexible, and saves having to define or remember those keys.
>
> If you already consistently use "Notes" as the heading for this purpose,
> you might not even need to tag them; you could try simply replacing
> (:tag . "INBOX") above with (:regexp . "Notes").
> (This might cast too wide a net, though.) See the documentation for
> org-refile targets.
>
> Yours,
> Christian
>
> Jack Bauer writes:
>
>> 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!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-07 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-06 19:55 org-refile using the ID of the target Jack Bauer
2021-04-07 13:51 ` Christian Moe
2021-04-07 14:42   ` Eglur

Code repositories for project(s) associated with this public 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).