From: Michael Welle <mwe012008@gmx.net>
To: emacs-orgmode@gnu.org
Subject: Re: org-bbdb-anniversaries-future
Date: Tue, 07 Mar 2017 10:19:32 +0100 [thread overview]
Message-ID: <87tw75bg0r.fsf@luisa.c0t0d0s0.de> (raw)
In-Reply-To: <877f437hw5.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Sun, 05 Mar 2017 18:28:10 +0100")
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
Hello,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Michael Welle <mwe012008@gmx.net> writes:
>
>> Maybe it's a tiny change, if we strip the comments ;). It's not too
>> sophisticated, everyone could have done it.
>
> I definitely think it _is_ a tiny change.
>
> Some comments follow.
thank you for the valuable comments. I think I've incorporated them all.
Furthermore I reworded some of the comments and I introduced a defvar,
so that the point in time, when to switch to the more general
descriptive text isn't hardcoded anymore, but customisable.
> Also, could you provide a commit message?
----
Make anniversaries' time span information more descriptive in agenda.
* lisp/org-bbdb.el (org-bbdb-anniversary-description): New function.
(org-bbdb-general-anniversary-description-after): New variable.
(org-bbdb-anniversaries-future): Incorporate calculation of the description.
----
Regards
hmw
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-bbdb-hmw-anniv-hackv2.diff --]
[-- Type: text/x-diff, Size: 3755 bytes --]
diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el
index f851668..0aa1ddb 100644
--- a/lisp/org-bbdb.el
+++ b/lisp/org-bbdb.el
@@ -138,6 +138,19 @@
: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 is ORG-BBDB-GENERAL-ANNIVERSARY-DESCRIPTION-AFTER
+or more days in the future, the general description is used,
+otherwise the more specific description is used."
+ :type 'integer
+ :group 'org-bbdb-anniversaries
+ :require 'bbdb)
+
(defcustom org-bbdb-anniversary-format-alist
'(("birthday" .
(lambda (name years suffix)
@@ -412,7 +425,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 +456,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 +476,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 ()
next prev parent reply other threads:[~2017-03-07 9:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <qf8k5dxnqs.ln2@news.c0t0d0s0.de>
2016-07-14 22:22 ` org-bbdb-anniversaries-future Marco Wahl
2017-03-01 9:19 ` org-bbdb-anniversaries-future Alan Schmitt
2017-03-01 9:30 ` org-bbdb-anniversaries-future Michael Welle
2017-03-01 10:39 ` org-bbdb-anniversaries-future Marco Wahl
2017-03-01 13:38 ` org-bbdb-anniversaries-future Nicolas Goaziou
2017-03-01 14:03 ` org-bbdb-anniversaries-future Michael Welle
2017-03-01 14:30 ` org-bbdb-anniversaries-future Alan Schmitt
2017-03-01 14:40 ` org-bbdb-anniversaries-future Michael Welle
2017-03-01 14:34 ` org-bbdb-anniversaries-future Rasmus
2017-03-05 17:28 ` org-bbdb-anniversaries-future Nicolas Goaziou
2017-03-07 9:19 ` Michael Welle [this message]
2017-03-12 12:47 ` org-bbdb-anniversaries-future Nicolas Goaziou
2017-03-13 8:22 ` org-bbdb-anniversaries-future Michael Welle
2017-03-13 8:31 ` org-bbdb-anniversaries-future Michael Welle
2017-03-17 7:29 ` org-bbdb-anniversaries-future Nicolas Goaziou
2017-03-01 10:35 ` org-bbdb-anniversaries-future Marco Wahl
[not found] <ipa2rcx5nc.ln2@news.c0t0d0s0.de>
2016-03-08 9:25 ` org-bbdb-anniversaries, bbdb v3 Marco Wahl
[not found] ` <7hp2rcx89n.ln2@news.c0t0d0s0.de>
2016-03-08 13:08 ` Nick Dokos
2016-03-08 15:43 ` org-bbdb-anniversaries-future Georges
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=87tw75bg0r.fsf@luisa.c0t0d0s0.de \
--to=mwe012008@gmx.net \
--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).