emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Daniele Nicolodi <daniele@grinta.net>
To: emacs-orgmode@gnu.org
Subject: Refile to datetree
Date: Sun, 14 Oct 2018 11:45:28 -0600	[thread overview]
Message-ID: <8b37c599-7119-a9a8-8cab-88d32ad93750@grinta.net> (raw)

Hello,

I'm not always very systematic in my note taking and sometimes I find 
the need to refile entries into a datetree. Unfortunately `org-refile` 
does not provide facilities for doing that easily. `org-archive` kind of 
does, but it does not allow to easily specify the target date.

I saw a few questions on Stack Overflow asking for this functionality, 
but all answers only provided partial solutions. I came up with the 
following:

;; org-refile to datetree
(defun dnn-refile-to-datetree (arg)
  (interactive "P")
  (require 'org-datetree)
  (let* ((loc (org-refile-get-location "Datetree root" (current-buffer)))
         (buffer (find-file-noselect (nth 1 loc)))
         (pos (nth 3 loc))
         (date
          (calendar-gregorian-from-absolute
           (if arg (time-to-days (org-read-date nil t)) (org-today))))
         (dest
          (with-current-buffer buffer
            (save-excursion
              (goto-char pos)
              (org-datetree-find-date-create date 'subtree-at-point)
              (list (org-get-heading) (buffer-file-name) nil (point))))))
    (org-refile nil nil dest)))

which works for me so far.  If people think it may be generally useful,
and we can agree on how to expose the functionality to the user, I would
like to integrate it in org-refile proper.

Thanks. Cheers,
Dan

                 reply	other threads:[~2018-10-14 17:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=8b37c599-7119-a9a8-8cab-88d32ad93750@grinta.net \
    --to=daniele@grinta.net \
    --cc=emacs-orgmode@gnu.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).