From 4df9db3eeb3b048579768050ae7bb413fefe9557 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 25 Aug 2021 13:37:20 +1000 Subject: [PATCH] Adding diary-offset to diary-lib.el. A new diary sexp that offsets another diary sexp (Bug#50195). * doc/emacs/calendar.texi: Document the change. * lisp/calendar/diary-lib.el (diary-offset): * test/lisp/calendar/icalendar-tests.el: Add a test. --- doc/emacs/calendar.texi | 14 ++++++++++++++ etc/NEWS | 8 ++++++++ lisp/calendar/diary-lib.el | 11 +++++++++++ test/lisp/calendar/icalendar-tests.el | 7 +++++++ 4 files changed, 40 insertions(+) diff --git a/doc/emacs/calendar.texi b/doc/emacs/calendar.texi index 3750e78e70..18de721e28 100644 --- a/doc/emacs/calendar.texi +++ b/doc/emacs/calendar.texi @@ -1363,6 +1363,20 @@ Special Diary Entries Thursday of January, February, and March. If the month is @code{t}, the entry applies to all months of the year. +@findex diary-offset +@example +%%(diary-offset '(diary-float t 3 4) 2) Monthly committee meeting +@end example + +@noindent +This entry applies to the Saturday after the third Thursday of each +month. The 2 specifies number of days after when the sexp +@w{@code{'(diary-float t 3 4)}} would evaluate to @code{t}. This is +useful when for example your organization has a committee meeting two +days after every monthly meeting which takes place on the third +Thursday, or if you would like to attend a virtual meeting scheduled +in a different timezone causing a difference in the date. + Each of the standard sexp diary entries takes an optional parameter specifying the name of a face or a single-character string to use when marking the entry in the calendar. Most generally, sexp diary entries diff --git a/etc/NEWS b/etc/NEWS index 07a78216b8..52774b3463 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2800,6 +2800,14 @@ never be narrower than 19 characters. 'gomoku-move-sw' and 'gomoku-move-ne' now work correctly, and horizontal movements now stop at the edge of the board. ++++ +*** New diary sexp 'diary-offset'. +It offsets another diary sexp by a number of days. This is useful +when for example your organization has a committee meeting two days +after every monthly meeting which takes place on the third Thursday, +or if you would like to attend a virtual meeting scheduled in a +different timezone causing a difference in the date. + ** xterm-mouse mode --- diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index f57fe26058..f71392b97f 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -2014,6 +2014,17 @@ diary-cyclic (and (>= diff 0) (zerop (% diff n)) (cons mark (format entry cycle (diary-ordinal-suffix cycle)))))) +;; To be called from diary-sexp-entry, where DATE, ENTRY are bound. +(defun diary-offset (sexp days) + "Offsetted diary entry. Offsets SEXP by DAYS days. +Entry applies if the date is DAYS days after another diary-sexp SEXP." + (with-no-warnings (defvar date)) + (or (integerp days) (user-error "Days must be an integer")) + (let ((date + (calendar-gregorian-from-absolute + (- (calendar-absolute-from-gregorian date) days)))) + (eval sexp))) + (defun diary-day-of-year () "Day of year and number of days remaining in the year of date diary entry." (with-no-warnings (defvar date)) diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el index 6973f7e5c9..de2a891758 100644 --- a/test/lisp/calendar/icalendar-tests.el +++ b/test/lisp/calendar/icalendar-tests.el @@ -1442,6 +1442,13 @@ icalendar-real-world SUMMARY:ff birthday (%d years old)") + (icalendar-tests--test-export + nil + nil + "%%(diary-offset '(diary-float t 3 4) 1) asdf" + nil) + + ;; FIXME! ;; export 2004-10-28 monthly, weekly entries -- 2.33.0