Browse Source

Improve error reporting in org-habit.

Include the entry in the error messages in org-habit-parse-todo. This makes it
much easier to find the heading you need to fix.
James TD Smith 15 years ago
parent
commit
aeb35b7995
2 changed files with 13 additions and 8 deletions
  1. 3 0
      lisp/ChangeLog
  2. 10 8
      lisp/org-habit.el

+ 3 - 0
lisp/ChangeLog

@@ -1,5 +1,8 @@
 2009-11-12  James TD Smith  <ahktenzero@mohorovi.cc>
 2009-11-12  James TD Smith  <ahktenzero@mohorovi.cc>
 
 
+	* org-habit.el (org-habit-parse-todo): Indicate which habit is
+	wrongly set up in the error messages.
+
 	* org-colview.el (org-columns-display-here): Don't try to
 	* org-colview.el (org-columns-display-here): Don't try to
 	calculate values if the underlying property is not set.
 	calculate values if the underlying property is not set.
 	(org-columns-string-to-number): Convert age strings back into
 	(org-columns-string-to-number): Convert age strings back into

+ 10 - 8
lisp/org-habit.el

@@ -149,19 +149,21 @@ This list represents a \"habit\" for the rest of this module."
 	   (scheduled-repeat (org-get-repeat org-scheduled-string))
 	   (scheduled-repeat (org-get-repeat org-scheduled-string))
 	   (sr-days (org-habit-duration-to-days scheduled-repeat))
 	   (sr-days (org-habit-duration-to-days scheduled-repeat))
 	   (end (org-entry-end-position))
 	   (end (org-entry-end-position))
+	   (habit-entry (org-no-properties (nth 5 (org-heading-components))))
 	   closed-dates deadline dr-days)
 	   closed-dates deadline dr-days)
       (if scheduled
       (if scheduled
 	  (setq scheduled (time-to-days scheduled))
 	  (setq scheduled (time-to-days scheduled))
-	(error "Habit has no scheduled date"))
+	(error "Habit %s has no scheduled date" habit-entry))
       (unless scheduled-repeat
       (unless scheduled-repeat
-	(error "Habit has no scheduled repeat period"))
+	(error "Habit %s has no scheduled repeat period" habit-entry))
       (unless (> sr-days 0)
       (unless (> sr-days 0)
-	(error "Habit's scheduled repeat period is less than 1d"))
+	(error "Habit %s scheduled repeat period is less than 1d" habit-entry))
       (when (string-match "/\\([0-9]+[dwmy]\\)" scheduled-repeat)
       (when (string-match "/\\([0-9]+[dwmy]\\)" scheduled-repeat)
 	(setq dr-days (org-habit-duration-to-days
 	(setq dr-days (org-habit-duration-to-days
 		       (match-string-no-properties 1 scheduled-repeat)))
 		       (match-string-no-properties 1 scheduled-repeat)))
 	(if (<= dr-days sr-days)
 	(if (<= dr-days sr-days)
-	    (error "Habit's deadline repeat period is less than or equal to scheduled"))
+	    (error "Habit %s deadline repeat period is less than or equal to scheduled (%s)"
+		   habit-entry scheduled-repeat))
 	(setq deadline (+ scheduled (- dr-days sr-days))))
 	(setq deadline (+ scheduled (- dr-days sr-days))))
       (org-back-to-heading t)
       (org-back-to-heading t)
       (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\\]" end t)
       (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\\]" end t)
@@ -218,13 +220,13 @@ SCHEDULED-DAYS defaults to the habit's actual scheduled days if nil.
 Habits are assigned colors on the following basis:
 Habits are assigned colors on the following basis:
   Blue      Task is before the scheduled date.
   Blue      Task is before the scheduled date.
   Green     Task is on or after scheduled date, but before the
   Green     Task is on or after scheduled date, but before the
-            end of the schedule's repeat period.
+	    end of the schedule's repeat period.
   Yellow    If the task has a deadline, then it is after schedule's
   Yellow    If the task has a deadline, then it is after schedule's
-            repeat period, but before the deadline.
+	    repeat period, but before the deadline.
   Orange    The task has reached the deadline day, or if there is
   Orange    The task has reached the deadline day, or if there is
-            no deadline, the end of the schedule's repeat period.
+	    no deadline, the end of the schedule's repeat period.
   Red       The task has gone beyond the deadline day or the
   Red       The task has gone beyond the deadline day or the
-            schedule's repeat period."
+	    schedule's repeat period."
   (let* ((scheduled (or scheduled-days (org-habit-scheduled habit)))
   (let* ((scheduled (or scheduled-days (org-habit-scheduled habit)))
 	 (s-repeat (org-habit-scheduled-repeat habit))
 	 (s-repeat (org-habit-scheduled-repeat habit))
 	 (scheduled-end (+ scheduled (1- s-repeat)))
 	 (scheduled-end (+ scheduled (1- s-repeat)))