diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-04-23 18:46:09 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-04-23 18:46:09 +0200 |
commit | ef901153404d24ca1694a2b98e845eaca47aa085 (patch) | |
tree | b6951abaacb63226819235c08a2b596795dc62d3 | |
parent | Fix failing test. (diff) | |
download | calp-ef901153404d24ca1694a2b98e845eaca47aa085.tar.gz calp-ef901153404d24ca1694a2b98e845eaca47aa085.tar.xz |
Change how util is loaded.
Diffstat (limited to '')
-rw-r--r-- | module/config.scm | 20 | ||||
-rwxr-xr-x | module/main.scm | 12 | ||||
-rw-r--r-- | module/parameters.scm | 23 |
3 files changed, 40 insertions, 15 deletions
diff --git a/module/config.scm b/module/config.scm index f15c73d5..6a7358e4 100644 --- a/module/config.scm +++ b/module/config.scm @@ -2,6 +2,7 @@ ;;; Currently loaded by main, and requires that `calendar-files` ;;; is set to a list of files (or directories). +(define-module (config) #:use-module (parameters)) (use-modules (srfi srfi-26) (srfi srfi-88) @@ -9,10 +10,10 @@ (ice-9 regex) (ice-9 rdelim)) -(define calendar-files - (let ((path (string-append (getenv "HOME") "/.calendars/"))) - (map (cut string-append path <>) - (scandir path (lambda (str) (not (char=? #\. (string-ref str 0)))))))) +(calendar-files + (let ((path (string-append (getenv "HOME") "/.calendars/"))) + (map (cut string-append path <>) + (scandir path (lambda (str) (not (char=? #\. (string-ref str 0)))))))) ;;; TODO possibly replace with propper lookup (define my-courses @@ -26,8 +27,9 @@ (define* (aref alist key optional: default) (or (assoc-ref alist key) default key)) -(define (summary-filter ev str) - (regexp-substitute/global - #f "T[A-Z]{3}[0-9]{2}" str - 'pre (lambda (m) (aref my-courses (string->symbol (match:substring m)))) - 'post)) +(summary-filter + (lambda (ev str) + (regexp-substitute/global + #f "T[A-Z]{3}[0-9]{2}" str + 'pre (lambda (m) (aref my-courses (string->symbol (match:substring m)))) + 'post))) diff --git a/module/main.scm b/module/main.scm index 6a2cd9c9..095a4d7c 100755 --- a/module/main.scm +++ b/module/main.scm @@ -22,6 +22,8 @@ (terminal util) (html html) + + (parameters) ) (define (ev-time<? a b) @@ -59,7 +61,7 @@ (if (= i cur-event) "\x1b[7m" "") (color-escape (attr (parent ev) 'COLOR)) ;; Summary filter is a hook for the user - (trim-to-width (summary-filter ev (attr ev 'SUMMARY)) 30) + (trim-to-width ((summary-filter) ev (attr ev 'SUMMARY)) 30) STR-RESET (trim-to-width (or (attr ev 'LOCATION) "\x1b[1;30mINGEN LOKAL") 20) @@ -67,8 +69,6 @@ events (iota (length events)))) -(define (summary-filter _ str) str) - (define (main-loop event-stream) (define time (now)) (define cur-event 0) @@ -132,8 +132,8 @@ - -(load "config.scm") +;; (load "config.scm") +(use-modules (config)) ;; 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 @@ -141,7 +141,7 @@ ;; ;; Given as a sepparate function from main to ease debugging. (define (init proc) - (define calendars (map make-vcomponent calendar-files)) + (define calendars (map make-vcomponent (calendar-files))) (define events (concatenate (map (cut children <> 'VEVENT) calendars))) (let* ((repeating regular (partition repeating? events))) diff --git a/module/parameters.scm b/module/parameters.scm new file mode 100644 index 00000000..45b8862b --- /dev/null +++ b/module/parameters.scm @@ -0,0 +1,23 @@ +;;; Commentary: + +;; This file should define all global configurable variables which +;; doesn't belong anywhere else. The config module should then import +;; this module, and set all configs as needed. The config module +;; should also be able to set configs gotten from other parts. + +;;; Code: + +(define-module (parameters)) + +(define (ensure pred?) + (lambda (v) + (unless (pred? v) + (error "Bad value to config")) + v)) + +(define-public calendar-files + (make-parameter + '() (ensure list?))) + +(define-public summary-filter + (make-parameter (lambda (_ a) a) (ensure procedure?))) |