emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Refile to datetree
@ 2018-10-14 17:45 Daniele Nicolodi
  0 siblings, 0 replies; only message in thread
From: Daniele Nicolodi @ 2018-10-14 17:45 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-14 17:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14 17:45 Refile to datetree Daniele Nicolodi

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