From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniele Nicolodi Subject: Refile to datetree Date: Sun, 14 Oct 2018 11:45:28 -0600 Message-ID: <8b37c599-7119-a9a8-8cab-88d32ad93750@grinta.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBkSU-0007EH-0m for emacs-orgmode@gnu.org; Sun, 14 Oct 2018 13:45:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gBkSP-0005n2-0g for emacs-orgmode@gnu.org; Sun, 14 Oct 2018 13:45:41 -0400 Received: from zed.grinta.net ([109.74.203.128]:60670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gBkSO-0005lh-Md for emacs-orgmode@gnu.org; Sun, 14 Oct 2018 13:45:36 -0400 Received: from black.local (c-98-245-163-4.hsd1.co.comcast.net [98.245.163.4]) (Authenticated sender: daniele) by zed.grinta.net (Postfix) with ESMTPSA id BE02AE0569 for ; Sun, 14 Oct 2018 17:45:31 +0000 (UTC) Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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