emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: James TD Smith <ahktenzero@mohorovi.cc>
To: emacs-orgmode@gnu.org
Subject: [PATCH 6/9] Add some functions for handling checklists.
Date: Sat, 20 Sep 2008 22:09:11 +0100	[thread overview]
Message-ID: <20080920210911.19759.63738.stgit@nyarlathotep.internal.mohorovi.cc> (raw)
In-Reply-To: <20080920210101.19759.15959.stgit@nyarlathotep.internal.mohorovi.cc>

Add a module to contrib for handling repeated tasks which require checking 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  <ahktenzero@mohorovi.cc>
+
+	* lisp/org-checklist.el: Add various checklist handling functions
+
 2008-09-02  Carsten Dominik  <dominik@science.uva.nl>
 
 	* 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.
 
+
 2008-06-18  Christian Egli  <christian.egli@alumni.ethz.ch>
 
 	* scripts/org2hpda (DIARY): Make the location of the diary file
diff --git a/contrib/lisp/org-checklist.el b/contrib/lisp/org-checklist.el
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
+;;
+;; ©2008 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 involve
+;; checking off a list of items. By setting the RESET_CHECK_BOXES property in an
+;; item, when the TODO state is set to done all checkboxes under that item 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 prompted 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 items 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_BASENAME")
+				  "-" (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= (match-string 0) "[ ]")
+			       (string= (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

  parent reply	other threads:[~2008-09-20 21:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-20 21:08 [PATCH 0/9] Update my last patchset James TD Smith
2008-09-20 21:08 ` [PATCH 1/9] Some improvements to the modeline clock display James TD Smith
2008-09-20 21:08 ` [PATCH 2/9] Fix X clipboard handling in emacs21 James TD Smith
2008-09-20 21:08 ` [PATCH 3/9] Show durations of clocked times in timeline James TD Smith
2008-09-20 21:09 ` [PATCH 4/9] Fix link display in imenus and the refile interface James TD Smith
2008-09-21  6:25   ` Carsten Dominik
2008-09-21 14:31     ` [PATCH] " James TD Smith
2008-09-21 19:40       ` Carsten Dominik
2008-09-20 21:09 ` [PATCH 5/9] Fix note insertion in entries with drawers James TD Smith
2008-10-16  4:50   ` Carsten Dominik
2008-09-20 21:09 ` James TD Smith [this message]
2008-09-20 21:09 ` [PATCH 7/9] Add some new interaction between remember and clocked tasks James TD Smith
2008-09-20 21:09 ` [PATCH 8/9] Add a % expansion for inserting properties in remember buffers James TD Smith
2008-09-20 21:09 ` [PATCH 9/9] Some bugfixes for org-plot James TD Smith
2008-09-21  4:48 ` [PATCH 0/9] Update my last patchset Carsten Dominik
2008-09-21 12:21   ` James TD Smith
2008-09-21 12:43     ` Carsten Dominik

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=20080920210911.19759.63738.stgit@nyarlathotep.internal.mohorovi.cc \
    --to=ahktenzero@mohorovi.cc \
    --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).