summaryrefslogtreecommitdiff
path: root/lisp/org/org-bbdb.el
diff options
context:
space:
mode:
authorRasmus <rasmus@gmx.us>2017-09-18 12:01:12 +0200
committerRasmus <rasmus@gmx.us>2017-09-18 12:01:12 +0200
commitab351d442d7bb4d17cbb43638aaed1775d8c0344 (patch)
tree19da4c93526d3de543efe21a53ab2d098fb9f50b /lisp/org/org-bbdb.el
parent5490ccc5ebf39759dfd084bbd31f464701a3e775 (diff)
downloademacs-ab351d442d7bb4d17cbb43638aaed1775d8c0344.tar.gz
emacs-ab351d442d7bb4d17cbb43638aaed1775d8c0344.tar.bz2
emacs-ab351d442d7bb4d17cbb43638aaed1775d8c0344.zip
Update Org to v9.1.1
Please see etc/ORG-NEWS for major changes.
Diffstat (limited to 'lisp/org/org-bbdb.el')
-rw-r--r--lisp/org/org-bbdb.el55
1 files changed, 45 insertions, 10 deletions
diff --git a/lisp/org/org-bbdb.el b/lisp/org/org-bbdb.el
index 2189b2050a5..889271affea 100644
--- a/lisp/org/org-bbdb.el
+++ b/lisp/org/org-bbdb.el
@@ -138,6 +138,24 @@
:group 'org-bbdb-anniversaries
:require 'bbdb)
+(defcustom org-bbdb-general-anniversary-description-after 7
+ "When to switch anniversary descriptions to a more general format.
+
+Anniversary descriptions include the point in time, when the
+anniversary appears. This is, in its most general form, just the
+date of the anniversary. Or more specific terms, like \"today\",
+\"tomorrow\" or \"in n days\" are used to describe the time span.
+
+If the anniversary happens in less than that number of days, the
+specific description is used. Otherwise, the general one is
+used."
+ :group 'org-bbdb-anniversaries
+ :version "26.1"
+ :package-version '(Org . "9.1")
+ :type 'integer
+ :require 'bbdb
+ :safe #'integerp)
+
(defcustom org-bbdb-anniversary-format-alist
'(("birthday" .
(lambda (name years suffix)
@@ -412,7 +430,25 @@ 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)))))
-;;;###autoload
+(defun org-bbdb-anniversary-description (agenda-date anniv-date)
+ "Return a string used to incorporate into an agenda anniversary entry.
+The calculation of the anniversary description string is based on
+the difference between the anniversary date, given as ANNIV-DATE,
+and the date on which the entry appears in the agenda, given as
+AGENDA-DATE. 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 org-bbdb-general-anniversary-description-after) (format " -- in %d days\\&" delta))
+ ((pcase-let ((`(,month ,day ,year) anniv-date))
+ (format " -- %d-%02d-%02d\\&" year month day))))))
+
+
(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)))
@@ -425,19 +461,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 +481,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 ()