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: Thu, 26 Aug 2021 16:54:00 +1000 Message-ID: <87h7fcbss7.fsf@ypei.me> References: <87fsuychjr.fsf@ypei.me> <83mtp5vizs.fsf@gnu.org> <87mtp4bszq.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="8945"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 27.2 Cc: 50195@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 26 08:55:17 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 1mJ9ID-000254-8Y for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Aug 2021 08:55:17 +0200 Original-Received: from localhost ([::1]:51902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJ9IB-0008Qd-FK for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 26 Aug 2021 02:55:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJ9Hy-0008QO-C3 for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mJ9Hy-0000fV-4N for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mJ9Hy-0000nG-3y for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Yuchen Pei Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Aug 2021 06:55:02 +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-Cc: Eli Zaretskii , bug-gnu-emacs@gnu.org, 50195@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16299608522973 (code B ref -1); Thu, 26 Aug 2021 06:55:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Aug 2021 06:54:12 +0000 Original-Received: from localhost ([127.0.0.1]:48241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJ9H9-0000ls-Hj for submit@debbugs.gnu.org; Thu, 26 Aug 2021 02:54:12 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55296) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mJ9H8-0000lk-95 for submit@debbugs.gnu.org; Thu, 26 Aug 2021 02:54:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJ9H7-0008Nk-VO for bug-gnu-emacs@gnu.org; Thu, 26 Aug 2021 02:54:09 -0400 Original-Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:49755) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJ9H5-0008L7-RD; Thu, 26 Aug 2021 02:54:09 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id B39BD3200302; Thu, 26 Aug 2021 02:54:05 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 26 Aug 2021 02:54:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ypei.me; h= references:from:cc:subject:in-reply-to:date:message-id :mime-version:content-type; s=fm2; bh=HqsXuDJqQDzLbSLNnJTAYzDx0P qwtvDdq0WVCHDEwWk=; b=VfJ5F+GJ3GSKBZ2Xs1mvXvO8szJSD6CLyBAKTJCGAA jisUwOxt1FQeiOS0z5Zky/xSQmxLaNvjWztZcZO7fHEe45HzJ9zl2VLIvp4I8Eyr weEfUq0O3rclFWFODhay2Fqg2X6Vu7ZnmF4ERrgHxneKisbs5k6CCyboVmpFxpY3 XDSvTwnc+07/PUUS99qfWRwM+CvuarBrsXmm57daPq12wyZ/JAgGc0iSmOoCqfiz aKGeRNmk38fCYrfx6loElpHUqfixh2SiVADACbPVG6B2wOjHoH/YdJnIwk13xq/q NuaFcbcWSTdvQgpopAjFGPBiw9CKuNleNC4sdrg9hUNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=HqsXuD JqQDzLbSLNnJTAYzDx0PqwtvDdq0WVCHDEwWk=; b=cQQI+ZW2g9R4JuihBoJpUp FUOtcGt+zfnno3froYWXwL4YK5WRnSyE+pNE+cEtPxmS2AzbPKHPa9/7XZ+PZwFv Byt3GOdEfzm3hfOge1dJ4mj1Ck5xba4gjHTCvZwLBhB64ZG1WouXTZh2iGu4W7bI 0J2cNy1JeRWiOM03OzFKcVweJhdtZdBWU/Ln/et6p7XwNa02WD8gJmv5ANSog2a0 ls5SVpyiqd0/j+PZkqECR8vZcw3NFqti+Wos+qfD9xJ56Iu5WiWfMfxhG42pt442 orhnpVE3dyGXpLE+XxLPS5CfDOIX9ePKuxSwh4lPmhRRcYVYggXLiksGAUNIv3kQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddutddguddufecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enmhhishhsihhnghcuvffquchfihgvlhguucdlfedtmdenucfjughrpehffgfhufgjfffk gggtsehgtderredtredtnecuhfhrohhmpegjuhgthhgvnhcurfgvihcuoehhiheshihpvg hirdhmvgeqnecuggftrfgrthhtvghrnhepieduhfeivedvtdfhfeelgeelteeltddtheev heejtdejgfetgeeuueeuudehveevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhephhhiseihphgvihdrmhgv X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Aug 2021 02:54:03 -0400 (EDT) In-reply-to: <87mtp4bszq.fsf@ypei.me> Received-SPF: pass client-ip=64.147.123.25; envelope-from=hi@ypei.me; helo=wout2-smtp.messagingengine.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.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, MISSING_HEADERS=1.021, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no 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:212692 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; format=flowed Sorry, forgot the attach the patch. Here it is. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Adding-diary-offset-to-diary-lib.el.patch Content-Transfer-Encoding: quoted-printable From=204df9db3eeb3b048579768050ae7bb413fefe9557 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. =2D-- 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 =2D-- 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. =20 +@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 =2D-- 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. =20 ++++ +*** 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 =20 --- diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index f57fe26058..f71392b97f 100644 =2D-- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -2014,6 +2014,17 @@ diary-cyclic (and (>=3D diff 0) (zerop (% diff n)) (cons mark (format entry cycle (diary-ordinal-suffix cycle)))))) =20 +;; 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 entr= y." (with-no-warnings (defvar date)) diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/ica= lendar-tests.el index 6973f7e5c9..de2a891758 100644 =2D-- 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)") =20 =20 + (icalendar-tests--test-export + nil + nil + "%%(diary-offset '(diary-float t 3 4) 1) asdf" + nil) + + ;; FIXME! =20 ;; export 2004-10-28 monthly, weekly entries =2D-=20 2.33.0 --=-=-= Content-Type: text/plain; format=flowed 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+dBQHhGIeZBASUEhJn6T74bf0AUCYSc6iAscaGlAeXBlaS5t ZQAKCRAhJn6T74bf0NNcAP0YyrXdx/ZCGNdbmVwKXT2z61A75dwJmWYP42xwAVL6 WgD/QcqsPuWlvvfCY0cwdZ6P9Gopi8XMKOB2GLb9U0s+aQE= =JvQg -----END PGP SIGNATURE----- --==-=-=--