From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuchen Pei Newsgroups: gmane.emacs.bugs Subject: bug#50195: [PATCH] Adding diary-offset to diary-lib.el Date: Fri, 27 Aug 2021 23:16:06 +1000 Message-ID: <87fsuv9gfd.fsf@ypei.me> References: <87fsuychjr.fsf@ypei.me> <83mtp5vizs.fsf@gnu.org> <87mtp4bszq.fsf@ypei.me> <87h7fcbss7.fsf@ypei.me> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21807"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 27.2 To: eliz@gnu.org, 50195@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 27 15:17:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mJbjN-0005NX-Gg for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Aug 2021 15:17:14 +0200 Original-Received: from localhost ([::1]:60174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJbjM-0005P8-45 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 27 Aug 2021 09:17:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJbjC-0005Oe-8X for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 09:17:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJbjC-0005UB-0s for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 09:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mJbjB-00085m-T6 for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 09:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuchen Pei Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 27 Aug 2021 13:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50195 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Eli Zaretskii , 50195@debbugs.gnu.org, bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.163007018731056 (code B ref -1); Fri, 27 Aug 2021 13:17:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Aug 2021 13:16:27 +0000 Original-Received: from localhost ([127.0.0.1]:51442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJbiZ-00084i-1t for submit@debbugs.gnu.org; Fri, 27 Aug 2021 09:16:27 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:35314) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJbiS-00084R-QM for submit@debbugs.gnu.org; Fri, 27 Aug 2021 09:16:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJbiS-0005KQ-FG for bug-gnu-emacs@gnu.org; Fri, 27 Aug 2021 09:16:16 -0400 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:45445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJbiQ-00052L-3Z; Fri, 27 Aug 2021 09:16:16 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 41CB632007CF; Fri, 27 Aug 2021 09:16:12 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Fri, 27 Aug 2021 09:16:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ypei.me; h= references:from:to:subject:in-reply-to:date:message-id :mime-version:content-type; s=fm2; bh=q/zC+1zY5zndU3PCzSgwLH9Oul qvgB2i5jDQeeGjSFY=; b=UzKKCXczEUhJX47omwjkwlwwyrYHnZmK8LqdxzSaYv TYpFnU6r/OlHoGX1SnNbt/0Jc29sbo7GYhh9tNYdx0FAXHsiPD3RR9NnvdvL6fpa xILUstlTq9MOqw99L/7yEThUGnrpl96e2CvrzTk4pbWJDQhnOPqus5DTLBcWEOOz LggO3C8vbuVFyQMICbBAIS8nh1jMhe5YvVUpQN5FPXLie08OMKo0NPbrAU0idt+N b/tzvzUa6HAqNnt38ZScKza1o5RfmyFyDKTkPrneFQXpRw+MRzFzwL6SLnz2YxX7 oyo5cd4DUcA+3lQHhsqT4eqL5CVdDukAFtE/oUc1awJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=q/zC+1 zY5zndU3PCzSgwLH9OulqvgB2i5jDQeeGjSFY=; b=MxAtbZkvlJkt4gImXJKY5K FWKtRlQavfYM64uTYetnbgCGdOiBrXoK6Xo7u1X6uwLulB45W59RUmyUkpsmk39N XG//x+Bss46CJF86AVVV+oep35UHmGHl35J+U70BPrqb7vs7EEk9dVwlMrelrK3/ yizUg0Sj+J5v0rq8fJLkkhfsdGA8z66/p4EsP663avNqzMQMSDrgPFQNSWnWS71c NCxKRz7emyBuvBqlGuMRVXdApsqY+Y3XRx00lewwkr+lu+BxVwfCsvuqDR0EJ9ry 6OAYWkWezGKtSBFpXkyaet2aI2rIxuqPXyGxhXMcEW19KBacn5fZlythPzwCQ56w == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddufedgiedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvufgjfffkgggtsehgtderredtredtnecuhfhrohhmpegjuhgthhgv nhcurfgvihcuoehhiheshihpvghirdhmvgeqnecuggftrfgrthhtvghrnhepkedtfffhle eigfehueevieeuueekvdfgveegheeiudeuffdvgfejleeijeevheetnecuffhomhgrihhn peihphgvihdrmhgvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhephhhiseihphgvihdrmhgv X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Aug 2021 09:16:09 -0400 (EDT) In-reply-to: <87h7fcbss7.fsf@ypei.me> Received-SPF: pass client-ip=64.147.123.21; envelope-from=hi@ypei.me; helo=wout5-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212812 Archived-At: --=-=-= Content-Type: text/plain; format=flowed 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 writes: > Sorry, forgot the attach the patch. Here it is. > > 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 > > > Yuchen Pei writes: > >> Thanks for the comments. >> Eli Zaretskii writes: >> >>>> From: Yuchen Pei >>>> 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 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iIEEARYIACkWIQRH+dBQHhGIeZBASUEhJn6T74bf0AUCYSjllgscaGlAeXBlaS5t ZQAKCRAhJn6T74bf0Pv3AP9tyqARflhzswCeqpyqL7s2NmOOdXi2BVZDbVZLlre6 3gEA3ODvM5iFE+/SdPySpiRwoG3YOL9WApm+Zx4fCh951Aw= =yRLQ -----END PGP SIGNATURE----- --=-=-=--