From 37a87cc34e78a6af28085b57450c0665e80e1aaf Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Tue, 11 Feb 2025 20:26:30 -0800 Subject: [PATCH] Update cl/khal-notify.lisp --- cl/khal-notify.lisp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/cl/khal-notify.lisp b/cl/khal-notify.lisp index f0b1683..5225511 100644 --- a/cl/khal-notify.lisp +++ b/cl/khal-notify.lisp @@ -36,6 +36,16 @@ (subseq str 0 (1- len)) str))) +(defun process-escape-sequences (str) + (coerce (loop with escape = nil + for chr across str + when (and (not escape) (eql chr #\\)) + do (setq escape t) + else + do (setq escape nil) and + collect chr) + 'string)) + (defun get-ics-file-alarms (path) (with-open-file (stream path :direction :input :if-does-not-exist nil) (when stream @@ -49,7 +59,10 @@ while line do (cond ((and (not in-valarm) (uiop:string-prefix-p "SUMMARY:" line)) - (setq summary (subseq (remove-trailing-return line) 8))) + (setq summary (subseq + (process-escape-sequences + (remove-trailing-return line)) + 8))) ((uiop:string-prefix-p "BEGIN:VALARM" line) (setq in-valarm t)) ((uiop:string-prefix-p "END:VALARM" line) @@ -59,18 +72,19 @@ current-notice "")) ((and in-valarm (uiop:string-prefix-p "TRIGGER:" line)) (ppcre:register-groups-bind - (negative (#'parse-integer num) unit) - (pattern (subseq line 8)) - (setq current-offset - (* (if (equal negative "-") -1 1) - (cond - ((equal unit "S") num) - ((equal unit "M") (* num 60)) - ((equal unit "H") (* num 60 60)) - ((equal unit "D") (* num 60 60 24)) - (t 0)))))) + (negative (#'parse-integer num) unit) + (pattern (subseq line 8)) + (setq current-offset + (* (if (equal negative "-") -1 1) + (cond + ((equal unit "S") num) + ((equal unit "M") (* num 60)) + ((equal unit "H") (* num 60 60)) + ((equal unit "D") (* num 60 60 24)) + (t 0)))))) ((and in-valarm (uiop:string-prefix-p "DESCRIPTION:" line)) - (setq current-notice (subseq (remove-trailing-return line) + (setq current-notice (subseq (process-escape-sequences + (remove-trailing-return line)) 12)))) finally (return (mapcar (lambda (alarm) (list (if (uiop:emptyp (car alarm)) @@ -115,7 +129,8 @@ :time alarm-time :event-title event-title :event-end end - :uid uid)))) alarms))))))) + :uid uid)))) + alarms))))))) (defun build-alarm-list (calendar-dirs &optional exclude-before) (let* ((output (run-khal "list" @@ -166,4 +181,4 @@ (defun toplevel () (sb-ext:disable-debugger) (exit-on-ctrl-c - (main))) + (main)))