From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder]
Date: Sun, 16 Aug 2015 13:25:51 -0400 [thread overview]
Message-ID: <87pp2n6t7k.fsf_-_@pierrot.dokosmarshall.org> (raw)
In-Reply-To: 87vbcg76lq.fsf@free.fr
[-- 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
next prev parent reply other threads:[~2015-08-16 17:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Nick Dokos [this message]
2015-08-17 9:16 ` [PATCH] Allow early-warning anniversaries in agends [was: Re: org-bbdb-birthday reminder] 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
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pp2n6t7k.fsf_-_@pierrot.dokosmarshall.org \
--to=ndokos@gmail.com \
--cc=emacs-orgmode@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 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).