emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Thomas Baumann <dtbaumann@yahoo.de>
To: emacs-orgmode@gnu.org
Subject: Re: Add anniversary and org-mode
Date: Fri, 21 Mar 2008 20:55:20 +0100	[thread overview]
Message-ID: <m363vfn97b.fsf@norvel.baumann-gauting.site> (raw)
In-Reply-To: 87abkstd5v.fsf@bzg.ath.cx

Bastien Guerry <bzg@altern.org> 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 <thomas.baumann@ch.tum.de>
;;         based on bbdb-anniv.el by Ivar Rummelhoff <ivarru@math.uio.no>
;; Maintainer: Thomas Baumann <thomas.baumann@ch.tum.de>
;; 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

  reply	other threads:[~2008-03-21 19:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-20  0:02 Add anniversary and org-mode Richard G Riley
2008-03-20 10:05 ` Carsten Dominik
2008-03-20 10:20   ` Richard G Riley
2008-03-20 10:12 ` Bastien Guerry
2008-03-20 10:24   ` Richard G Riley
2008-03-20 10:33     ` Bastien Guerry
2008-03-20 10:48       ` Richard G Riley
2008-03-20 10:53         ` Bastien Guerry
2008-03-20 12:20           ` Thomas Baumann
2008-03-20 18:23             ` Bastien Guerry
2008-03-21 12:28               ` Thomas Baumann
2008-03-21 13:33                 ` Bastien Guerry
2008-03-21 19:55                   ` Thomas Baumann [this message]
2008-03-22 17:19                     ` Carsten Dominik
2008-03-23  7:16                       ` Thomas Baumann
2008-03-23 12:52                         ` Carsten Dominik

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=m363vfn97b.fsf@norvel.baumann-gauting.site \
    --to=dtbaumann@yahoo.de \
    --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).