GNU bug report logs - #50195
[PATCH] Adding diary-offset, a diary-sexp offsetting another diary-sexp.

Previous Next

Package: emacs;

Reported by: Yuchen Pei <hi <at> ypei.me>

Date: Wed, 25 Aug 2021 05:57:01 UTC

Severity: wishlist

Tags: patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50195 in the body.
You can then email your comments to 50195 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 05:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Yuchen Pei <hi <at> ypei.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 25 Aug 2021 05:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: bug-gnu-emacs <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting another
 diary-sexp.
Date: Wed, 25 Aug 2021 13:46:48 +1000
[Message part 1 (text/plain, inline)]
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?

[0001-Adding-diary-offset-a-diary-sexp-offsetting-another-.patch (text/x-patch, inline)]
From d385b1bc02f2922fbff4496f81d4574d0abcf082 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <hi <at> 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

[Message part 3 (text/plain, inline)]
-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 11:33:01 GMT) Full text and rfc822 format available.

Message #8 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Yuchen Pei <hi <at> ypei.me>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 13:31:49 +0200
Yuchen Pei <hi <at> ypei.me> writes:

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

Looks useful -- some tests would be nice.

> +;; 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

The (integerp days) here doesn't do anything -- is it supposed to be
(when (integerp days)

?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 11:54:02 GMT) Full text and rfc822 format available.

Message #11 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuchen Pei <hi <at> ypei.me>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset,
 a diary-sexp offsetting another diary-sexp.
Date: Wed, 25 Aug 2021 14:52:55 +0300
> From: Yuchen Pei <hi <at> ypei.me>
> Date: Wed, 25 Aug 2021 13:46:48 +1000
> 
> See below my first patch to Emacs.  The copyright assignment has 
> already been done BTW.

Congrats, and welcome aboard.

> Let me know what you think.

Some minor comments below.

> Would you like me to add some tests?

Adding more tests is always welcome, thanks.

> Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting another
>  diary-sexp.

"git am" uses the Subject for the heading line, and this Subject is
too long for that.  Please consider making it shorter.

> 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.

The commit log message should include a ChangeLog-style description of
the files and functions where you made the changes.  See CONTRIBUTE
for more details about the format we prefer.

Also, please in the next version include the bug number as part of the
log message.

> --- 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

That line is too long, and will overflow the page width in the printed
version of the manual.  Please break it in two.

> +@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
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This should be in @code, not @samp.  I'd also wrap it in @w{..}, so
that it doesn't get broken between two lines.

> +(defun diary-offset (sexp days)
> +  "Offsetted diary entry.

The first line of a doc string should preferably mention the
arguments, but without becoming too long, so it could still fit on a
single line.

> +  (with-no-warnings (defvar date) (defvar entry))

Why did you need this?

> +  (integerp days)

Isn't it better to use an assertion?

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 12:07:01 GMT) Full text and rfc822 format available.

Message #14 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Yuchen Pei <hi <at> ypei.me>, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 14:06:02 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

>> +  (with-no-warnings (defvar date) (defvar entry))
>
> Why did you need this?

It's how all these functions in diary-lib are defined after the lexical
rewrite -- the `eval' depends on those dynamic variables.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 12:26:02 GMT) Full text and rfc822 format available.

Message #17 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 15:24:54 +0300
> From: Lars Ingebrigtsen <larsi <at> gnus.org>
> Cc: Yuchen Pei <hi <at> ypei.me>,  50195 <at> debbugs.gnu.org
> Date: Wed, 25 Aug 2021 14:06:02 +0200
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> +  (with-no-warnings (defvar date) (defvar entry))
> >
> > Why did you need this?
> 
> It's how all these functions in diary-lib are defined after the lexical
> rewrite -- the `eval' depends on those dynamic variables.

Ugh!  Is it worth it?  If we cannot convert these functions to use
lexical-binding, maybe we should say lexical-binding: nil in the first
line of the file, and remove all those gross kludges?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 12:40:02 GMT) Full text and rfc822 format available.

Message #20 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 14:38:51 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

>> It's how all these functions in diary-lib are defined after the lexical
>> rewrite -- the `eval' depends on those dynamic variables.
>
> Ugh!  Is it worth it?  If we cannot convert these functions to use
> lexical-binding, maybe we should say lexical-binding: nil in the first
> line of the file, and remove all those gross kludges?

I think having all files lexically bound is a win in itself -- it means
that you know the Lisp dialect without looking at the mode line (and can
write code that depends on closures etc freely).

It does lead to these hacks here, yes, but it's already done, so...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 15:23:02 GMT) Full text and rfc822 format available.

Message #23 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 17:22:04 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> > It's how all these functions in diary-lib are defined after the lexical
> > rewrite -- the `eval' depends on those dynamic variables.
>
> Ugh!  Is it worth it?  If we cannot convert these functions to use
> lexical-binding, maybe we should say lexical-binding: nil in the first
> line of the file, and remove all those gross kludges?

That would not work, you would still get warnings about free variables.

This case is a bit special and not directly related to lexical-binding
because these variables are just not declared with `defvar' (and I think
we don't want to introduce global variables like `date').

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 15:33:01 GMT) Full text and rfc822 format available.

Message #26 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 17:32:26 +0200
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> This case is a bit special and not directly related to lexical-binding
> because these variables are just not declared with `defvar' (and I think
> we don't want to introduce global variables like `date').

(defvar date) could work, but note that the code uses `date' as function
argument variable as well, so adding this would introduce "shadowing"
warnings for these appearances.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 16:08:01 GMT) Full text and rfc822 format available.

Message #29 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: larsi <at> gnus.org, hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 19:07:39 +0300
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: Lars Ingebrigtsen <larsi <at> gnus.org>,  hi <at> ypei.me,  50195 <at> debbugs.gnu.org
> Date: Wed, 25 Aug 2021 17:22:04 +0200
> 
> > Ugh!  Is it worth it?  If we cannot convert these functions to use
> > lexical-binding, maybe we should say lexical-binding: nil in the first
> > line of the file, and remove all those gross kludges?
> 
> That would not work, you would still get warnings about free variables.

I don't understand.  This code did compile under dynamic-binding, so
what warnings did you have in mind?

> This case is a bit special and not directly related to lexical-binding
> because these variables are just not declared with `defvar' (and I think
> we don't want to introduce global variables like `date').

You are saying this always emitted warnings?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Wed, 25 Aug 2021 16:24:02 GMT) Full text and rfc822 format available.

Message #32 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, hi <at> ypei.me, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Wed, 25 Aug 2021 18:22:46 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

> > That would not work, you would still get warnings about free variables.
>
> I don't understand.  This code did compile under dynamic-binding, so
> what warnings did you have in mind?

You can just try, they look like

| In diary-list-entries-1:
| diary-lib.el:731:17: Warning: reference to free variable ‘number’
| diary-lib.el:734:48: Warning: reference to free variable ‘list-only’

I just removed lexical-binding from the header and commented the
`with-no-warnings' call in `diary-list-entries-1'.

> > This case is a bit special and not directly related to lexical-binding
> > because these variables are just not declared with `defvar' (and I think
> > we don't want to introduce global variables like `date').
>
> You are saying this always emitted warnings?

AFAIR there have been problems with these variables and warnings about
them for a long time, and different measures to handle them.  I think
(I'm not sure) we had (defvar date) in the file in the past.  If you
want to have any useful information you must ask Stefan, he was the one
that worked on that.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 06:50:02 GMT) Full text and rfc822 format available.

Message #35 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Thu, 26 Aug 2021 16:49:29 +1000
[Message part 1 (text/plain, inline)]
Thanks for the comments.
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Yuchen Pei <hi <at> ypei.me>
>> Date: Wed, 25 Aug 2021 13:46:48 +1000
>> 
>> See below my first patch to Emacs.  The copyright assignment 
>> has 
>> already been done BTW.
>
> Congrats, and welcome aboard.
>
>> Let me know what you think.
>
> Some minor comments below.
>
>> Would you like me to add some tests?
>
> Adding more tests is always welcome, thanks.

All diary sexp tests are in icalendar tests, but diary-offset does 
not easily translate to icalendar events (exporting to icalendar 
for this sexp is rather complicated if not impossible as it 
applies on top of another arbitrary sexp), so I am just adding a 
simple no-op-like test.

>
>> Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting 
>> another
>>  diary-sexp.
>
> "git am" uses the Subject for the heading line, and this Subject 
> is
> too long for that.  Please consider making it shorter.

Done.

>
>> 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.
>
> The commit log message should include a ChangeLog-style 
> description of
> the files and functions where you made the changes.  See 
> CONTRIBUTE
> for more details about the format we prefer.
>
> Also, please in the next version include the bug number as part 
> of the
> log message.

Done.

>
>> --- 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
>
> That line is too long, and will overflow the page width in the 
> printed
> version of the manual.  Please break it in two.

Done. I made it shorter :)

>
>> +@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
>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This should be in @code, not @samp.  I'd also wrap it in @w{..}, 
> so
> that it doesn't get broken between two lines.

Done.

>
>> +(defun diary-offset (sexp days)
>> +  "Offsetted diary entry.
>
> The first line of a doc string should preferably mention the
> arguments, but without becoming too long, so it could still fit 
> on a
> single line.

Done.

>
>> +  (with-no-warnings (defvar date) (defvar entry))
>
> Why did you need this?

The sexp diary-offset itself requires the date supplied by 
diary-sexp-entry.  The sexp passed to diary-offset will ask for 
both date and entry.  Removed (defvar entry) as this is not needed 
by diary-offset.  After the removel I tested it in org mode and 
org agenda and it works.

>
>> +  (integerp days)
>
> Isn't it better to use an assertion?

Done.  Added a user-error statement like in diary-cyclic.

>
> Thanks.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 06:53:01 GMT) Full text and rfc822 format available.

Message #38 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Eli Zaretskii <eliz <at> gnu.org>, larsi <at> gnus.org, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Thu, 26 Aug 2021 16:52:23 +1000
[Message part 1 (text/plain, inline)]
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>> > That would not work, you would still get warnings about free 
>> > variables.
>>
>> I don't understand.  This code did compile under 
>> dynamic-binding, so
>> what warnings did you have in mind?
>
> You can just try, they look like
>
> | In diary-list-entries-1:
> | diary-lib.el:731:17: Warning: reference to free variable 
> ‘number’
> | diary-lib.el:734:48: Warning: reference to free variable 
> ‘list-only’
>
> I just removed lexical-binding from the header and commented the
> `with-no-warnings' call in `diary-list-entries-1'.

Which command did you use to compile?  I compiled with just `make` 
and there was no warning.

>
>> > This case is a bit special and not directly related to 
>> > lexical-binding
>> > because these variables are just not declared with `defvar' 
>> > (and I think
>> > we don't want to introduce global variables like `date').
>>
>> You are saying this always emitted warnings?
>
> AFAIR there have been problems with these variables and warnings 
> about
> them for a long time, and different measures to handle them.  I 
> think
> (I'm not sure) we had (defvar date) in the file in the past.  If 
> you
> want to have any useful information you must ask Stefan, he was 
> the one
> that worked on that.
>
> Michael.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 06:55:02 GMT) Full text and rfc822 format available.

Message #41 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
Cc: Eli Zaretskii <eliz <at> gnu.org>, bug-gnu-emacs <at> gnu.org, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Thu, 26 Aug 2021 16:54:00 +1000
[Message part 1 (text/plain, inline)]
Sorry, forgot the attach the patch. Here it is.

[0001-Adding-diary-offset-to-diary-lib.el.patch (text/x-patch, inline)]
From 4df9db3eeb3b048579768050ae7bb413fefe9557 Mon Sep 17 00:00:00 2001
From: Yuchen Pei <hi <at> ypei.me>
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

[Message part 3 (text/plain, inline)]
Yuchen Pei <hi <at> ypei.me> writes:

> Thanks for the comments.
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> From: Yuchen Pei <hi <at> ypei.me>
>>> Date: Wed, 25 Aug 2021 13:46:48 +1000
>>> See below my first patch to Emacs.  The copyright assignment 
>>> has already been done BTW.
>>
>> Congrats, and welcome aboard.
>>
>>> Let me know what you think.
>>
>> Some minor comments below.
>>
>>> Would you like me to add some tests?
>>
>> Adding more tests is always welcome, thanks.
>
> All diary sexp tests are in icalendar tests, but diary-offset 
> does not
> easily translate to icalendar events (exporting to icalendar for 
> this
> sexp is rather complicated if not impossible as it applies on 
> top of
> another arbitrary sexp), so I am just adding a simple no-op-like 
> test.
>
>>
>>> Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting
>>> another
>>>  diary-sexp.
>>
>> "git am" uses the Subject for the heading line, and this 
>> Subject is
>> too long for that.  Please consider making it shorter.
>
> Done.
>
>>
>>> 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.
>>
>> The commit log message should include a ChangeLog-style 
>> description
>> of
>> the files and functions where you made the changes.  See 
>> CONTRIBUTE
>> for more details about the format we prefer.
>>
>> Also, please in the next version include the bug number as part 
>> of
>> the
>> log message.
>
> Done.
>
>>
>>> --- 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
>>
>> That line is too long, and will overflow the page width in the
>> printed
>> version of the manual.  Please break it in two.
>
> Done. I made it shorter :)
>
>>
>>> +@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
>>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> This should be in @code, not @samp.  I'd also wrap it in 
>> @w{..}, so
>> that it doesn't get broken between two lines.
>
> Done.
>
>>
>>> +(defun diary-offset (sexp days)
>>> +  "Offsetted diary entry.
>>
>> The first line of a doc string should preferably mention the
>> arguments, but without becoming too long, so it could still fit 
>> on a
>> single line.
>
> Done.
>
>>
>>> +  (with-no-warnings (defvar date) (defvar entry))
>>
>> Why did you need this?
>
> The sexp diary-offset itself requires the date supplied by
> diary-sexp-entry.  The sexp passed to diary-offset will ask for 
> both date and entry.  Removed (defvar entry) as this is not 
> needed by
> diary-offset.  After the removel I tested it in org mode and org
> agenda and it works.
>
>>
>>> +  (integerp days)
>>
>> Isn't it better to use an assertion?
>
> Done.  Added a user-error statement like in diary-cyclic.
>
>>
>> Thanks.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 06:55:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 09:27:02 GMT) Full text and rfc822 format available.

Message #47 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Yuchen Pei <hi <at> ypei.me>
Cc: Eli Zaretskii <eliz <at> gnu.org>, larsi <at> gnus.org, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Thu, 26 Aug 2021 11:26:03 +0200
[Message part 1 (text/plain, inline)]
Yuchen Pei <hi <at> ypei.me> writes:

> > I just removed lexical-binding from the header and commented the
> > `with-no-warnings' call in `diary-list-entries-1'.
>
> Which command did you use to compile?  I compiled with just `make` and
> there was no warning.

B from dired.  But I get these warnings also with "make", just tried now
(using master).

To avoid misunderstandings, this is what I tried:

[0001-Test-warnings-in-diary-lib.patch (text/x-diff, inline)]
From b1f973c7c5ed6591bb7132b9254ee549f44162d2 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen <at> web.de>
Date: Thu, 26 Aug 2021 11:21:14 +0200
Subject: [PATCH] Test warnings in diary-lib

---
 lisp/calendar/diary-lib.el | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el
index f57fe26058..8044768476 100644
--- a/lisp/calendar/diary-lib.el
+++ b/lisp/calendar/diary-lib.el
@@ -1,4 +1,4 @@
-;;; diary-lib.el --- diary functions  -*- lexical-binding:t -*-
+;;; diary-lib.el --- diary functions

 ;; Copyright (C) 1989-1990, 1992-1995, 2001-2021 Free Software
 ;; Foundation, Inc.
@@ -726,7 +726,6 @@ diary-list-entries-1
 MONTHS is an array of month names.  SYMBOL marks diary entries of the type
 in question.  ABSFUNC is a function that converts absolute dates to dates
 of the appropriate type."
-  (with-no-warnings (defvar number) (defvar list-only))
   (let ((gdate original-date))
     (dotimes (_ number)
       (diary-list-entries-2
--
2.30.2

[Message part 3 (text/plain, inline)]

Michael.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Thu, 26 Aug 2021 10:28:02 GMT) Full text and rfc822 format available.

Message #50 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Yuchen Pei <hi <at> ypei.me>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Thu, 26 Aug 2021 12:26:46 +0200
Yuchen Pei <hi <at> ypei.me> writes:

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

Because we are just talking about it: my personal solution for this kind
of problem: I extended the diary language with some date arithmetic
functions and a `date-let' macro, that allows you to solve the same task
like

  (date-let ((date+ date 2))
    SEXP)

An advantage is that this saves one layer of `eval', and it allows the
delta of days to be an expression (that might depend on the DATE).

I also worked on finer grained solutions for the problems of the kind
"every Nth Xday of the month unless it's a day that fulfills some TEST
(e.g., it's a holiday), then use an alternative date.  Useful for
specifying rules for garbage collection (real-life garbage, not Emacs
gc).

I planned to provide these things as a separate library, and I'm not
against what has been supposed here, just wanted to mention an
alternative view on the problem.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Fri, 27 Aug 2021 13:12:02 GMT) Full text and rfc822 format available.

Message #53 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset, a diary-sexp offsetting
 another diary-sexp.
Date: Fri, 27 Aug 2021 23:11:34 +1000
[Message part 1 (text/plain, inline)]
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Yuchen Pei <hi <at> ypei.me> writes:
>
>> A bit like diary-remind, as a diary-sexp rather than reminder, 
>> and
>> also support both positive and negative offsets.
>
> Because we are just talking about it: my personal solution for 
> this kind
> of problem: I extended the diary language with some date 
> arithmetic
> functions and a `date-let' macro, that allows you to solve the 
> same task
> like
>
>   (date-let ((date+ date 2))
>     SEXP)
>
> An advantage is that this saves one layer of `eval', and it 
> allows the
> delta of days to be an expression (that might depend on the 
> DATE).

Interesting - I never thought of defining my own let macro.

>
> I also worked on finer grained solutions for the problems of the 
> kind
> "every Nth Xday of the month unless it's a day that fulfills 
> some TEST
> (e.g., it's a holiday), then use an alternative date.  Useful 
> for
> specifying rules for garbage collection (real-life garbage, not 
> Emacs
> gc).
>
> I planned to provide these things as a separate library, and I'm 
> not
> against what has been supposed here, just wanted to mention an
> alternative view on the problem.

Thanks, I'll be curious to see your library when it gets 
published.

>
> Michael.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Fri, 27 Aug 2021 13:17:01 GMT) Full text and rfc822 format available.

Message #56 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: Eli Zaretskii <eliz <at> gnu.org>, 50195 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Fri, 27 Aug 2021 23:16:06 +1000
[Message part 1 (text/plain, inline)]
I didn't see this message making its way to the bug-gnu-emacs 
mailing list and I haven't heard back after the revision, so I'm 
not sure if the revised patch below has been made available for 
people to see.  Sorry if this is a duplicate.  Let me know what 
you think.
Yuchen Pei <hi <at> ypei.me> writes:

> Sorry, forgot the attach the patch. Here it is.
>
> From 4df9db3eeb3b048579768050ae7bb413fefe9557 Mon Sep 17 
> 00:00:00 2001
> From: Yuchen Pei <hi <at> ypei.me>
> 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
>
>
> Yuchen Pei <hi <at> ypei.me> writes:
>
>> Thanks for the comments.
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>>
>>>> From: Yuchen Pei <hi <at> ypei.me>
>>>> Date: Wed, 25 Aug 2021 13:46:48 +1000
>>>> See below my first patch to Emacs.  The copyright assignment 
>>>> has
>>>> already been done BTW.
>>>
>>> Congrats, and welcome aboard.
>>>
>>>> Let me know what you think.
>>>
>>> Some minor comments below.
>>>
>>>> Would you like me to add some tests?
>>>
>>> Adding more tests is always welcome, thanks.
>>
>> All diary sexp tests are in icalendar tests, but diary-offset 
>> does
>> not
>> easily translate to icalendar events (exporting to icalendar 
>> for
>> this
>> sexp is rather complicated if not impossible as it applies on 
>> top of
>> another arbitrary sexp), so I am just adding a simple 
>> no-op-like
>> test.
>>
>>>
>>>> Subject: [PATCH] Adding diary-offset, a diary-sexp offsetting
>>>> another
>>>>  diary-sexp.
>>>
>>> "git am" uses the Subject for the heading line, and this 
>>> Subject is
>>> too long for that.  Please consider making it shorter.
>>
>> Done.
>>
>>>
>>>> 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.
>>>
>>> The commit log message should include a ChangeLog-style 
>>> description
>>> of
>>> the files and functions where you made the changes.  See 
>>> CONTRIBUTE
>>> for more details about the format we prefer.
>>>
>>> Also, please in the next version include the bug number as 
>>> part of
>>> the
>>> log message.
>>
>> Done.
>>
>>>
>>>> --- 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
>>>
>>> That line is too long, and will overflow the page width in the
>>> printed
>>> version of the manual.  Please break it in two.
>>
>> Done. I made it shorter :)
>>
>>>
>>>> +@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
>>>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>> This should be in @code, not @samp.  I'd also wrap it in 
>>> @w{..}, so
>>> that it doesn't get broken between two lines.
>>
>> Done.
>>
>>>
>>>> +(defun diary-offset (sexp days)
>>>> +  "Offsetted diary entry.
>>>
>>> The first line of a doc string should preferably mention the
>>> arguments, but without becoming too long, so it could still 
>>> fit on
>>> a
>>> single line.
>>
>> Done.
>>
>>>
>>>> +  (with-no-warnings (defvar date) (defvar entry))
>>>
>>> Why did you need this?
>>
>> The sexp diary-offset itself requires the date supplied by
>> diary-sexp-entry.  The sexp passed to diary-offset will ask for 
>> both
>> date and entry.  Removed (defvar entry) as this is not needed 
>> by
>> diary-offset.  After the removel I tested it in org mode and 
>> org
>> agenda and it works.
>>
>>>
>>>> +  (integerp days)
>>>
>>> Isn't it better to use an assertion?
>>
>> Done.  Added a user-error statement like in diary-cyclic.
>>
>>>
>>> Thanks.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Fri, 27 Aug 2021 13:17:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Fri, 03 Sep 2021 22:41:02 GMT) Full text and rfc822 format available.

Message #62 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: 50195 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Cc: eliz <at> gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Sat, 04 Sep 2021 08:40:07 +1000
[Message part 1 (text/plain, inline)]
Yuchen Pei <hi <at> ypei.me> writes:

> I didn't see this message making its way to the bug-gnu-emacs 
> mailing
> list and I haven't heard back after the revision, so I'm not 
> sure if
> the revised patch below has been made available for people to 
> see.
> Sorry if this is a duplicate.  Let me know what you think.

Any updates?

> Yuchen Pei <hi <at> ypei.me> writes:
>
>> Sorry, forgot the attach the patch. Here it is.
>>
>> From 4df9db3eeb3b048579768050ae7bb413fefe9557 Mon Sep 17 
>> 00:00:00
>> 2001
>> From: Yuchen Pei <hi <at> ypei.me>
>> 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
>>
>>
>> Yuchen Pei <hi <at> ypei.me> writes:
>>
>>> Thanks for the comments.
>>> Eli Zaretskii <eliz <at> gnu.org> writes:
>>>
>>>>> From: Yuchen Pei <hi <at> ypei.me>
>>>>> Date: Wed, 25 Aug 2021 13:46:48 +1000
>>>>> See below my first patch to Emacs.  The copyright assignment 
>>>>> has
>>>>> already been done BTW.
>>>>
>>>> Congrats, and welcome aboard.
>>>>
>>>>> Let me know what you think.
>>>>
>>>> Some minor comments below.
>>>>
>>>>> Would you like me to add some tests?
>>>>
>>>> Adding more tests is always welcome, thanks.
>>>
>>> All diary sexp tests are in icalendar tests, but diary-offset 
>>> does
>>> not
>>> easily translate to icalendar events (exporting to icalendar 
>>> for
>>> this
>>> sexp is rather complicated if not impossible as it applies on 
>>> top
>>> of
>>> another arbitrary sexp), so I am just adding a simple 
>>> no-op-like
>>> test.
>>>
>>>>
>>>>> Subject: [PATCH] Adding diary-offset, a diary-sexp 
>>>>> offsetting
>>>>> another
>>>>>  diary-sexp.
>>>>
>>>> "git am" uses the Subject for the heading line, and this 
>>>> Subject
>>>> is
>>>> too long for that.  Please consider making it shorter.
>>>
>>> Done.
>>>
>>>>
>>>>> 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.
>>>>
>>>> The commit log message should include a ChangeLog-style
>>>> description
>>>> of
>>>> the files and functions where you made the changes.  See
>>>> CONTRIBUTE
>>>> for more details about the format we prefer.
>>>>
>>>> Also, please in the next version include the bug number as 
>>>> part of
>>>> the
>>>> log message.
>>>
>>> Done.
>>>
>>>>
>>>>> --- 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
>>>>
>>>> That line is too long, and will overflow the page width in 
>>>> the
>>>> printed
>>>> version of the manual.  Please break it in two.
>>>
>>> Done. I made it shorter :)
>>>
>>>>
>>>>> +@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
>>>>    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>>>> This should be in @code, not @samp.  I'd also wrap it in 
>>>> @w{..},
>>>> so
>>>> that it doesn't get broken between two lines.
>>>
>>> Done.
>>>
>>>>
>>>>> +(defun diary-offset (sexp days)
>>>>> +  "Offsetted diary entry.
>>>>
>>>> The first line of a doc string should preferably mention the
>>>> arguments, but without becoming too long, so it could still 
>>>> fit on
>>>> a
>>>> single line.
>>>
>>> Done.
>>>
>>>>
>>>>> +  (with-no-warnings (defvar date) (defvar entry))
>>>>
>>>> Why did you need this?
>>>
>>> The sexp diary-offset itself requires the date supplied by
>>> diary-sexp-entry.  The sexp passed to diary-offset will ask 
>>> for
>>> both
>>> date and entry.  Removed (defvar entry) as this is not needed 
>>> by
>>> diary-offset.  After the removel I tested it in org mode and 
>>> org
>>> agenda and it works.
>>>
>>>>
>>>>> +  (integerp days)
>>>>
>>>> Isn't it better to use an assertion?
>>>
>>> Done.  Added a user-error statement like in diary-cyclic.
>>>
>>>>
>>>> Thanks.


-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Fri, 03 Sep 2021 22:41:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Sat, 04 Sep 2021 06:16:02 GMT) Full text and rfc822 format available.

Message #68 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuchen Pei <hi <at> ypei.me>
Cc: 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Sat, 04 Sep 2021 09:15:14 +0300
> From: Yuchen Pei <hi <at> ypei.me>
> Cc: eliz <at> gnu.org
> Date: Sat, 04 Sep 2021 08:40:07 +1000
> 
> Yuchen Pei <hi <at> ypei.me> writes:
> 
> > I didn't see this message making its way to the bug-gnu-emacs
> > mailing list and I haven't heard back after the revision, so I'm
> > not sure if the revised patch below has been made available for
> > people to see.  Sorry if this is a duplicate.  Let me know what
> > you think.
> 
> Any updates?

I have no further comments.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Sat, 04 Sep 2021 06:30:02 GMT) Full text and rfc822 format available.

Message #71 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Yuchen Pei <hi <at> ypei.me>, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Sat, 04 Sep 2021 08:29:25 +0200
Eli Zaretskii <eliz <at> gnu.org> writes:

>> > I didn't see this message making its way to the bug-gnu-emacs
>> > mailing list and I haven't heard back after the revision, so I'm
>> > not sure if the revised patch below has been made available for
>> > people to see.  Sorry if this is a duplicate.  Let me know what
>> > you think.
>> 
>> Any updates?
>
> I have no further comments.

Looks good to me, so I've pushed it to Emacs 28 (with some trivial
changes).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug marked as fixed in version 28.1, send any further explanations to 50195 <at> debbugs.gnu.org and Yuchen Pei <hi <at> ypei.me> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 04 Sep 2021 06:30:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50195; Package emacs. (Sat, 04 Sep 2021 07:22:01 GMT) Full text and rfc822 format available.

Message #76 received at 50195 <at> debbugs.gnu.org (full text, mbox):

From: Yuchen Pei <hi <at> ypei.me>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 50195 <at> debbugs.gnu.org
Subject: Re: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Sat, 04 Sep 2021 17:21:22 +1000
[Message part 1 (text/plain, inline)]
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> > I didn't see this message making its way to the 
>>> > bug-gnu-emacs
>>> > mailing list and I haven't heard back after the revision, so 
>>> > I'm
>>> > not sure if the revised patch below has been made available 
>>> > for
>>> > people to see.  Sorry if this is a duplicate.  Let me know 
>>> > what
>>> > you think.
>>> 
>>> Any updates?
>>
>> I have no further comments.
>
> Looks good to me, so I've pushed it to Emacs 28 (with some 
> trivial
> changes).

Cool, thanks!

-- 
Best,
Yuchen

PGP Key: 47F9 D050 1E11 8879 9040  4941 2126 7E93 EF86 DFD0
          <https://ypei.me/assets/ypei-pubkey.txt>
[signature.asc (application/pgp-signature, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 02 Oct 2021 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 178 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.