From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] Date: Mon, 17 Aug 2015 12:42:49 -0400 Message-ID: <87lhd97to6.fsf@pierrot.dokosmarshall.org> References: <87a8ufdqte.fsf@free.fr> <871tf89qh8.fsf@fastmail.fm> <87wpwzlmpn.fsf@free.fr> <87lhdftjzy.fsf@fastmail.fm> <871tf690lg.fsf@pierrot.dokosmarshall.org> <878u9ehris.fsf@fastmail.fm> <87vbcg76lq.fsf@free.fr> <87pp2n6t7k.fsf_-_@pierrot.dokosmarshall.org> <87lhda6zrg.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRNVB-0001i4-Sq for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 12:43:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRNV7-0002Cu-RB for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 12:43:13 -0400 Received: from plane.gmane.org ([80.91.229.3]:49794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRNV7-0002Ce-Av for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 12:43:09 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZRNV2-0001Qa-R2 for emacs-orgmode@gnu.org; Mon, 17 Aug 2015 18:43:05 +0200 Received: from pool-108-20-41-232.bstnma.fios.verizon.net ([108.20.41.232]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Aug 2015 18:43:04 +0200 Received: from ndokos by pool-108-20-41-232.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Aug 2015 18:43:04 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Nicolas Goaziou writes: > Hello, > > Nick Dokos writes: > >> Here's a patch to add a new function to org-bbdb.el that provides early >> warning for upcoming anniversaries; it also adds some documentation to >> org.texi. > > Thank you. Some comments follow. > Thanks for the comments. Revised patch attached. > >> + (apply 'nconc (mapcar gen-anniversaries dates))))) > > #'nconc (there is also `cl-mapcan'). > I did a mapcan originally and saw that it was an alias for cl-mapcan in cl-extras.el and that got me scared: I vaguely recalled some rules about using cl-* stuff, but I don't really remember the rules any more. For future reference, are they written down somewhere? Also, does it matter if I use the alias "mapcan" instead of "cl-mapcan"? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-early-warning-anniversaries-in-agenda.patch Content-Description: Allow early-warning anniversaries in agenda. >From f90ab3346f0b49b7397d1b963359f14a48a019f1 Mon Sep 17 00:00:00 2001 From: Nick Dokos Date: Sun, 16 Aug 2015 12:22:55 -0400 Subject: [PATCH] Allow early-warning anniversaries in agenda. * lisp/org-bbdb.el (org-bbdb-anniversaries-future, org-bbdb-date-list): New functions. * doc/org.texi: Document the usage of `org-bbdb-anniversaries-future'. Feature requested by Julien Cubizolles: http://thread.gmane.org/gmane.emacs.orgmode/99344 --- doc/org.texi | 14 ++++++++++++++ lisp/org-bbdb.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/doc/org.texi b/doc/org.texi index b23be03..927ecbd 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -8046,6 +8046,20 @@ hash with anniversaries. However, from then on things will be very fast---much faster in fact than a long list of @samp{%%(diary-anniversary)} entries in an Org or Diary file. +If you would like to see upcoming anniversaries with a bit of forewarning, +you can use the following instead: + +@example +* Anniversaries + :PROPERTIES: + :CATEGORY: Anniv + :END: +%%(org-bbdb-anniversaries-future 3) +@end example + +That will give you three days' warning: on the anniversary date itself and the +two days prior. The argument is optional: if omitted, it defaults to 7. + @subsubheading Appointment reminders @cindex @file{appt.el} @cindex appointment reminders diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el index c489385..e03cda9 100644 --- a/lisp/org-bbdb.el +++ b/lisp/org-bbdb.el @@ -397,6 +397,55 @@ This is used by Org to re-create the anniversary hash table." )) text)) +;;; Return list of anniversaries for today and the next n-1 (default: n=7) days. +;;; This is meant to be used in an org file instead of org-bbdb-anniversaries: +;;; +;;; %%(org-bbdb-anniversaries-future) +;;; +;;; or +;;; +;;; %%(org-bbdb-anniversaries-future 3) +;;; +;;; to override the 7-day default. + +(defun org-bbdb-date-list (date n) + "Return a list of dates in (m d y) format from the given 'date' to n-1 days hence." + (let ((abs (calendar-absolute-from-gregorian date)) + ret) + (dotimes (i n (nreverse ret)) + (push (calendar-gregorian-from-absolute (+ abs i)) ret)))) + +;;;###autoload +(defun org-bbdb-anniversaries-future (&optional n) + "Return list of anniversaries for today and the next n-1 days (default n=7)." + (let ((n (or n 7))) + (when (<= n 0) + (error "The (optional) argument of `org-bbdb-anniversaries-future' must be positive")) + (let ( + ;; List of relevant dates. + (dates (org-bbdb-date-list date n)) + ;; Function to annotate text of each element of l with the anniversary date d. + (annotate-descriptions + (lambda (d l) + (mapcar (lambda (x) + ;; The assumption here is that x is a bbdb link of the form + ;; [[bbdb:name][description]]. + ;; This function rather arbitrarily modifies the description + ;; by adding the date to it in a fixed format. + (string-match "]]" x) + (replace-match (format " -- %d-%02d-%02d\\&" (third d) (first d) (second d)) + nil nil x)) + l)))) + ;; Map a function that generates anniversaries for each date over the dates + ;; and nconc the results into a single list. + (cl-mapcan (lambda (d) + (let ((date d)) + ;; Rebind 'date' so that org-bbdb-anniversaries will be + ;; fooled into giving us the list for the given date + ;; and then annotate the descriptions for that date. + (funcall annotate-descriptions d (org-bbdb-anniversaries)))) + dates)))) + (defun org-bbdb-complete-link () "Read a bbdb link with name completion." (require 'bbdb-com) -- 2.4.3 --=-=-= Content-Type: text/plain Thanks! -- Nick --=-=-=--