From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Hyatt Subject: [PATCH] Add the ability to archive to the datetree. Date: Wed, 9 Nov 2011 00:06:48 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:40809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RO0N9-0004fe-G3 for emacs-orgmode@gnu.org; Wed, 09 Nov 2011 00:06:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RO0N8-0003aW-I2 for emacs-orgmode@gnu.org; Wed, 09 Nov 2011 00:06:51 -0500 Received: from mail-vw0-f41.google.com ([209.85.212.41]:56980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RO0N8-0003aM-Ef for emacs-orgmode@gnu.org; Wed, 09 Nov 2011 00:06:50 -0500 Received: by vws16 with SMTP id 16so1341872vws.0 for ; Tue, 08 Nov 2011 21:06:49 -0800 (PST) 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * org.el (org-archive-location): Add documentation on new datetree option. * org-archive.el (org-archive-subtree): Add special handling of datetree options to archive to datetree. --- lisp/org-archive.el | 21 +++++++++++++++++---- lisp/org.el | 7 +++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lisp/org-archive.el b/lisp/org-archive.el index 16c35cf..4df6f1e 100644 --- a/lisp/org-archive.el +++ b/lisp/org-archive.el @@ -213,13 +213,14 @@ this heading." (current-time))) category todo priority ltags itags atags ;; end of variables that will be used for saving context - location afile heading buffer level newfile-p infile-p visiting) + location afile heading buffer level newfile-p infile-p visiting + datetree-date) ;; Find the local archive location (setq location (org-get-local-archive-location) afile (org-extract-archive-file location) heading (org-extract-archive-heading location) - infile-p (equal file (abbreviate-file-name afile))) + infile-p (equal file (abbreviate-file-name (or afile "")))) (unless afile (error "Invalid `org-archive-location'")) @@ -230,6 +231,12 @@ this heading." (setq buffer (current-buffer))) (unless buffer (error "Cannot access file \"%s\"" afile)) + (when (string-match "\\`datetree/" heading) + ;; Replace with ***, to represent the 3 levels of headings the + ;; datetree has. + (setq heading (string-replace-match "\\`datetree/" heading "***")) + (setq datetree-date (org-date-to-gregorian + (or (org-entry-get nil "CLOSED" t) time)))) (if (and (> (length heading) 0) (string-match "^\\*+" heading)) (setq level (match-end 0)) @@ -262,6 +269,9 @@ this heading." (goto-char (point-max)) (insert (format "\nArchived entries from file %s\n\n" (buffer-file-name this-buffer)))) + (when datetree-date + (org-datetree-find-date-create datetree-date) + (org-narrow-to-subtree)) ;; Force the TODO keywords of the original buffer (let ((org-todo-line-regexp tr-org-todo-line-regexp) (org-todo-keywords-1 tr-org-todo-keywords-1) @@ -285,7 +295,8 @@ this heading." ;; Heading not found, just insert it at the end (goto-char (point-max)) (or (bolp) (insert "\n")) - (insert "\n" heading "\n") + ;; datetrees don't need to much spacing + (if datetree-date (insert heading) (insert "\n" heading "\n")) (end-of-line 0)) ;; Make the subtree visible (show-subtree) @@ -296,7 +307,8 @@ this heading." (org-end-of-subtree t)) (skip-chars-backward " \t\r\n") (and (looking-at "[ \t\r\n]*") - (replace-match "\n\n"))) + ;; datetree archives don't need so much spacing. + (replace-match (if datetree-date "\n" "\n\n")))) ;; No specific heading, just go to end of file. (goto-char (point-max)) (insert "\n")) ;; Paste @@ -326,6 +338,7 @@ this heading." (setq n (concat "ARCHIVE_" (upcase (symbol-name e)))) (org-entry-put (point) n v))))) + (widen) ;; Save and kill the buffer, if it is not the same buffer. (when (not (eq this-buffer buffer)) (save-buffer)))) diff --git a/lisp/org.el b/lisp/org.el index 6ee3b4e..9c80c9c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4046,6 +4046,13 @@ Here are a few examples: Archive in file ./basement (relative path), as level 3 trees below the level 2 heading \"** Finished Tasks\". +\"~/org/datetree.org::datetree/* Finished Tasks\" + The \"datetree/\" string is special, signifiying to + archive items to the datetree. Items are placed in + either the CLOSED date of the item, or the current date + if there is no CLOSED date. The heading will be a + subentry to the current date. + You may set this option on a per-file basis by adding to the buffer a line like -- 1.7.3.1