emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-bbdb-birthday reminder
@ 2015-07-29 13:41 Julien Cubizolles
  2015-08-12 20:55 ` Matt Lundin
  0 siblings, 1 reply; 18+ messages in thread
From: Julien Cubizolles @ 2015-07-29 13:41 UTC (permalink / raw)
  To: emacs-orgmode

I'm using org-bbdb-anniversaries to use the bbdb-anniversaries. At the
moment, it only displays the birthdays of the day. How can I generate a
reminder for a few days before the actual birthday ?

Julien.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-07-29 13:41 org-bbdb-birthday reminder Julien Cubizolles
@ 2015-08-12 20:55 ` Matt Lundin
  2015-08-13  1:36   ` Nick Dokos
  2015-08-13  6:35   ` Julien Cubizolles
  0 siblings, 2 replies; 18+ messages in thread
From: Matt Lundin @ 2015-08-12 20:55 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

Julien Cubizolles <j.cubizolles@free.fr> writes:

> I'm using org-bbdb-anniversaries to use the bbdb-anniversaries. At the
> moment, it only displays the birthdays of the day. How can I generate a
> reminder for a few days before the actual birthday ?

This is not possible at the moment with bbdb-anniversaries. 

For advanced reminders of birthdays and the like, you could use a
diary-sexp:

%%(diary-remind '(org-anniversary 1996 8 20) -7) Someone turns %s

Best,
Matt

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-12 20:55 ` Matt Lundin
@ 2015-08-13  1:36   ` Nick Dokos
  2015-08-13  6:35   ` Julien Cubizolles
  1 sibling, 0 replies; 18+ messages in thread
From: Nick Dokos @ 2015-08-13  1:36 UTC (permalink / raw)
  To: emacs-orgmode

Matt Lundin <mdl@imapmail.org> writes:

> Julien Cubizolles <j.cubizolles@free.fr> writes:
>
>> I'm using org-bbdb-anniversaries to use the bbdb-anniversaries. At the
>> moment, it only displays the birthdays of the day. How can I generate a
>> reminder for a few days before the actual birthday ?
>
> This is not possible at the moment with bbdb-anniversaries. 
>
> For advanced reminders of birthdays and the like, you could use a
> diary-sexp:
>
> %%(diary-remind '(org-anniversary 1996 8 20) -7) Someone turns %s
>

org-bbdb-anniversaries depends on having a dynamically bound variable
called 'date' in the format (month day year) and produces the list
of anniversaries for that particular date. Instead of doing

%%(org-bbdb-anniversaries)

you could do

%%(let ((date '(9 1 2015))) (org-bbdb-anniversaries))

which produces the anniversaries for 2015-09-01,
no matter what the current date is. That's silly of
course but you could take advantage of it as follows:
you could define your own function and do

%%(my-anniversaries)

org-bbdb-anniversaries produces a list of strings, one string for each
anniversary falling on the given date. So your function
would have to calculate the list of dates that it wants anniversaries
for, and for each date d in that list calculate the list of
anniversaries for that date:

   (let ((date d)) (org-bbdb-anniversaries))

probably annotating each string in the resulting list with the date of
the anniversary and accumulating it in a single list, which it would
then return.

Obviously lots of details are missing - nevertheless, I hope it helps
a bit.

Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-12 20:55 ` Matt Lundin
  2015-08-13  1:36   ` Nick Dokos
@ 2015-08-13  6:35   ` Julien Cubizolles
  2015-08-13 13:07     ` Matt Lundin
  1 sibling, 1 reply; 18+ messages in thread
From: Julien Cubizolles @ 2015-08-13  6:35 UTC (permalink / raw)
  To: Matt Lundin; +Cc: emacs-orgmode

Matt Lundin <mdl@imapmail.org> writes:


> This is not possible at the moment with bbdb-anniversaries. 

I thought someone would have felt the need to have this list of upcoming
birthdays. I'm guess not so many of you always end up rushing to buy
presents in the last days the way I dO.

> For advanced reminders of birthdays and the like, you could use a
> diary-sexp:
>
> %%(diary-remind '(org-anniversary 1996 8 20) -7) Someone turns %s

I'll give it a try thanks, but you need one line per birthday you want
to be reminded of. It would be much easier to have just a field in bbdb
to select these contatcs.

Julien.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-13  6:35   ` Julien Cubizolles
@ 2015-08-13 13:07     ` Matt Lundin
  2015-08-14  0:26       ` Nick Dokos
  0 siblings, 1 reply; 18+ messages in thread
From: Matt Lundin @ 2015-08-13 13:07 UTC (permalink / raw)
  To: Julien Cubizolles; +Cc: emacs-orgmode

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Matt Lundin <mdl@imapmail.org> writes:
>
>> For advanced reminders of birthdays and the like, you could use a
>> diary-sexp:
>>
>> %%(diary-remind '(org-anniversary 1996 8 20) -7) Someone turns %s
>
> I'll give it a try thanks, but you need one line per birthday you want
> to be reminded of. It would be much easier to have just a field in bbdb
> to select these contatcs.

You could use a "calendar" agenda to look for upcoming birthdays
generated by org-bbdb-anniversaries:

--8<---------------cut here---------------start------------->8---
(add-to-list 'org-agenda-custom-commands
             '("c" "Calendar" agenda ""
                ((org-agenda-span 'month) 
                 (org-agenda-time-grid nil) ;;
                 (org-agenda-entry-types '(:timestamp :sexp)))))
--8<---------------cut here---------------end--------------->8---

If (for speed's sake) you wanted to limit the calendar just to
birthdays, you could create an org file with a single headline:

--8<---------------cut here---------------start------------->8---
* Birthdays
%%(org-bbdb-anniversaries)
--8<---------------cut here---------------end--------------->8---

...and then add an org-agenda-files line that points just to that
minimal file to the custom command above.

Matt

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-13 13:07     ` Matt Lundin
@ 2015-08-14  0:26       ` Nick Dokos
  2015-08-14 14:30         ` Matt Lundin
  0 siblings, 1 reply; 18+ messages in thread
From: Nick Dokos @ 2015-08-14  0:26 UTC (permalink / raw)
  To: emacs-orgmode

Here's a quick implementation of the method I described earlier
in the thread:

--8<---------------cut here---------------start------------->8---
;;; Return list of anniversaries for today and the next n (default: 7) days.
;;; This is meant to be used in an org file instead of org-bbdb-anniversaries:
;;;
;;; %%(my-anniversaries)
;;;
;;; or
;;; %%(my-anniversaries 3)
;;;
;;; to override the 7-day default.

(defun date-list (date &optional n)
  "Return a list of dates in (m d y) format from 'date' to n days hence."
  (if (not n) (setq n 7))
  (let ((abs (calendar-absolute-from-gregorian date))
        (i 0)
        ret)
    (while (<= i n)
      (setq ret (cons (calendar-gregorian-from-absolute (+ abs i)) ret))
      (setq i (1+ i)))
    (reverse ret)))

(defun annotate-link-with-date (d l)
  "Annotate text of each element of l with the anniversary date.
  The assumption is that the text is a bbdb link  of the form
  [[bbdb:name][Description]] and the annotation
  is added to the description."
  (let ((f (lambda (x)
             (string-match "]]" x)
             (replace-match (format " -- %d-%d-%d\\&" (caddr d) (car d) (cadr d)) nil nil x))))
    (mapcar f l)))

(defun my-anniversaries (&optional n)
  "Return list of anniversaries for today and the next n days (default 7).
'date' is dynamically bound."
  (let ((dates (date-list date n))
        (f (lambda (d) (let ((date d)) (annotate-link-with-date d (org-bbdb-anniversaries))))))
    (delete nil (mapcan f dates))))
    
--8<---------------cut here---------------end--------------->8---

Lightly tested. Hope it helps

-- 
Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-14  0:26       ` Nick Dokos
@ 2015-08-14 14:30         ` Matt Lundin
  2015-08-15 18:24           ` Julien Cubizolles
  2015-08-16 13:46           ` org-bbdb-birthday reminder Bastien Guerry
  0 siblings, 2 replies; 18+ messages in thread
From: Matt Lundin @ 2015-08-14 14:30 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Nick Dokos <ndokos@gmail.com> writes:

> Here's a quick implementation of the method I described earlier
> in the thread:

This works great. Thanks! Perhaps we could integrate something like this
into org-bbdb.el...

Matt

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-14 14:30         ` Matt Lundin
@ 2015-08-15 18:24           ` Julien Cubizolles
  2015-08-16 17:25             ` [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] Nick Dokos
  2015-08-16 13:46           ` org-bbdb-birthday reminder Bastien Guerry
  1 sibling, 1 reply; 18+ messages in thread
From: Julien Cubizolles @ 2015-08-15 18:24 UTC (permalink / raw)
  To: Matt Lundin; +Cc: Nick Dokos, emacs-orgmode

Matt Lundin <mdl@imapmail.org> writes:

> Nick Dokos <ndokos@gmail.com> writes:
>
>> Here's a quick implementation of the method I described earlier
>> in the thread:
>
> This works great. Thanks! Perhaps we could integrate something like this
> into org-bbdb.el...

I second that. It's exactly what I was looking for.

Thanks,

Julien.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: org-bbdb-birthday reminder
  2015-08-14 14:30         ` Matt Lundin
  2015-08-15 18:24           ` Julien Cubizolles
@ 2015-08-16 13:46           ` Bastien Guerry
  1 sibling, 0 replies; 18+ messages in thread
From: Bastien Guerry @ 2015-08-16 13:46 UTC (permalink / raw)
  To: Matt Lundin; +Cc: Nick Dokos, emacs-orgmode

Hi Matt and Nick,

Matt Lundin <mdl@imapmail.org> writes:

> Nick Dokos <ndokos@gmail.com> writes:
>
>> Here's a quick implementation of the method I described earlier
>> in the thread:
>
> This works great. Thanks! Perhaps we could integrate something like this
> into org-bbdb.el...

Agreed.  Nick, would you like to provide a patch against master?

Thanks in advance!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-15 18:24           ` Julien Cubizolles
@ 2015-08-16 17:25             ` Nick Dokos
  2015-08-17  9:16               ` Nicolas Goaziou
  0 siblings, 1 reply; 18+ messages in thread
From: Nick Dokos @ 2015-08-16 17:25 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]

Julien Cubizolles <j.cubizolles@free.fr> writes:

> Matt Lundin <mdl@imapmail.org> writes:
>
>> Nick Dokos <ndokos@gmail.com> writes:
>>
>>> Here's a quick implementation of the method I described earlier
>>> in the thread:
>>
>> This works great. Thanks! Perhaps we could integrate something like this
>> into org-bbdb.el...
>
> I second that. It's exactly what I was looking for.
>

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.

I cleaned up the implementation a bit: the date list is produced in a
somewhat more lisp-ish way, the other helper functions have been moved
into the new org-bbdb-anniversaries-future function to avoid polluting
the name space. I could probably move the date list function in there as
well, but it seems generic enough that it should be independently
available.

The meaning of the optional argument has changed: in the previous
version, it meant "today plus the next n days"; now it means "today plus
the next (n-1) days".

Let me know what you think.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Allow early-warning anniversaries in agenda --]
[-- Type: text/x-patch, Size: 3829 bytes --]

From ba42045c9905e698db1bd62a2d547c29a9e9f097 Mon Sep 17 00:00:00 2001
From: Nick Dokos <ndokos@gmail.com>
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 | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 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..7c717d7 100644
--- a/lisp/org-bbdb.el
+++ b/lisp/org-bbdb.el
@@ -397,6 +397,58 @@ 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)
+    (reverse (dotimes (i n ret)
+	       (setq ret (cons (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)."
+  (if (not n) (setq n 7))
+  (if (<= n 0) nil
+    (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)
+	      (let ((modify-description
+		     (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))))
+		(mapcar modify-description l))))
+	   ;; Function to generate the list of annotated anniversaries
+	   ;; for the given date d.
+	   (gen-anniversaries
+	    (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))))))
+      ;; map the gen-anniversaries function over the dates
+      ;; and nconc the results into a single list
+      (apply 'nconc (mapcar gen-anniversaries dates)))))
+
 (defun org-bbdb-complete-link ()
   "Read a bbdb link with name completion."
   (require 'bbdb-com)
-- 
2.4.3


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]


Thanks!
-- 
Nick

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-16 17:25             ` [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] Nick Dokos
@ 2015-08-17  9:16               ` Nicolas Goaziou
  2015-08-17 16:42                 ` Nick Dokos
  0 siblings, 1 reply; 18+ messages in thread
From: Nicolas Goaziou @ 2015-08-17  9:16 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Hello,

Nick Dokos <ndokos@gmail.com> 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.

> +(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)
> +    (reverse (dotimes (i n ret)
> +	       (setq ret (cons (calendar-gregorian-from-absolute (+ abs i)) 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)."
> +  (if (not n) (setq n 7))

  (let ((n (or n 7)))
    (when (<= n 0) (error "..."))
    (let* (...)))
 
> +  (if (<= n 0) nil
> +    (let* (
> +	   ;; list of relevant dates.

You need to capitalize comments.

> +	   (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)
> +	      (let ((modify-description
> +		     (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.

Missing full stop in first sentence.

> +		       (string-match "]]" x)
> +		       (replace-match (format " -- %d-%02d-%02d\\&" (third d) (first d) (second d))
> +				      nil nil x))))
> +		(mapcar modify-description l))))

Why don't you simply write

  (mapcar (lambda (x) (string-match "]]" x) ...)
          l)

?

> +	   ;; Function to generate the list of annotated anniversaries
> +	   ;; for the given date d.
> +	   (gen-anniversaries
> +	    (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.

"Rebind".

> +		(funcall annotate-descriptions d (org-bbdb-anniversaries))))))
> +      ;; map the gen-anniversaries function over the dates
> +      ;; and nconc the results into a single list

Missing capitalization and full stop.

> +      (apply 'nconc (mapcar gen-anniversaries dates)))))

#'nconc (there is also `cl-mapcan').

Also, gen-anniversaries is a one-liner. I don't think it deserves its
own name.

IOW, wouldn't it be better to use less levels of indirection, i.e., less
helper functions?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-17  9:16               ` Nicolas Goaziou
@ 2015-08-17 16:42                 ` Nick Dokos
  2015-08-17 16:57                   ` Rasmus
  0 siblings, 1 reply; 18+ messages in thread
From: Nick Dokos @ 2015-08-17 16:42 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Nick Dokos <ndokos@gmail.com> 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"?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Allow early-warning anniversaries in agenda. --]
[-- Type: text/x-patch, Size: 3739 bytes --]

From f90ab3346f0b49b7397d1b963359f14a48a019f1 Mon Sep 17 00:00:00 2001
From: Nick Dokos <ndokos@gmail.com>
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


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]


Thanks!
-- 
Nick

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-17 16:42                 ` Nick Dokos
@ 2015-08-17 16:57                   ` Rasmus
  2015-08-17 17:35                     ` Nicolas Goaziou
  0 siblings, 1 reply; 18+ messages in thread
From: Rasmus @ 2015-08-17 16:57 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <ndokos@gmail.com> writes:

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

My understanding is (require 'cl-lib) is OK.  We can probably kill a lot
of our own prefixed functions by using cl-lib functions.  And IMO we
should.  (require 'cl) is not good (other than when byte-compiling).

Correct me if I'm wrong. 

So cl-mapcan is OK.

> Also, does it matter if I use the alias "mapcan" instead of "cl-mapcan"?

I think for newer Emacs the prefix is preferred.  Sometimes the older
versions do not have it (e.g. outline-mode).  I don't know when the change
was made....

Rasmus

-- 
Lasciate ogni speranza o voi che entrate: siete nella mani di'machellaio

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-17 16:57                   ` Rasmus
@ 2015-08-17 17:35                     ` Nicolas Goaziou
  2015-10-06 15:11                       ` Nick Dokos
  0 siblings, 1 reply; 18+ messages in thread
From: Nicolas Goaziou @ 2015-08-17 17:35 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Nick Dokos <ndokos@gmail.com> writes:
>
>> 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?
>
> My understanding is (require 'cl-lib) is OK.  We can probably kill a lot
> of our own prefixed functions by using cl-lib functions.  And IMO we
> should.  (require 'cl) is not good (other than when byte-compiling).
>
> Correct me if I'm wrong. 

cl-lib is standard in Emacs 24.3. Before that, all you can do is

  (eval-when-compile (require 'cl))

and use macros only.

> So cl-mapcan is OK.

Actually it's not until Emacs minimal version issue is sorted out by Bastien.


Regards,

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-08-17 17:35                     ` Nicolas Goaziou
@ 2015-10-06 15:11                       ` Nick Dokos
  2015-10-07 19:58                         ` Nicolas Goaziou
  0 siblings, 1 reply; 18+ messages in thread
From: Nick Dokos @ 2015-10-06 15:11 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail <at> nicolasgoaziou.fr> writes:

> 
> Rasmus <rasmus <at> gmx.us> writes:
> 
> > Nick Dokos <ndokos <at> gmail.com> writes:
> >
> >> I did a mapcan originally and saw that it was an alias for cl-mapcan in
> >> cl-extras.el and that got me scared: ...
> 
> > So cl-mapcan is OK.
> 
> Actually it's not until Emacs minimal version issue is sorted out by Bastien.
> 


IIUC, this issue has not been sorted out yet. Should I wait for that to happen, 
or change the patch to use (apply #'nconc ...) and possibly revisit it in the 
future?

Thanks,
Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-10-06 15:11                       ` Nick Dokos
@ 2015-10-07 19:58                         ` Nicolas Goaziou
  2015-10-13 15:54                           ` Nick Dokos
  2015-10-14 23:21                           ` Nick Dokos
  0 siblings, 2 replies; 18+ messages in thread
From: Nicolas Goaziou @ 2015-10-07 19:58 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Hello,

Nick Dokos <ndokos@gmail.com> writes:

> IIUC, this issue has not been sorted out yet. Should I wait for that to happen, 
> or change the patch to use (apply #'nconc ...) and possibly revisit it in the 
> future?

I think the latter is fine. There are plenty of places to revisit in the
future anyway. Thank you.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-10-07 19:58                         ` Nicolas Goaziou
@ 2015-10-13 15:54                           ` Nick Dokos
  2015-10-14 23:21                           ` Nick Dokos
  1 sibling, 0 replies; 18+ messages in thread
From: Nick Dokos @ 2015-10-13 15:54 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Nick Dokos <ndokos@gmail.com> writes:
>
>> IIUC, this issue has not been sorted out yet. Should I wait for that to happen, 
>> or change the patch to use (apply #'nconc ...) and possibly revisit it in the 
>> future?
>
> I think the latter is fine. There are plenty of places to revisit in the
> future anyway. Thank you.
>
>

Thanks! I pushed the change. Please let me know if there is any problem
with it.

Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
  2015-10-07 19:58                         ` Nicolas Goaziou
  2015-10-13 15:54                           ` Nick Dokos
@ 2015-10-14 23:21                           ` Nick Dokos
  1 sibling, 0 replies; 18+ messages in thread
From: Nick Dokos @ 2015-10-14 23:21 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

>> IIUC, this issue has not been sorted out yet. Should I wait for that to happen, 
>> or change the patch to use (apply #'nconc ...) and possibly revisit it in the 
>> future?
>
> I think the latter is fine. There are plenty of places to revisit in the
> future anyway. Thank you.

[I thought I had replied but I cannot find it - apologies if this is a
duplicate]

Thank you. I pushed the change to master in commit
75f91f0bb7aa401e62a7ce08ce01596e051c096e.

Let me know if there are any problems.

--
Nick

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-10-14 23:21 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-29 13:41 org-bbdb-birthday reminder Julien Cubizolles
2015-08-12 20:55 ` Matt Lundin
2015-08-13  1:36   ` Nick Dokos
2015-08-13  6:35   ` Julien Cubizolles
2015-08-13 13:07     ` Matt Lundin
2015-08-14  0:26       ` Nick Dokos
2015-08-14 14:30         ` Matt Lundin
2015-08-15 18:24           ` Julien Cubizolles
2015-08-16 17:25             ` [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] Nick Dokos
2015-08-17  9:16               ` Nicolas Goaziou
2015-08-17 16:42                 ` Nick Dokos
2015-08-17 16:57                   ` Rasmus
2015-08-17 17:35                     ` Nicolas Goaziou
2015-10-06 15:11                       ` Nick Dokos
2015-10-07 19:58                         ` Nicolas Goaziou
2015-10-13 15:54                           ` Nick Dokos
2015-10-14 23:21                           ` Nick Dokos
2015-08-16 13:46           ` org-bbdb-birthday reminder Bastien Guerry

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).