The only thing this code does is gray out stuff that can't be done
yet. For really cool stuff, we should be doing fancy sorting and
whatnot, but I don't feel up to doing a topological sort in Emacs Lisp
at 2 in the morning. =)
It's easy to change the syntax. For example, we can use 2->1,5 to mean
that this is task 2 and it's dependent on tasks 1 and 5. That might be
fun.
Hope this sparks an aha! moment somewhere. =)
----------------------------------------------------------------
;;; Task dependency tracking for Planner
;; #A X Do something {{Tasks:1}}
;; #B _ Do another thing {{Depends:1,5}} {{Tasks:2}}
;; #B _ Do yet another thing {{Depends:1}} {{Tasks:3}}
;; Task 3 depends on a completed task, so it will be okay. Task 2
;; still has an incomplete dependency, so it'll be grayed out after
;; (planner-depend-highlight-tasks).
(defface planner-depend-invalid-face
'((t (:foreground "gray")))
"Face for tasks with incomplete dependencies."
:group 'planner-depend)
(defun planner-depend-highlight-tasks ()
"Gray out all tasks with dependencies not satisfied on the current page."
(goto-char (point-min))
(let (found-ids)
;; Find all the completed IDs
(while (re-search-forward "{{Tasks:\\(0-9+\\)}}" nil t)
(let* ((task-id (number-to-string (match-string 1)))
(info (planner-current-task-info)))
(when (string= "X" (planner-task-status info))
(setq found-ids (cons task-id found-ids)))))
;; Highlight everything else
(goto-char (point-min))
(while (re-search-forward planner-task-regexp nil t)
(let ((info (planner-current-task-info))
dependencies
failed)
(when (string-match "{{Depends:\\([0-9,]+\\)}}"
(planner-task-description info))
(setq dependencies (split-string (match-string 1
(planner-task-description info)) ","))
(while dependencies
(if (memq (string-to-number (car dependencies)) found-ids)
(setq dependencies (cdr dependencies))
(setq dependencies nil
failed t)))
(when failed
(planner-highlight-region (planner-line-beginning-position)
(planner-line-end-position)
'dependency
100
'(face planner-depend-invalid-face))))))))
--
Sacha Chua <[EMAIL PROTECTED]> - open source geekette
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C
interests: emacs, gnu/linux, personal information management, juggling
sachac on irc.freenode.net#emacs . YM: sachachua83
_______________________________________________
emacs-wiki-discuss mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/emacs-wiki-discuss