From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Baumann Subject: Re: Add anniversary and org-mode Date: Fri, 21 Mar 2008 20:55:20 +0100 Message-ID: References: <87od99n1qm.fsf@bzg.ath.cx> <87prtplm64.fsf@bzg.ath.cx> <9uwsnxlli0.fsf@richardriley.net> <87d4ppll92.fsf@bzg.ath.cx> <87hcf1p83y.fsf@bzg.ath.cx> <87abkstd5v.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JcnL5-0000dq-Ce for emacs-orgmode@gnu.org; Fri, 21 Mar 2008 15:55:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JcnL4-0000dB-MB for emacs-orgmode@gnu.org; Fri, 21 Mar 2008 15:55:43 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JcnL4-0000d5-Hp for emacs-orgmode@gnu.org; Fri, 21 Mar 2008 15:55:42 -0400 Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JcnL3-0007Rn-Pi for emacs-orgmode@gnu.org; Fri, 21 Mar 2008 15:55:42 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JcnKy-0004yT-I4 for emacs-orgmode@gnu.org; Fri, 21 Mar 2008 19:55:36 +0000 Received: from p54963904.dip0.t-ipconnect.de ([84.150.57.4]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 21 Mar 2008 19:55:36 +0000 Received: from dtbaumann by p54963904.dip0.t-ipconnect.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 21 Mar 2008 19:55:36 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Bastien Guerry writes: > > I use this: > > (add-hook 'list-diary-entries-hook 'bbdb-include-anniversaries) > > -- > Bastien For those who hardly use the diary (like me), here's a wrapper/replacement to bbdb-anniv.el. Add %%(org-bbdb-anniversaries) somewhere in your org-file and all the anniversaries from the bbdb will be included in the diary. The format for birthdays, weddings, ... , can be customized in bbdb-anniv. Thomas ;;; org-bbdb-anniv.el --- Get anniversaries from BBDB ;; Copyright (C) 2008 Thomas Baumann ;; Author: Thomas Baumann ;; based on bbdb-anniv.el by Ivar Rummelhoff ;; Maintainer: Thomas Baumann ;; Created: 21 March 2008 ;; Keywords: calendar org ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; If you have not received a copy of the GNU General Public License ;; along with this software, it can be obtained from the GNU Project's ;; World Wide Web server (http://www.gnu.org/copyleft/gpl.html), from ;; its FTP server (ftp://ftp.gnu.org/pub/gnu/GPL), by sending an electronic ;; mail to this program's maintainer or by writing to the Free Software ;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;;; Commentary: ;; (require 'org-bbdb-anniv) ;; %%(org-bbdb-anniversaries) ;; ;; will include BBDB-anniversaries in the agenda view ;; ;; From bbdb-anniv.el ;; The anniversaries are stored in BBDB in the field `anniversary' ;; in the format ;; ;; [YYYY-MM-DD CLASS-OR-FORMAT-STRING] ;; {\nYYYY-MM-DD CLASS-OR-FORMAT-STRING}* ;; ;; CLASS-OR-FORMAT-STRING is one of two things: ;; ;; * an identifier for a class of anniversaries (eg. birthday or ;; wedding) from `bbdb-anniversary-format-alist'. ;; * the (format) string displayed in the diary. ;; ;; It defaults to the value of `bbdb-default-anniversary-format' ;; ("birthday" by default). ;; ;; The substitutions in the format string are (in order): ;; * the name of the record containing this anniversary ;; * the number of years ;; * an ordinal suffix (st, nd, rd, th) for the year ;; ;; See the documentation of `bbdb-anniversary-format-alist' for ;; further options. ;; ;; Example (my own record): ;; ;; 1973-06-22 ;; 20??-??-?? wedding ;; 1998-03-12 %s created bbdb-anniv.el %d years ago ;; ;; If you use the hook `sort-diary-entries', you should make sure that ;; it is executed after `bbdb-include-anniversaries'. ;; (require 'bbdb-anniv) ;;;###autoload (defun org-bbdb-anniversaries () "Extract anniversaries from BBDB for display in the agenda." (let ((dates (list (cons (cons (extract-calendar-month date) (extract-calendar-day date)) (extract-calendar-year date)))) (text ()) annivs date years split class form) (dolist (rec (bbdb-records)) (when (setq annivs (bbdb-record-getprop rec bbdb-anniversary-field)) (setq annivs (bbdb-split annivs "\n")) (while annivs (setq split (bbdb-anniv-split (pop annivs))) (multiple-value-bind (m d y) (funcall bbdb-extract-date-fun (car split)) (when (and (or (setq date (assoc (cons m d) dates)) (and (= d 29) (= m 2) (setq date (assoc '(3 . 1) dates)) (not (calendar-leap-year-p (cdr date))))) (< 0 (setq years (- (cdr date) y)))) (let* ((class (or (cadr split) bbdb-default-anniversary-format)) (form (or (cdr (assoc class bbdb-anniversary-format-alist)) class)) ; (as format string) (name (bbdb-record-name rec)) (suffix (diary-ordinal-suffix years)) (tmp (cond ((functionp form) (funcall form name years suffix)) ((listp form) (eval form)) (t (format form name years suffix))))) (if text (setq text (append text (list tmp))) (setq text (list tmp)))) ))))) (when text (mapconcat 'identity text "; ")))) (provide 'org-bbdb-anniv) ;;; org-bbdb-anniv.el ends here