diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-12-23 23:40:14 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-12-24 00:02:02 +0100 |
commit | 92b2f429a06ed9b052baff5e27f012397b338f6a (patch) | |
tree | 0ca9c2d8d1d72f5c898ee8384c2ef5459c1ef112 /module/vcomponent/load.scm | |
parent | Move open-{input,output}-port to (util io). (diff) | |
download | calp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.gz calp-92b2f429a06ed9b052baff5e27f012397b338f6a.tar.xz |
Rework program initialization.
Old init setup had the fancy idea to parse all files before anything
could be done with them. This however led to problems when a part of the
program which didn't care for the calendar files (such as text
formatting).
It also made testing performance almost impossible since to much code
was run before I had a chance to init statprof.
Diffstat (limited to 'module/vcomponent/load.scm')
-rw-r--r-- | module/vcomponent/load.scm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/module/vcomponent/load.scm b/module/vcomponent/load.scm new file mode 100644 index 00000000..fb25732d --- /dev/null +++ b/module/vcomponent/load.scm @@ -0,0 +1,39 @@ +(define-module (vcomponent load) + :export (load-calendars) + :use-module (util) + :use-module (srfi srfi-1) + :use-module (srfi srfi-19) + :use-module (srfi srfi-41) + :use-module (srfi srfi-41 util) + :use-module (parameters) + ;; :use-module (vcomponent) + :use-module (vcomponent base) + :use-module ((vcomponent parse) :select (parse-cal-path)) + :use-module ((vcomponent recurrence) :select (generate-recurrence-set repeating?)) + :use-module ((vcomponent datetime) :select (ev-time<?))) + + +;; Reads all calendar files from disk, and creates a list of "regular" events, +;; and a stream of "repeating" events, which are passed in that order to the +;; given procedure @var{proc}. +;; +;; Given as a sepparate function from main to ease debugging. +(define* (load-calendars #:key (calendar-files (calendar-files))) + (define calendars (map parse-cal-path calendar-files)) + (define events (concatenate + ;; TODO does this drop events? + (map (lambda (cal) (filter (lambda (o) (eq? 'VEVENT (type o))) + (children cal))) + calendars))) + + (let* ((repeating regular (partition repeating? events))) + + (set! repeating (sort*! repeating time<? (extract 'DTSTART)) + regular (sort*! regular time<? (extract 'DTSTART))) + + (values + calendars + (interleave-streams + ev-time<? + (cons (list->stream regular) + (map generate-recurrence-set repeating)))))) |