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 | |
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 '')
-rw-r--r-- | module/vcomponent.scm | 5 | ||||
-rw-r--r-- | module/vcomponent/base.scm | 2 | ||||
-rw-r--r-- | module/vcomponent/load.scm | 39 |
3 files changed, 43 insertions, 3 deletions
diff --git a/module/vcomponent.scm b/module/vcomponent.scm index 0283161e..f40756e2 100644 --- a/module/vcomponent.scm +++ b/module/vcomponent.scm @@ -1,8 +1,9 @@ (define-module (vcomponent) :use-module (vcomponent base) :use-module (vcomponent parse) + :use-module (vcomponent load) :use-module (util) - :re-export (make-vcomponent parse-cal-path parse-calendar)) + :re-export (make-vcomponent parse-cal-path + parse-calendar load-calendars)) (re-export-modules (vcomponent base)) - diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm index aa5b9de9..bf15510d 100644 --- a/module/vcomponent/base.scm +++ b/module/vcomponent/base.scm @@ -26,7 +26,7 @@ (children children set-component-children!) (parent get-component-parent set-component-parent!) (attributes get-component-attributes)) -(export children type) +(export vcomponent? children type) ;; TODO should this also update the parent (define-public parent 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)))))) |