Refile to date-tree

Useful to refile notes to the journal file, which is a date-tree. org-refile isn't convenient to refile stuff to a date-tree.

(defun my/org-refile-to-journal ()
  "Refile an entry to journal file's date-tree"
  (require 'org-datetree)
  (let ((journal (expand-file-name "" org-directory))
    (setq post-date (or (org-entry-get (point) "TIMESTAMP_IA")
			(org-entry-get (point) "TIMESTAMP")))
    (setq post-date (nthcdr 3 (parse-time-string post-date)))
    (setq post-date (list (cadr post-date)
			  (car post-date)
			  (caddr post-date)))
    (with-current-buffer (or (find-buffer-visiting journal)
			     (find-file-noselect journal))
	(org-datetree-file-entry-under (current-kill 0) post-date)
	(bookmark-set "org-refile-last-stored")))
    (message "Refiled to %s" journal))
  (setq this-command 'my/org-refile-to-journal))

(defun my/org-agenda-refile-to-journal ()
  "Refile the item at point to journal."
  (let* ((marker (or (org-get-at-bol 'org-hd-marker)
	 (buffer (marker-buffer marker))
	 (pos (marker-position marker)))
    (with-current-buffer buffer
	  (goto-char marker)

(org-defkey org-agenda-mode-map (kbd "C-c C-S-w") 'my/org-agenda-refile-to-journal)
(org-defkey org-mode-map (kbd "C-c C-S-w") 'my/org-refile-to-journal)


Update [2016-06-16] Raam Dev pointed me to an issue and a suggested fix, that I have updated the above code with.

Show comments