diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el index f851668..5e99494 100644 --- a/lisp/org-bbdb.el +++ b/lisp/org-bbdb.el @@ -412,6 +412,22 @@ This is used by Org to re-create the anniversary hash table." (mapcar (lambda (i) (calendar-gregorian-from-absolute (+ abs i))) (number-sequence 0 (1- n))))) +(defun org-bbdb-anniversary-description (agenda-date anniv-date) + "Return a string used to modify an agenda anniversary entry. The + calculation of the string is based on the difference between + the anniversary date and the date on which the entry appears + in the agenda. This makes it possible to have different entries + for the same event depending on if it occurs in the next few days + or far away in the future." + (let ((delta (- (calendar-absolute-from-gregorian anniv-date) + (calendar-absolute-from-gregorian agenda-date)))) + + (cond + ((= delta 0) " -- today\\&") + ((= delta 1) " -- tomorrow\\&") + ((< delta 7) (format " -- in %d days\\&" delta)) + ((format " -- %d-%02d-%02d\\&" (third anniv-date) (first anniv-date) (second anniv-date)))))) + ;;;###autoload (defun org-bbdb-anniversaries-future (&optional n) "Return list of anniversaries for today and the next n-1 days (default n=7)." @@ -425,19 +441,17 @@ must be positive")) ;; Function to annotate text of each element of l with the ;; anniversary date d. (annotate-descriptions - (lambda (d l) + (lambda (agenda-date 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\\&" - (nth 2 d) - (nth 0 d) - (nth 1 d)) - nil nil x)) + (let ((desc (org-bbdb-anniversary-description + agenda-date d))) + (string-match "]]" x) + (replace-match desc nil nil x))) l)))) ;; Map a function that generates anniversaries for each date ;; over the dates and nconc the results into a single list. When @@ -447,12 +461,13 @@ must be positive")) (apply #'nconc (mapcar (lambda (d) - (let ((date d)) + (let ((agenda-date date) + (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)))) + (funcall annotate-descriptions agenda-date d (org-bbdb-anniversaries)))) dates))))) (defun org-bbdb-complete-link ()