1 ;;; planner-accomplishments.el --- Accomplishment reports for planner.el
3 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5 ;; Emacs Lisp Archive Entry
6 ;; Filename: planner-accomplishments.el
7 ;; Keywords: hypermedia
8 ;; Author: Sandra Jean Chua (Sacha) <sacha@free.net.ph>
9 ;; Description: Produce accomplishment reports for planner.el
10 ;; URL: http://www.plannerlove.com/
11 ;; Compatibility: Emacs20, Emacs21, XEmacs21
13 ;; This file is part of Planner. It is not part of GNU Emacs.
15 ;; Planner is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; Planner is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with Planner; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 ;; Boston, MA 02110-1301, USA.
32 ;; planner-accomplishments.el produces accomplishment reports for
33 ;; planner files. On date pages, it summarizes tasks by associated PlanPage.
35 ;; DISPLAYING A TEMPORARY BUFFER
37 ;; You can call `planner-accomplishments-show' to display a buffer
38 ;; containing the current page's accomplishment report.
40 ;; REWRITING SECTIONS OF YOUR PLANNER
42 ;; Choose this approach if you want accomplishment reports to be in
43 ;; their own section and you would like them to be readable in your
44 ;; plain text files even outside Emacs. Caveat: The accomplishment
45 ;; section should already exist in your template and will be rewritten
48 ;; To use, set `planner-accomplishments-section' to the name of the
49 ;; section to rewrite (default: "Accomplishments"). If you want
50 ;; rewriting to be automatically performed, call
51 ;; `planner-accomplishments-insinuate'. The accomplishments will be
52 ;; rewritten whenever you save a planner page. If you want rewriting
53 ;; to be manual, call `planner-accomplishments-update'.
57 ;; - On plan pages, it summarizes tasks by associated date page
58 ;; (controlled by `planner-accomplishments-plan-page-days'). Tasks
59 ;; are broken down by status.
65 ;;; USER VARIABLES -----------------------------------------------------------
67 (defgroup planner-accomplishments nil
68 "Accomplishment reports for planner.el."
69 :prefix
"planner-accomplishments"
72 (defcustom planner-accomplishments-section
"Accomplishments"
73 "Header for the accomplishments section in a plan page."
75 :group
'planner-accomplishments
)
77 (defcustom planner-accomplishments-status-display
78 '(("_" .
"Unfinished")
84 "Alist of status-label maps also defining the order of display."
85 :type
'(alist :key-type string
:value-type string
)
86 :group
'planner-accomplishments
)
88 (defvar planner-accomplishments-buffer
"*Planner Accomplishments*"
89 "Buffer name for accomplishment reports from `planner-accomplishments-show'.")
92 (defun planner-accomplishments-insinuate ()
93 "Automatically call `planner-accomplishments-update'."
94 (add-hook 'planner-mode-hook
97 (if (and (boundp 'write-file-functions
)
98 (not (featurep 'xemacs
)))
101 'planner-accomplishments-update nil t
))))
104 (defun planner-accomplishments-update ()
105 "Update `planner-accomplishments-section'."
109 (when (planner-narrow-to-section planner-accomplishments-section
)
110 (delete-region (point-min) (point-max))
111 (insert "* " planner-accomplishments-section
"\n\n"
112 (planner-accomplishments-format-table
113 (planner-accomplishments-extract-data))
115 nil
)))) ; Return nil for write-file-functions
118 (defun planner-accomplishments-show ()
119 "Display a buffer with the current page's accomplishment report."
121 (let ((page (and (planner-derived-mode-p 'planner-mode
)
122 (planner-page-name)))
123 (data (planner-accomplishments-extract-data)))
125 (set-buffer (get-buffer-create planner-accomplishments-buffer
))
126 (cd (planner-directory))
127 (setq muse-current-project
(muse-project planner-project
))
130 (insert "Accomplishment report for "
131 (planner-make-link page
) "\n\n"
132 (planner-accomplishments-format-table data
)
134 (goto-char (point-min))
135 (display-buffer (get-buffer-create planner-accomplishments-buffer
) t
))))
137 (defun planner-accomplishments-extract-data ()
138 "Return a list of ((link . status) . count) for tasks on the current page."
142 (goto-char (point-min))
144 (while (re-search-forward planner-task-regexp nil t
)
145 (let* ((info (planner-current-task-info))
146 (key (cons (planner-task-link info
)
147 (planner-task-status info
)))
148 (entry (assoc key results
)))
150 (setcdr entry
(1+ (cdr entry
)))
151 (setq results
(cons (cons key
1) results
)))))
154 (defun planner-accomplishments-total-by-link (data)
155 "Return a list of (link . total)."
159 (let ((entry (assoc (car (car item
)) results
)))
161 (setcdr entry
(+ (cdr entry
) (cdr item
)))
162 (setq results
(cons (cons (car (car item
)) (cdr item
)) results
)))))
166 (defun planner-accomplishments-total-by-status (data)
167 "Return a list of (status . total)."
171 (let ((entry (assoc (cdr (car item
)) results
)))
173 (setcdr entry
(+ (cdr entry
) (cdr item
)))
174 (setq results
(cons (cons (cdr (car item
)) (cdr item
)) results
)))))
178 (defun planner-accomplishments-format-table (data)
179 "Format DATA from `planner-accomplishments-extract-data' into a table."
180 (let ((links (planner-accomplishments-total-by-link data
))
181 (status (planner-accomplishments-total-by-status data
))
182 (page-format "%-30.30s")
184 (setq links
(sort links
(lambda (a b
) (> (cdr a
) (cdr b
)))))
185 ;; Determine the status to be displayed
187 (insert (format page-format
"Link"))
190 (when (assoc (car s
) status
)
191 (insert " | " (cdr s
))
192 (setq displayed-status
194 (format "%%%dd" (length (cdr s
))))
196 planner-accomplishments-status-display
)
197 (insert " | Total\n")
198 (setq displayed-status
(nreverse displayed-status
))
201 (insert (if (car page
)
202 (let ((len (length (car page
)))
203 (link (planner-make-link (car page
))))
205 (concat link
(make-string (- 30 len
) ?\
))
211 (format (concat " | " (cdr s
))
212 (or (cdr (assoc (cons (car page
) (car s
)) data
)) 0))))
214 (insert (format " | %5d\n" (cdr page
))))
216 (insert (format page-format
"Total"))
220 (setq count
(+ count
(cdr (assoc (car s
) status
))))
222 (format (concat " | " (cdr s
))
223 (cdr (assoc (car s
) status
)))))
225 (insert (format " | %5d\n" count
)))
228 (provide 'planner-accomplishments
)
230 ;;; planner-accomplishments.el ends here