]> code.delx.au - gnu-emacs/blobdiff - lisp/org/org-habit.el
Spelling fixes.
[gnu-emacs] / lisp / org / org-habit.el
index 394b4fb05db3c3eefe2ecc70430eda4c3d42968e..c146a5bebbd43aba6e17f525cfe5141b20bf4b55 100644 (file)
@@ -1,11 +1,11 @@
 ;;; org-habit.el --- The habit tracking code for Org-mode
 
-;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2009-2011 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw at gnu dot org>
 ;; Keywords: outlines, hypermedia, calendar, wp
 ;; Homepage: http://orgmode.org
-;; Version: 7.3
+;; Version: 7.7
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -170,10 +170,18 @@ This list represents a \"habit\" for the rest of this module."
                   habit-entry scheduled-repeat))
        (setq deadline (+ scheduled (- dr-days sr-days))))
       (org-back-to-heading t)
-      (while (re-search-forward "- State \"DONE\".*\\[\\([^]]+\\)\\]" end t)
-       (push (time-to-days
-              (org-time-string-to-time (match-string-no-properties 1)))
-             closed-dates))
+      (let* ((maxdays (+ org-habit-preceding-days org-habit-following-days))
+            (reversed org-log-states-order-reversed)
+            (search (if reversed 're-search-forward 're-search-backward))
+            (limit (if reversed end (point)))
+            (count 0))
+       (unless reversed (goto-char end))
+       (while (and (< count maxdays)
+                   (funcall search "- State \"DONE\".*\\[\\([^]]+\\)\\]" limit t))
+         (push (time-to-days
+                (org-time-string-to-time (match-string-no-properties 1)))
+               closed-dates)
+         (setq count (1+ count))))
       (list scheduled sr-days deadline dr-days closed-dates))))
 
 (defsubst org-habit-scheduled (habit)
@@ -197,10 +205,7 @@ This list represents a \"habit\" for the rest of this module."
   "Determine the relative priority of a habit.
 This must take into account not just urgency, but consistency as well."
   (let ((pri 1000)
-       (now (time-to-days
-             (or moment
-                 (time-subtract (current-time)
-                                (list 0 (* 3600 org-extend-today-until) 0)))))
+       (now (if moment (time-to-days moment) (org-today)))
        (scheduled (org-habit-scheduled habit))
        (deadline (org-habit-deadline habit)))
     ;; add 10 for every day past the scheduled date, and subtract for every
@@ -353,6 +358,6 @@ current time."
 
 (provide 'org-habit)
 
-;; arch-tag: 64e070d9-bd09-4917-bd44-44465f5ed348
+
 
 ;;; org-habit.el ends here