I've created a diary function to allow me to record cyclic events.
So something like
(diary-limited-cyclic-weekday 8 '(0 3 6) 01 01 2018) will create an event for every Sunday, Wednesday, and Saturday since the start date. So in the example: the 3, 6, 7, 10, 13, 14, 17, and 20th of January 2018 should be marked with an event.
I put this function in an org file as:
<%%(diary-limited-cyclic-weekday 8 '(0 3 6) 01 01 2018)> 09:00-10:00
When I run it I get
Bad sexp at line 9 in /home/luis/Documents/org/agenda/schedule.org: (let ((entry ) (date (quote (1 1 2018)))) (diary-limited-cyclic-weekday 8 (quote (0 3 6)) 1 1 2018))
I get subsequent errors just like this except with the day in
(quote (1 1 2018)) incremented by 1.
Bad sexp at line 9 ... (quote 1 2 2018)... Bad sexp at line 9 ... (quote 1 3 2018)... ...
At first this made me think that perhaps my function was too slow and because of this taking too long to return a value for a single date.
I wrote this function trying to emulate the
diary-limited-cyclic function I found online.
What could be the problem with my function? Note that even when I remove the potentially complicated
(> recurrences ...) sexp at the end, and expect it to just return every Sun, Wed, Sat afterwards, I get the same error.
(defun diary-limited-cyclic-weekday (recurrences weekdays m d y) "For use in emacs diary. Cyclic item with a limited number of occurences. WEEKDAYS is a list of the days of the week (0-6) in which event will repeat starting on YYYY-MM-DD, for a total of RECURRENCES occasions." (let* ((today-day (calendar-day-of-week date)) (today (calendar-absolute-from-gregorian date)) (start (calendar-absolute-from-gregorian (list m d y))) (start-day (calendar-day-of-week start)) (day-range (- today start))) (and (not (cl-minusp day-range)) ; not less than start day (cl-member today-day weekdays) ; is one of the desired weekdays ;; number of target weekdays in full weeks ;; + number of target weekdays in remainder days (> recurrences (+ (* (cl-list-length weekdays) (cl-mod day-range 7)) (cl-loop for day from start-day to (+ start-day (cl-rem day-range 7)) count (cl-member day weekdays))))))) (defun diary-limited-cyclic (recurrences interval m d y) "For use in emacs diary. Cyclic item with limited number of recurrences. Occurs every INTERVAL days, starting on YYYY-MM-DD, for a total of RECURRENCES occasions." (let ((startdate (calendar-absolute-from-gregorian (list m d y))) (today (calendar-absolute-from-gregorian date))) (and (not (cl-minusp (- today startdate))) (zerop (% (- today startdate) interval)) (< (floor (- today startdate) interval) recurrences))))