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

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

[emacs-wiki-discuss] planner-target.el: Importancy and Emergency support


From: Dryice Liu
Subject: [emacs-wiki-discuss] planner-target.el: Importancy and Emergency support in planner
Date: Thu, 27 Jan 2005 05:12:33 +0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (berkeley-unix)

Hi,

I started this a week ago and finally found sometime to finish it
today. So if you find bugs and mismatches, please point out.

Basically this is the Importancy and Emergency support we talked about
several weeks ago. Steal from pyGTD :) Now we have everything we've
talked about except planner-timeclock-summary.el support. I'm too
sleepy... Please see the Commentary for details.

Among the three attached files:

one is a patch to planner-deadline.el, moving the calculation of how
many days left out to be a function, and add some helper
functions. Also add planner-deadline-change-hook.

One is a patch to planner.el, adding a helper function
planner-set-task-category.

And the other is the planner-target.el, of cause :) Sorry I couldn't
think off a good name. Priority would be the best choice but it's
already used. If anyone can think off a good name, it's not too late
to change it :)

Attachment: planner-target.el
Description: application/emacs-lisp

--- planner.el.orig     Mon Jan 24 18:52:46 2005
+++ planner.el  Thu Jan 27 04:10:27 2005
@@ -3300,6 +3300,21 @@
 ;; numbers priorities and "A/B/C" categories. I'm not really sure if I
 ;; can change the name right now. I suppose we eventually should.
 
+(defun planner-set-task-category (category)
+  "Set the category of the current task.
+This changes a low-priority task to a medium-priority task
+and a medium-priority task to a high-priority task."
+  (let ((info (planner-current-task-info)))
+    (when info
+      (delete-region (line-beginning-position)
+                     (min (point-max) (1+ (line-end-position))))
+      (save-excursion
+        (insert (planner-format-task
+                 info
+                 category) "\n"))
+      (when (planner-task-link info)
+        (planner-update-task)))))
+
 (defun planner-raise-task-category ()
   "Raise the category of the current task.
 This changes a low-priority task to a medium-priority task
--- planner-deadline.el.orig    Mon Jan 24 19:21:32 2005
+++ planner-deadline.el Thu Jan 27 03:28:45 2005
@@ -42,6 +42,12 @@
   :prefix "planner-deadline"
   :group 'planner)
 
+(defcustom planner-deadline-change-hook nil
+  "Functions to run after `planner-deadline-change'.
+Point will be on the same line as the task."
+  :type 'hook
+  :group 'planner-deadline)
+
 (defcustom planner-deadline-regexp 
"\\({{Deadline:\\s-+\\([0-9]+\\.[0-9]+\\.[0-9]+\\)[^}]*}}\\)"
   "Regular expression for deadline data.
 The special deadline string should be regexp group 1. The
@@ -49,6 +55,43 @@
   :type 'regexp
   :group 'planner-deadline)
 
+(defsubst planner-deadline-get-deadline-from-string (string)
+  "Return the deadline in STRING."
+  (save-match-data
+    (if (string-match planner-deadline-regexp string)
+       (match-string-no-properties 2 string)
+      nil)))
+
+(defsubst planner-deadline-get-current-deadline ()
+  "Return the deadline of the current task."
+  (planner-deadline-get-deadline-from-string 
+   (buffer-substring (line-beginning-position) (line-end-position))))
+
+(defun planner-deadline-days-left (deadline task-info)
+  "Return how many days are left for the given task."
+  (let (diff)
+    (when (planner-task-date task-info)
+      (setq diff
+           (- (calendar-absolute-from-gregorian
+               (planner-filename-to-calendar-date
+                deadline))
+              (calendar-absolute-from-gregorian
+               (planner-filename-to-calendar-date
+                (planner-task-date task-info))))))
+    (let ((date
+          (if (string-match planner-date-regexp (planner-page-name))
+              (planner-page-name)
+            (planner-today))))
+      (unless (string< deadline (planner-today))
+       (setq diff
+             (- (calendar-absolute-from-gregorian
+                 (planner-filename-to-calendar-date
+                  deadline))
+                (calendar-absolute-from-gregorian
+                 (planner-filename-to-calendar-date
+                  date))))))
+    diff))
+
 (defun planner-deadline-update ()
   "Replace the text for all tasks with deadlines.
 By default, deadlines are of the form {{Deadline: yyyy.mm.dd}}.
@@ -62,29 +105,10 @@
              (deadline (match-string 2))
              diff new)
         (save-match-data
-          (if task-info
-              (when (and (not (equal status "X"))
-                         (not (equal status "C"))
-                         (planner-task-date task-info))
-                (setq diff
-                      (- (calendar-absolute-from-gregorian
-                          (planner-filename-to-calendar-date
-                           deadline))
-                         (calendar-absolute-from-gregorian
-                          (planner-filename-to-calendar-date
-                           (planner-task-date task-info))))))
-            (let ((date
-                   (if (string-match planner-date-regexp (planner-page-name))
-                       (planner-page-name)
-                     (planner-today))))
-              (unless (string< deadline (planner-today))
-                (setq diff
-                      (- (calendar-absolute-from-gregorian
-                          (planner-filename-to-calendar-date
-                           deadline))
-                         (calendar-absolute-from-gregorian
-                          (planner-filename-to-calendar-date
-                           date))))))))
+          (if (and task-info
+                  (not (equal status "X"))
+                    (not (equal status "C")))
+             (setq diff (planner-deadline-days-left deadline task-info))))
         (when diff
           (setq new
                 (concat "{{Deadline: "
@@ -123,7 +147,8 @@
                                               date
                                               "}}"))
       (planner-edit-task-description description)))
-  (planner-deadline-update))
+  (planner-deadline-update)
+  (run-hooks 'planner-deadline-change-hook))
 
 (provide 'planner-deadline)
 

-- 
Cheers,
Dryice

http://dryice.3322.org

reply via email to

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