From mboxrd@z Thu Jan 1 00:00:00 1970 From: James TD Smith Subject: [PATCH 6/9] Add some functions for handling checklists. Date: Sat, 20 Sep 2008 22:09:11 +0100 Message-ID: <20080920210911.19759.63738.stgit@nyarlathotep.internal.mohorovi.cc> References: <20080920210101.19759.15959.stgit@nyarlathotep.internal.mohorovi.cc> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kh9hb-0004DE-UY for emacs-orgmode@gnu.org; Sat, 20 Sep 2008 17:09:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kh9hb-0004Cj-1R for emacs-orgmode@gnu.org; Sat, 20 Sep 2008 17:09:15 -0400 Received: from [199.232.76.173] (port=60166 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kh9ha-0004CR-K7 for emacs-orgmode@gnu.org; Sat, 20 Sep 2008 17:09:14 -0400 Received: from 81-86-40-42.dsl.pipex.com ([81.86.40.42]:52801 helo=yog-sothoth.mohorovi.cc) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kh9hZ-00029K-R4 for emacs-orgmode@gnu.org; Sat, 20 Sep 2008 17:09:14 -0400 Received: from nyarlathotep.internal.mohorovi.cc (Debian-exim@nyarlathotep.internal.mohorovi.cc [10.0.0.5]) by yog-sothoth.mohorovi.cc (8.14.2/8.14.2) with ESMTP id m8KL9Bjg017673 for ; Sat, 20 Sep 2008 22:09:12 +0100 (BST) (envelope-from ahktenzero@mohorovi.cc) Received: from [127.0.0.1] (helo=nyarlathotep.internal.mohorovi.cc ident=ahktenzero) by nyarlathotep.internal.mohorovi.cc with esmtp (Exim 4.69) (envelope-from ) id 1Kh9hX-0005qV-Tp for emacs-orgmode@gnu.org; Sat, 20 Sep 2008 22:09:11 +0100 In-Reply-To: <20080920210101.19759.15959.stgit@nyarlathotep.internal.mohorovi.cc> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Add a module to contrib for handling repeated tasks which require checkin= g off a list of items. --- contrib/ChangeLog | 5 ++ contrib/lisp/org-checklist.el | 110 +++++++++++++++++++++++++++++++++++= ++++++ 2 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 contrib/lisp/org-checklist.el diff --git a/contrib/ChangeLog b/contrib/ChangeLog index c49e4b4..195f2b3 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,7 @@ +2008-09-20 James TD Smith + + * lisp/org-checklist.el: Add various checklist handling functions + 2008-09-02 Carsten Dominik =20 * lisp/org-mairix.el: Update to version 0.5. @@ -12,6 +16,7 @@ * lisp/org-mtags.el (org-mtags-replace): Allow prefix and prefix1 as options in the include directive. =20 + 2008-06-18 Christian Egli =20 * scripts/org2hpda (DIARY): Make the location of the diary file diff --git a/contrib/lisp/org-checklist.el b/contrib/lisp/org-checklist.e= l new file mode 100644 index 0000000..09ff911 --- /dev/null +++ b/contrib/lisp/org-checklist.el @@ -0,0 +1,110 @@ +;;; org-checklist.el --- org functions for checklist handling +;; +;; =C2=A92008 James TD Smith +;; +;; Author: James TD Smith (@ ahktenzero (. mohorovi cc)) +;; Version: 1.0 +;; Keywords: org, checklists +;; +;; This program 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, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, write to the Free Software +;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +;; +;;; Commentary: +;; This file provides some functions for handing repeated tasks which in= volve +;; checking off a list of items. By setting the RESET_CHECK_BOXES proper= ty in an +;; item, when the TODO state is set to done all checkboxes under that it= em are +;; cleared. If the LIST_EXPORT_BASENAME property is set, a file will be = created +;; using the value of that property plus a timestamp, containing all the= items +;; in the list which are not checked. Additionally the user will be prom= pted to +;; print the list. +;; +;; I use this for to keep track of stores of various things (food stores= , +;; components etc) which I check periodically and use the exported list = of items +;; which are not present as a shopping list. +;; +;;; Usage: +;; (require 'org-checklist) +;; +;; Set the RESET_CHECK_BOXES and LIST_EXPORT_BASENAME properties in item= s as +;; needed. +;; +;;; Code: +(require 'org) + +(defvar export-time-format "%Y%m%d%H%M" + "format of timestamp appended to export file") +(defvar export-function 'org-export-as-ascii + "function used to prepare the export file for printing") + +(defun org-reset-checkbox-state-maybe () + "Reset all checkboxes in an entry if the `RESET_CHECK_BOXES' property = is set" + (interactive "*") + (if (org-entry-get (point) "RESET_CHECK_BOXES") + (save-restriction + (save-excursion + (org-narrow-to-subtree) + (org-show-subtree) + (goto-char (point-min)) + (let ((end (point-max))) + (while (< (point) end) + (when (org-at-item-checkbox-p) + (replace-match "[ ]" t t)) + (beginning-of-line 2)))) + (org-update-checkbox-count-maybe)))) + +(defun org-make-checklist-export () + "Produce a checklist containing all unchecked items from a list +of checkbox items" + (interactive "*") + (if (org-entry-get (point) "LIST_EXPORT_BASENAME") + (let* ((export-file (concat (org-entry-get (point) "LIST_EXPORT_BA= SENAME") + "-" (format-time-string export-time-format) + ".org")) + exported-lines + title) + (save-restriction + (save-excursion + (org-narrow-to-subtree) + (org-show-subtree) + (goto-char (point-min)) + (if (looking-at org-complex-heading-regexp) + (setq title (match-string 4))) + (goto-char (point-min)) + (let ((end (point-max))) + (while (< (point) end) + (when (and (org-at-item-checkbox-p) + (or (string=3D (match-string 0) "[ ]") + (string=3D (match-string 0) "[-]"))) + (add-to-list 'exported-lines (thing-at-point 'line) t)) + (beginning-of-line 2))) + (set-buffer (get-buffer-create export-file)) + (org-insert-heading) + (insert (or title export-file) "\n") + (dolist (entry exported-lines) (insert entry)) + (org-update-checkbox-count-maybe) + (write-file export-file) + (if (y-or-n-p "Print list? ") + ((funcall export-function) + (a2ps-buffer)))))))) + +(defun org-checklist () + (if (member state org-done-keywords) + (org-make-checklist-export)) + (org-reset-checkbox-state-maybe)) + +(add-hook 'org-after-todo-state-change-hook 'org-checklist) + +(provide 'org-checklist) + +;;; org-elisp-symbol.el ends here