emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Refile to datetree


From: Daniele Nicolodi
Subject: [O] Refile to datetree
Date: Sun, 14 Oct 2018 11:45:28 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

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 via email to

[Prev in Thread] Current Thread [Next in Thread]