From: Christopher Allan Webber <cwebber@dustycloud.org>
To: emacs-orgmode@gnu.org
Subject: Conditionally archiving to subtree or archive file (depending on parent ARCHIVE property)
Date: Mon, 25 Jun 2012 13:43:25 -0500 [thread overview]
Message-ID: <87k3yvnsfm.fsf@grumps.lan> (raw)
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
reply other threads:[~2012-06-25 18:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k3yvnsfm.fsf@grumps.lan \
--to=cwebber@dustycloud.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).