emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] planner-report.el updates


From: Andrew J. Korty
Subject: [emacs-wiki-discuss] planner-report.el updates
Date: Sun, 05 Dec 2004 21:41:07 -0500
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (darwin)

Here are some major updates to planner-report.el:

- New customization option planner-report-remove-task-numbers enables
  removal of task priority numbers in status reports (they don't
  increment per-project and therefore don't mean much).
  
- New customization option planner-report-replace-note-numbers enables
  replacement of note numbers (again, they don't mean much in a status
  report) with some string (defaults to "**").

- New customization option planner-report-unfinished-offset specifies
  the number of days from the current date of unfinished tasks to
  include in the status report.  Before, all unfinished tasks were
  included.

- Fix bugs that caused some tasks and notes to be left out.

- Remove redundant code.

Here's the patch against today's dev snapshot.  Hope it works!

--8<---------------cut here---------------start------------->8---
--- planner/planner-report.el~  Sat Dec  4 03:38:57 2004
+++ planner/planner-report.el   Sun Dec  5 21:39:00 2004
@@ -1,13 +1,13 @@
 ;;; planner-report.el --- create a timely status report based on planner pages
 
-;; Copyright 2004 by Andrew J. Korty <address@hidden>
+;; Copyright 2004 by Andrew J. Korty <address@hidden>
 
 ;; Emacs Lisp Archive Entry
 ;; Filename: planner-authz.el
-;; Version: $Revision: 1.4 $
+;; Version: $Revision: 1.11 $
 ;; Keywords: hypermedia
-;; Author: Andrew J. Korty <address@hidden>
-;; Maintainer: Andrew J. Korty <address@hidden>
+;; Author: Andrew J. Korty <address@hidden>
+;; Maintainer: Andrew J. Korty <address@hidden>
 ;; Description: Create a timely status report based on planner pages
 ;; URL: 
 ;; Compatibility: Emacs21
@@ -75,9 +75,9 @@
 ;; All user-serviceable options can be customized with
 ;; M-x customize-group RET planner-report RET.
 
-;;; Code
+;; $Id: planner-report.el,v 1.11 2004/12/06 02:39:00 ajk Exp $
 
-;; $Id: planner-report.el,v 1.4 2004/06/21 22:58:36 ajk Exp $
+;;; Code:
 
 (defgroup planner-report nil
   "A planner.el extension for generating timely status reports
@@ -86,72 +86,95 @@
   :prefix "planner-report")
 
 (defcustom planner-report-authz nil
-  "List of users a status report should be restricted to.  When
-status reports are generated, only planner pages accessible by
-these users will be consulted, and the resulting status report
+  "List of users a status report should be restricted to.
+When status reports are generated, only planner pages accessible
+by these users will be consulted, and the resulting status report
 will be similarly restricted."
   :group 'planner-report
   :type '(repeat string))
 
-(defvar planner-report-version "$Revision: 1.4 $"
+(defcustom planner-report-remove-task-numbers t
+  "Remove task numbers when generating status reports."
+  :group 'planner-report
+  :type 'boolean)
+
+(defcustom planner-report-replace-note-numbers "**"
+  "If non-nil, a string with which to replace note numbers when
+generating status reports."
+  :group 'planner-report
+  :type 'string)
+
+(defcustom planner-report-unfinished-offset nil
+  "If non-nil, the offset in days from the current date of
+unfinished tasks to include in the status report.  If nil,
+include all unfinished tasks."
+  :group 'planner-report
+  :type '(choice (integer :tag "Number of days")
+                (const :tag "Include all unifinished tasks" nil)))
+
+(defvar planner-report-version "$Revision: 1.11 $"
   "Version of of planner-report.el.")
 
 (defun planner-report-generate (begin end)
-  "Generate a status report spanning a period from BEG to END,
-which are in the format YYYY.MM.DD."
+  "Generate a status report spanning a period from BEGIN to END.
+BEGIN and END are in the format YYYY.MM.DD."
   (interactive
    (let ((planner-expand-name-favor-future-p
-                (or planner-expand-name-favor-future-p
-                    planner-task-dates-favor-future-p)))
-           (list (planner-report-read-date "Start date")
-                 (planner-report-read-date "End date"))))
+          (or planner-expand-name-favor-future-p
+              planner-task-dates-favor-future-p)))
+     (list (planner-read-date "Start date")
+           (planner-read-date "End date"))))
   (save-some-buffers nil (lambda () (derived-mode-p 'emacs-wiki-mode)))
   (cd planner-directory)
-  (with-temp-buffer
-    (when planner-report-authz
-      (require 'planner-authz)
-      (insert "#authz " (mapconcat 'identity planner-report-authz " ") "\n"))
-    (insert "#title Status report for " begin " to " end "\n")
-    (let ((pages (if planner-report-authz
-                     (planner-authz-file-alist planner-report-authz)
-                   (planner-file-alist)))
-          notes tasks)
-      (while pages
-        (when (caar pages)
-          ;; Add only project pages, and skip other status reports
-          (unless (or (string-match planner-name-regexp (caar pages))
-                      (string-match "^StatusReport" (caar pages)))
-            (with-temp-buffer
-              (insert-file-contents-literally (cdar pages))
-              (setq tasks (planner-report-find-tasks (caar pages) begin end))
-              (setq notes (planner-report-find-notes (caar pages) begin end))))
-          ;; Insert a linked heading if we found anything
-          (if (or notes tasks)
-              (insert "\n* [[" (caar pages) "]["
-                      (or (emacs-wiki-get-title-fast (cdar pages))
-                          (emacs-wiki-prettify-title (caar pages)))
-                      "]]\n\n"))
-          (when tasks
+  (let ((filename (concat "StatusReport" end)))
+    (with-temp-buffer
+      (when planner-report-authz
+        (require 'planner-authz)
+        (insert "#authz "
+                (mapconcat 'identity planner-report-authz " ") "\n"))
+      (insert "#title Status report for " begin " to " end "\n")
+      (let ((pages (if planner-report-authz
+                       (planner-authz-file-alist planner-report-authz)
+                     (planner-file-alist)))
+            notes tasks)
+        (while pages
+          (when (caar pages)
+            ;; Add only project pages, and skip other status reports
+            (unless (or (string-match planner-name-regexp (caar pages))
+                        (string-match "^StatusReport" (caar pages)))
+              (with-temp-buffer
+                (with-emacs-wiki-project planner-project
+                  (insert-file-contents-literally (cdar pages))
+                  (setq tasks
+                        (planner-report-find-tasks (caar pages) begin end))
+                  (setq notes
+                        (planner-report-find-notes (caar pages) begin end)))))
+            ;; Insert a linked heading if we found anything
+            (if (or notes tasks)
+                (insert "\n* [[" (caar pages) "]["
+                        (or (emacs-wiki-get-title-fast (cdar pages))
+                            (emacs-wiki-prettify-title (caar pages)))
+                        "]]\n\n"))
+            (when tasks
               (insert tasks "\n\n")
               (setq tasks nil))
-          (when notes
+            (when notes
               (insert notes "\n")
               (setq notes nil)))
-        (setq pages (cdr pages))))
-    (write-file
-     (concat "StatusReport"
-             (planner-date-to-filename (decode-time (current-time)))) t)))
+          (setq pages (cdr pages))))
+      (write-file filename t))
+    (find-file filename)))
 
 (defun planner-report-find-notes (page begin end)
-  "Find notes on planner page PAGE that were created between BEG
-and END, which are formatted as YYYY.MM.DD."
+  "Find notes on PAGE that were created between BEGIN and END.
+BEGIN and END are formatted as YYYY.MM.DD."
   (goto-char (point-min))
   (let (result)
     (while (re-search-forward "^\\.#[0-9]+\\s-+" nil t)
       (let ((note
               (buffer-substring
                (line-beginning-position)
-               (progn
+               (save-excursion
                  ;; Find the end of this note (maybe EOF)
                  (re-search-forward "^\\(\\.#[0-9]+\\s-+\\|\\*\\*?\\s-+\\)"
                                     nil 1)
@@ -165,12 +188,20 @@
             (and date
                  (not (string< date begin))
                  (not (string< end date))
-                 (setq result (if result (concat note result) note)))))))
+                (progn
+                  (if planner-report-replace-note-numbers
+                      (setq note
+                            (replace-regexp-in-string
+                             "^\\.#[0-9]+" planner-report-replace-note-numbers
+                             note t t)))
+                  (setq result (if result (concat note result) note))))))))
     result))
 
 (defun planner-report-find-tasks (page begin end)
-  "Find tasks on planner page PAGE that were created between BEG
-and END, which are formatted as YYYY.MM.DD."
+  "Find cancelled or completed tasks on PAGE with a date between
+BEGIN and END and any unfinished tasks with a date constrained by
+`planner-report-unfinished-offset'.  BEGIN and END are formatted
+as YYYY.MM.DD."
   (goto-char (point-min))
   (let (result)
     (while (re-search-forward "^#[A-C]" nil t)
@@ -179,31 +210,30 @@
              (info (planner-task-info-from-string page task)))
         (when info
           (let ((date (planner-task-date info)))
-            ;; If the task isn't completed and has a date, snarf.  If it
-            ;; has been completed and the date is in range, snarf.
+            ;; If the task isn't cancelled nor completed and has a
+            ;; date less than or equal to planner-report-unfinished
+            ;; away, snarf.  If it has been cancelled or completed and
+            ;; the date is in range, snarf.
             (and date
-                 (or (not (string= (planner-task-status info) "X"))
+                 (or (and (not (or (equal (planner-task-status info) "C")
+                                  (equal (planner-task-status info) "X")))
+                         (or (null planner-report-unfinished-offset)
+                             (not (string<
+                                   (planner-calculate-date-from-day-offset
+                                    (planner-date-to-filename
+                                     (decode-time (current-time)))
+                                    planner-report-unfinished-offset)
+                                   date))))
                      (and (not (string< date begin))
                           (not (string< end date))))
-                 (setq result (if result (concat result "\n" task) task)))))))
+                (progn
+                  (if planner-report-remove-task-numbers
+                      (setq task (replace-regexp-in-string
+                                  "^#[A-C]\\([0-9]+ +\\)" " " task t t 1)))
+                  (setq result
+                        (if result (concat result "\n" task) task))))))))
     result))
 
-(defun planner-report-read-date (prompt)
-  "Prompt for a date string in the minibuffer using PROMPT."
-  (save-excursion
-    (save-window-excursion
-      (calendar)
-      (let ((old-map (current-local-map)))
-        (unwind-protect
-            (let ((map (copy-keymap calendar-mode-map)))
-              (use-local-map map)
-              (define-key map (kbd "RET") 'planner-calendar-select)
-              (define-key map [mouse-1] 'planner-calendar-select)
-              (setq planner-calendar-selected-date nil)
-              (let ((text (read-string (format "%s %s" prompt
-                           (format-time-string
-                            "(%Y.%m.%d, %m.%d, %d): ")))))
-                (or planner-calendar-selected-date
-                    (planner-expand-name text))))
-          (use-local-map old-map))))))
+(provide 'planner-report)
 
+;;; planner-report.el ends here
--8<---------------cut here---------------end--------------->8---

-- 
Andrew J. Korty, Principal Security Engineer, GCIA, GCFA
Office of the Vice President for Information Technology
Indiana University




reply via email to

[Prev in Thread] Current Thread [Next in Thread]