Re: Re: planner task syntax

Jim Ottaway <[email protected]>
Newsgroups gmane.emacs.wiki.general
Message-ID <[email protected]>
>>>>> Torsten Anders <[email protected]> writes:

> Just to be a bit more specific: how can I change the function below
> such that it expects a page/file/buffer as an argument? How is such a
> page usually given (path? string of page content?). Thank you very
> much.

> (defun torsten/planner-schedule-sum-task-durations ()
>      "Returns duration sum of all tasks in buffer (?). The duration is
>      returned in seconds."
>      (save-excursion
>        (goto-char (point-min))
>        (let ((result 0))
>          (while (re-search-forward "^#[A-C]" nil t)
>            (let* ((task (planner-current-task-info))
>                   (time (<get-duration> task)))
>              (setq result (+ result time))))
>          result)))

I think that planner-find-file would be suitable, something like this
[untested]:

(defun torsten/planner-schedule-sum-task-durations (page)
  "Returns duration sum of all tasks in PAGE.
The duration is returned in seconds."
  (planner-find-file page)
  (save-excursion
    (goto-char (point-min))
    (let ((result 0))
      (while (re-search-forward "^#[A-C]" nil t)
        (let* ((task (planner-current-task-info))
               (time (<get-duration> task)))
          (setq result (+ result time))))
      result)))

It would probably be a good idea to use `planner-task-regexp' for the
re-search-forward' regexp.

You might also want to wrap the body of this [or the loop that uses
this function] with `with-planner-update-setup' so that newly opened
files are cleaned up.

A suitable function to get a list of day pages is
planner-get-day-pages: 

,----[ C-h f planner-get-day-pages RET ]
| planner-get-day-pages is a compiled Lisp function in `planner.el'.
| (planner-get-day-pages &optional FROM TO EXCLUDE-TEMP)
| 
| Return a descending list of day pages from FROM to TO (inclusive).
| If EXCLUDE-TEMP is non-nil, ignore unsaved pages.
| 
| [back]
`----

It returns an alist of (page-name . path) elements, so you would want
to just use the car of each element as arguments for planner-find-file.

I hope this helps.

-- 
Jim Ottaway
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.