all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuchen Pei <hi@ypei.me>
Cc: 50195@debbugs.gnu.org
Subject: bug#50195: [PATCH] Adding diary-offset to diary-lib.el
Date: Thu, 26 Aug 2021 16:54:00 +1000	[thread overview]
Message-ID: <87h7fcbss7.fsf@ypei.me> (raw)
In-Reply-To: <87mtp4bszq.fsf@ypei.me>


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

Sorry, forgot the attach the patch. Here it is.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Adding-diary-offset-to-diary-lib.el.patch --]
[-- Type: text/x-patch, Size: 3989 bytes --]

From 4df9db3eeb3b048579768050ae7bb413fefe9557 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 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


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


Yuchen Pei <hi@ypei.me> writes:

> Thanks for the comments.
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Yuchen Pei <hi@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>

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

  reply	other threads:[~2021-08-26  6:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7fcbss7.fsf@ypei.me \
    --to=hi@ypei.me \
    --cc=50195@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.