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

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

[emacs-wiki-discuss] sacha/planner-diary-schedule-task


From: Sacha Chua
Subject: [emacs-wiki-discuss] sacha/planner-diary-schedule-task
Date: Fri, 16 Apr 2004 12:01:26 +0800
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

I like associating tasks with schedule entries, and I suspect other
people do as well. Here's code to make it easy to schedule tasks.
To use:

Position point on a task, like

#A0 _ Tell everyone about sacha/planner-diary-schedule-task {{Tasks:1}}

Invoke M-x sacha/planner-diary-schedule-task. It will prompt you for
start and end time. I prefer 24h time.

Start: 13:00
End: 14:00

It'll rewrite the task to look like this so that you know you've
scheduled the task already:

#A0 _ Tell everyone about sacha/planner-diary-schedule-task 
{{Schedule:13:00-14:00}}

and create a diary entry in the current buffer that looks like this:

13:00 | 14:00 | Tell everyone about sacha/planner-diary-schedule-task 
{{Tasks:1}}

If you don't want it to add a Schedule tag to the current task, you
can just edit the function or grab my old copy at
http://sacha.free.net.ph/EmacsHacks.php .

If your preferred schedule format is different, just tweak the
function. =)

Have fun!

----------------------------------------------------------------

(defun sacha/planner-diary-schedule-task (start end)
  "Add a diary entry for the current task from START to END."
  (interactive "MStart: \nMEnd: ")
  (save-window-excursion
    (save-excursion
      (save-restriction
        (let* ((info (planner-current-task-info))
               (original (planner-task-description info))
               description)
          ;; TODO: Mark the task as scheduled for a particular time
          (setq description
                (cond
                 ((string-match "\\s-+{{Schedule:\\([^}]+\\)}}" original)
                  (replace-match (concat start "-" end) t t original 1))
                 ((string-match "\\(\\s-*\\)$" original)
                  (replace-match (concat " {{Schedule:" start "-" end "}}")
                                 t t original 1))))
          (save-window-excursion
            (when (planner-task-link info)
              (planner-jump-to-linked-task)
              (let ((info (planner-current-task-info)))
                (setcar (cdr (cdr (cdr (cdr info))))
                        description)
                (delete-region (line-beginning-position)
                               (min (point-max)
                                    (1+ (line-end-position))))
                (insert (planner-format-task info) "\n"))))
          (setcar (cdr (cdr (cdr (cdr info))))
                  description)
          (delete-region (line-beginning-position)
                         (min (point-max)
                              (1+ (line-end-position))))
          (insert (planner-format-task info) "\n")
          ;; Add the diary entry
          (sacha/planner-diary-add-entry
           (planner-task-date info)
           (concat start " | " end " | " original)))))))

(defun sacha/planner-diary-add-entry (date text &optional annotation)
  "Prompt for a diary entry to add to `diary-file'."
  (interactive
   (list
    (if (or current-prefix-arg
            (not (string-match planner-date-regexp (planner-page-name))))
        (planner-read-date)
      (planner-page-name))
    (read-string
     "Diary entry: ")))
  (save-excursion
    (save-window-excursion
      (make-diary-entry
       (concat
        (let ((cal-date (planner-filename-to-calendar-date date)))
          (calendar-date-string cal-date t t))
        " " text
        (or annotation
            (let ((annotation (run-hook-with-args-until-success
                               'planner-annotation-functions)))
              (if annotation
                  (concat " " annotation)
                "")))))
      (planner-goto date)
      (planner-diary-insert-diary-maybe))))


-- 
Sacha Chua <address@hidden> - Ateneo CS faculty geekette
interests: emacs, gnu/linux, making computer science education fun
http://sacha.free.net.ph/ - PGP Key ID: 0xE7FDF77C




reply via email to

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