From b223f825f6081982063469986259bf1e1981b2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Mon, 2 Mar 2026 17:10:04 +0100 Subject: [PATCH] =?UTF-8?q?=CE=B7-reduce=20icr:make-bysetpos-filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lisp/calendar/icalendar-recur.el | 44 ++++++++++----------- test/lisp/calendar/icalendar-recur-tests.el | 5 +-- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lisp/calendar/icalendar-recur.el b/lisp/calendar/icalendar-recur.el index 4de4d00281f..696112c653d 100644 --- a/lisp/calendar/icalendar-recur.el +++ b/lisp/calendar/icalendar-recur.el @@ -953,8 +953,8 @@ BYSECOND=... clause; see `icalendar-recur' for the possible values." (BYMINUTE (icr:refine-byminute interval values vtimezone)) (BYSECOND (icr:refine-bysecond interval values vtimezone)))) -(defun icr:make-bysetpos-filter (setpos) - "Return a filter on values for the indices in SETPOS. +(defun icr:bysetpos-filter (setpos recurrences) + "Filter RECURRENCES on values for the indices in SETPOS. SETPOS should be a list of positive or negative integers between -366 and 366, indicating a fixed index in a set of recurrences for *one @@ -963,25 +963,24 @@ an `icalendar-recur'. For example, in a YEARLY recurrence rule with an INTERVAL of 1, the SETPOS represent indices in the recurrence instances generated for a single year. -The returned value is a closure which can be called on the list of -recurrences for one interval to filter it by index." - (lambda (dts) - (let* ((len (length dts)) - (keep-indices (mapcar - (lambda (pos) - ;; sequence indices are 0-based, POS's are 1-based: - (if (< pos 0) - (+ pos len) - (1- pos))) - setpos)) - (r nil) - (i 0)) - (while dts - (when (memq i keep-indices) - (push (car dts) r)) - (incf i) - (pop dts)) - (nreverse r)))) +The returned value is RECURRENCES filtered by index." + (let* ((len (length recurrences)) + (keep-indices (mapcar + (lambda (pos) + ;; sequence indices are 0-based, POS's are 1-based: + (if (< pos 0) + (+ pos len) + (1- pos))) + setpos)) + (r nil) + (i 0) + (dts recurrences)) + (while dts + (when (memq i keep-indices) + (push (car dts) r)) + (incf i) + (pop dts)) + (nreverse r))) (defun icr:refine-from-clauses (interval recur-value dtstart &optional vtimezone) @@ -1225,8 +1224,7 @@ retrieved on subsequent calls with the same arguments." (keep-indices (ical:recur-by* 'BYSETPOS recur-value)) (pos-recs (if keep-indices - (funcall (icr:make-bysetpos-filter keep-indices) - sub-recs) + (icr:bysetpos-filter keep-indices sub-recs) sub-recs)) ;; Remove any recurrences before DTSTART or after UNTIL ;; (both of which are inclusive bounds): diff --git a/test/lisp/calendar/icalendar-recur-tests.el b/test/lisp/calendar/icalendar-recur-tests.el index 655be9b8c7a..028319035c7 100644 --- a/test/lisp/calendar/icalendar-recur-tests.el +++ b/test/lisp/calendar/icalendar-recur-tests.el @@ -117,13 +117,12 @@ END:VTIMEZONE ;; Tests for basic functions: (ert-deftest ict:recur-bysetpos-filter () - "Test that `icr:make-bysetpos-filter' filters correctly by position" + "Test that `icr:bysetpos-filter' filters correctly by position" (let* ((t1 (list 1 1 2024)) (t2 (list 2 1 2024)) (t3 (list 12 30 2024)) (dts (list t1 t2 t3)) - (filter (icr:make-bysetpos-filter (list 1 -1))) - (filtered (funcall filter dts))) + (filtered (icr:bysetpos-filter (list 1 -1) dts))) (should (member t1 filtered)) (should (member t3 filtered)) (should-not (member t2 filtered))))