5 Commits 3e1ed0de1e ... 79bb4b629b

Author SHA1 Message Date
  c1-g 79bb4b629b docs: Update Readme 2 years ago
  c1-g de7cbd146a add: org-agenda-dych-default-end 2 years ago
  c1-g c84e58c9a3 fix: Indentation 2 years ago
  c1-g 8814a217bb change: Ignore unscheduled tasks when rescheduling 2 years ago
  c1-g 37526cec3b fix: Prevent errors 2 years ago
2 changed files with 27 additions and 19 deletions
  1. 2 2
      README.org
  2. 25 17
      org-agenda-dych-mode.el

+ 2 - 2
README.org

@@ -1,4 +1,4 @@
-* *Dy*namic s*ch*eduling for org-agenda
+* DYnamic SCheduling for org-agenda
 
 A minor mode that keeps optimum proportions of time devoted to
 particular tasks in your agenda. Meant to replicate the [[https://www.help.supermemo.org/wiki/Plan][Plan]] tool in
@@ -8,7 +8,7 @@ particular tasks in your agenda. Meant to replicate the [[https://www.help.super
 
 The project is still alpha & untested! It might ruin your entire agenda scheduling so be careful!
 
-** Why?
+** Motivation
 
 I haven't seen this kind of dynamic time allocation that works in Linux. If such a thing exists then I reckon it wouldn't integrate well with org files and my agenda.
 

+ 25 - 17
org-agenda-dych-mode.el

@@ -43,6 +43,9 @@
 (defcustom org-agenda-dych-default-work-hour "8h"
   "The length of your schedule in hours.")
 
+(defcustom org-agenda-dych-default-end "16:00"
+  "The length of your schedule in hours.")
+
 (defcustom org-agenda-dych-default-start "08:00"
   "The default start time to start the working day."
   :group 'org-properties
@@ -63,7 +66,6 @@ Includes leading space character.")
   (or (bound-and-true-p org-agenda-dych-overriding-start)
       (car (alist-get 'org-agenda-dych-overriding-start
                       (nth 2 (org-get-at-bol 'org-series-cmd))))
-      org-agenda-dych-current-start
       org-agenda-dych-default-start))
 
 ;;; Utilities
@@ -179,12 +181,15 @@ ARG is passed through to `org-agenda-schedule'."
    ((bound-and-true-p org-overriding-work-hours))
    ((let ((m (org-get-at-bol 'org-hd-marker)))
       (and m (with-current-buffer (marker-buffer m)
-               org-agenda-dych-default-work-hour))))
+               (- (org-duration-to-minutes org-agenda-dych-default-end)
+                  (org-duration-to-minutes (org-agenda-dych-get-start)))))))
    ((let ((m (next-single-property-change (point-min) 'org-hd-marker)))
       (and m (let ((m (get-text-property m 'org-hd-marker)))
                (with-current-buffer (marker-buffer m)
-                 org-agenda-dych-default-work-hour)))))
-   (t org-agenda-dych-default-work-hour)))
+                 (- (org-duration-to-minutes org-agenda-dych-default-end)
+                    (org-duration-to-minutes (org-agenda-dych-get-start))))))))
+   (t (- (org-duration-to-minutes org-agenda-dych-default-end)
+         (org-duration-to-minutes (org-agenda-dych-get-start))))))
 
 (defun org-agenda-dych-get-dotime (&optional point)
   "Get the scheduled time of the current entry or the entry at POINT."
@@ -324,7 +329,8 @@ have the user confirm to set its scheduled time as the start of the day."
                                  (org-get-at-bol 'org-hd-marker) t)
                                 (setq rigid-minute
                                       (string-to-number
-                                       (calc-eval (format "%f+%f" rigid-minute (org-get-at-bol 'effort-minutes)))))
+                                       (calc-eval (format "%f+%f" rigid-minute
+                                                          (org-get-at-bol 'effort-minutes)))))
                                 (cl-incf rigid-count))))
 
                  block-start
@@ -335,10 +341,11 @@ have the user confirm to set its scheduled time as the start of the day."
         
           (setq neffort (abs (string-to-number
                               (calc-eval (format "(%f-%f-%f)/%d"
-                                                 (org-duration-to-minutes
-                                                  (or (and (not (eq (org-agenda-dych-get-dotime) 'time))
-                                                           (org-agenda-dych-get-dotime))
-                                                      (org-agenda-dych-get-workhours)))
+                                                 (or (ignore-errors
+                                                       (org-duration-to-minutes
+                                                        (and (not (eq (org-agenda-dych-get-dotime) 'time))
+                                                             (org-agenda-dych-get-dotime))))
+                                                     (org-agenda-dych-get-workhours))
                                                  (org-duration-to-minutes
                                                   (or (org-agenda-dych-get-dotime block-start)
                                                       "0:00"))
@@ -349,18 +356,19 @@ have the user confirm to set its scheduled time as the start of the day."
           (save-excursion
             (dolist (pl effort-plists)
               (goto-line (plist-get pl :index))
-              (if (plist-get pl :fixed)
+              (if (and (plist-get pl :fixed)
+                       (string= (org-get-at-bol 'type) "scheduled"))
                   (setq org-last-inserted-timestamp
                         (org-agenda-dych-h:mm-to-full-ts
                          (plist-get pl :dotime)))
                 (let ((ntime (seconds-to-time
-                                 (string-to-number
-                                  (calc-eval (format "(%f*60)+%f"
-                                                     (if lrigid leffort neffort)
-                                                     (org-time-string-to-seconds
-                                                      (if org-last-inserted-timestamp
-                                                          (substring org-last-inserted-timestamp 1 -1)
-                                                        (org-agenda-dych-h:mm-to-full-ts (org-agenda-dych-get-start))))))))))
+                              (string-to-number
+                               (calc-eval (format "(%f*60)+%f"
+                                                  (if lrigid leffort neffort)
+                                                  (org-time-string-to-seconds
+                                                   (if org-last-inserted-timestamp
+                                                       (substring org-last-inserted-timestamp 1 -1)
+                                                     (org-agenda-dych-h:mm-to-full-ts (org-agenda-dych-get-start))))))))))
                   (when (org-agenda-dych-time-less-than-tomorrow-p ntime)
                     (org-agenda-dych-maybe-schedule
                      nil (format-time-string (org-time-stamp-format t) ntime)))))