From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Allan Webber Subject: Conditionally archiving to subtree or archive file (depending on parent ARCHIVE property) Date: Mon, 25 Jun 2012 13:43:25 -0500 Message-ID: <87k3yvnsfm.fsf@grumps.lan> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjEDT-00025a-9z for emacs-orgmode@gnu.org; Mon, 25 Jun 2012 14:40:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SjEDR-0003e3-HV for emacs-orgmode@gnu.org; Mon, 25 Jun 2012 14:40:50 -0400 Received: from li424-160.members.linode.com ([50.116.34.160]:54360 helo=dustycloud.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SjEDR-0003dx-Dx for emacs-orgmode@gnu.org; Mon, 25 Jun 2012 14:40:49 -0400 Received: from grumps.lan (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTP id 5885826D00 for ; Mon, 25 Jun 2012 14:40:47 -0400 (EDT) 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 Hi all, I've written a snippet of elisp which I'm finding very helpful. I've replaced the archive keybinding with it. Basically, I found that when I had something like this: #+BEGIN_SRC org * Task tree :PROPERTIES: :ARCHIVE: %s_archive::* Task tree :END: ** TODO Some task *** TODO Some subtask *** DONE Another subtask ** DONE This is done #+END_SRC ... on something like "This is done", I'd want that whole tree moved to the archive file. On something like "some task", if I eventually finished the whole tree, I wanted it moved to the archive file, but if I had subtasks within that subtree, I might want to move them out of the way, but not have them disappear from the bigger subtask... that would be confusing! So I wanted them to move to the archive subtree so I could clean up that bigger TODO structure, like so: #+BEGIN_SRC org * Task tree :PROPERTIES: :ARCHIVE: %s_archive::* Task tree :END: ** TODO Some task *** TODO Some subtask *** Archive :ARCHIVE: **** DONE Another subtask #+END_SRC But I wanted this logic to happen automatically. So I wrote some trivial elisp to do this. Maybe someone else will find it helpful? #+BEGIN_SRC emacs-lisp ;; This software is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. (defun org-archive-subtree-depending-on-property () "Conditionally archive the subtree to a file or archive sibling If the parent subtree has an ARCHIVE property, archive to a file. Otherwise, archive to an archive sibling. " (interactive) (let* ((current-level (org-current-level)) (parent-archive-property (if current-level (save-excursion (org-up-heading-safe) (org-entry-get (point) "ARCHIVE"))))) (cond ; If there is no current level, do nothing ((not current-level) nil) ; If we're at the first level, subtree archive it ((or (eq current-level 1) (not parent-archive-property)) (let ((org-archive-default-command 'org-archive-to-archive-sibling)) (org-archive-subtree-default-with-confirmation))) ; Otherwise, archive to a file (t (let ((org-archive-default-command 'org-archive-subtree)) (org-archive-subtree-default-with-confirmation)))))) #+END_SRC