Yesterday morning, Jim Ottaway wrote: [snip] > >> I still have one problem, that is related to the weekly-view >> production. Right now I have a function that collects the appts for 6 days, >> starting from the beginning of the week. My problem is how to get the right >> Monday date from (planner-today). There's a function that works with the >> calendar cursor, but that's no good, because it messes the weekly-view >> code. I'd like to calculate it, but didn't put much thought into it - I was >> hoping there was already a nice elisp function to do it for me! (Btw, if you >> want to test this, it already works, but only if calendar cursor is under a >> Monday!) > > Does this work?: > > (defun planner-beginning-of-week (planner-date) > (let ((date (planner-filename-to-calendar-date planner-date))) > (planner-date-to-filename > (calendar-gregorian-from-absolute > (+ (calendar-absolute-from-gregorian date) > (- calendar-week-start-day > (calendar-day-of-week date))))))) > > It uses calendar-week-start-day for consistency with calendar [0 for > Sunday, 1 for Monday, etc.].
Thanks, it works fine! It's better than something I've arranged myself, that would do a recursion subtracting one day at a time and asking "is it Monday yet?" :) I've now come to decent results. I was having some problems because I had forgotten to fix `planner-appt-forthcoming-get-cyclic'. I don't really know how the first dolist "was" working (because it was!), but I had to add a START-DAY optional argument (not affecting callers of the previous function), and this is working for me: (defun planner-appt-forthcoming-get-cyclic (n &optional start-day) (let ((appts '()) (cyclic-task-descriptions '()) (start-day (or start-day (planner-today))) date line time text task-info task-data) (dolist (entry (planner-list-diary-entries planner-cyclic-diary-file (planner-filename-to-calendar-date (planner-calculate-date-from-day-offset start-day 0)) (1+ n))) (setq date (planner-date-to-filename (car entry)) line (cadr entry)) (if (string-match planner-appt-schedule-appt-regexp line) (setq time (save-match-data (appt-convert-time (match-string 1 line))) text (match-string 0 line)) (when (string-match planner-appt-forthcoming-task-regexp line) (setq task-info (planner-task-info-from-string date line)) (setq task-data (planner-appt-forthcoming-task-data task-info)) (when task-data ;; For duplicate checking: remember the description as ;; it would be transformed by planner-cyclic. (push (format planner-cyclic-task-description-format (planner-task-description task-info) date) cyclic-task-descriptions) (setq time (car task-data) text (cdr task-data))))) (when (and time text) (add-to-list 'appts (list (calendar-absolute-from-gregorian (car entry)) time date text)) (setq time nil text nil))) (cons appts cyclic-task-descriptions))) So now I have a weekly-view by adding the appts only to the diary entries with this advice: (defadvice week-graph-view-diary-entries (around show-planner-appts activate) (let ((list-diary-entries-hook '(planner-include-appt-entries))) ad-do-it)) And the "magic" function is: (defun planner-include-appt-entries () "Add diary entries with todays planner appointments." (declare (special original-date)) (let ((start-day (planner-beginning-of-week (planner-date-to-filename original-date)))) ;; Cycle through forthcoming appts for all the week days: (dolist (appt (planner-appt-forthcoming-get-appts 4 start-day)) (let ((date (car appt)) ;; date : YYYY.MM.DD (text (cadr appt))) ;; description: @START-TIME | END-TIME | TEXT (add-to-diary-list (planner-filename-to-calendar-date date) text ""))))) Don't forget you have to change cal-desk's regexp recognition (unfortunately they're hard coded, it'd be better to have some variable regexp list!), and add the regexps I've mentioned in a previous post in this thread to `diary-time-regexp-list'. On my TODO list are the following interesting (at least for me) issues: - Make tooltips to weekly-view entries, with start and end times and description - Make buttons with links in weekly-view entries - Give different colors to weekly-view entries (e.g., tasks priorities) - Make entries editable. This could be tricky, because I'd have to detect cyclic entries (changing the diary file) and task entries (and I'd use `planner-edit-task-description'). Hope someone will enjoy this! ;) -- Edgar Gonçalves Software Engineering Group @ INESC-ID IST/Technical University of Lisbon Rua Alves Redol, 9, Room 635 1000-029 Lisboa, Portugal mailto:edgar[DOT]goncalves[AT]inesc[DASH]id[DOT]pt http://www.esw.inesc-id.pt/~eemg _______________________________________________ emacs-wiki-discuss mailing list emacs-wiki-discuss@nongnu.org http://lists.nongnu.org/mailman/listinfo/emacs-wiki-discuss