unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting another diary-sexp.
@ 2021-08-25  3:46 Yuchen Pei
  2021-08-25 11:31 ` Lars Ingebrigtsen
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Yuchen Pei @ 2021-08-25  3:46 UTC (permalink / raw)
  To: 50195


[-- Attachment #1.1: Type: text/plain, Size: 164 bytes --]

Hello,

See below my first patch to Emacs.  The copyright assignment has 
already been done BTW.

Let me know what you think. Would you like me to add some tests?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: the patch --]
[-- Type: text/x-patch, Size: 2827 bytes --]

From d385b1bc02f2922fbff4496f81d4574d0abcf082 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <hi@ypei.me>
Date: Wed, 25 Aug 2021 13:37:20 +1000
Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting another
 diary-sexp.

A bit like diary-remind, as a diary-sexp rather than reminder, and
also support both positive and negative offsets.

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.
---
 doc/emacs/calendar.texi    | 14 ++++++++++++++
 lisp/calendar/diary-lib.el | 11 +++++++++++
 2 files changed, 25 insertions(+)

diff --git a/doc/emacs/calendar.texi b/doc/emacs/calendar.texi
index 3750e78e70..44766c92de 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 post-event 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
+@samp{'(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/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el
index f57fe26058..d83a60680f 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.
+Entry applies if the date is DAYS days after another diary-sexp SEXP."
+  (with-no-warnings (defvar date) (defvar entry))
+  (integerp days)
+  (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))
-- 
2.33.0


[-- Attachment #1.3: Type: text/plain, Size: 131 bytes --]


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
           <https://ypei.me/assets/ypei-pubkey.txt>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 243 bytes --]

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-09-04  7:21 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-25  3:46 bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting another diary-sexp Yuchen Pei
2021-08-25 11:31 ` Lars Ingebrigtsen
2021-08-25 11:52 ` Eli Zaretskii
2021-08-25 12:06   ` Lars Ingebrigtsen
2021-08-25 12:24     ` Eli Zaretskii
2021-08-25 12:38       ` Lars Ingebrigtsen
2021-08-25 15:22       ` Michael Heerdegen
2021-08-25 15:32         ` Michael Heerdegen
2021-08-25 16:07         ` Eli Zaretskii
2021-08-25 16:22           ` Michael Heerdegen
2021-08-26  6:52             ` Yuchen Pei
2021-08-26  9:26               ` Michael Heerdegen
2021-08-26  6:49   ` bug#50195: [PATCH] Adding diary-offset to diary-lib.el Yuchen Pei
2021-08-26  6:54     ` Yuchen Pei
2021-08-27 13:16       ` Yuchen Pei
2021-09-03 22:40         ` Yuchen Pei
2021-09-04  6:15           ` Eli Zaretskii
2021-09-04  6:29             ` Lars Ingebrigtsen
2021-09-04  7:21               ` Yuchen Pei
2021-08-26 10:26 ` bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting another diary-sexp Michael Heerdegen
2021-08-27 13:11   ` Yuchen Pei

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).