2008-03-21 12:10:23 -04:00
|
|
|
;;; org-bbdb.el --- Support for links to BBDB entries from within Org-mode
|
2008-03-14 13:22:03 -04:00
|
|
|
|
2012-01-03 12:47:01 -05:00
|
|
|
;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
|
2008-03-14 13:22:03 -04:00
|
|
|
|
2008-04-13 15:04:21 -04:00
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>,
|
|
|
|
;; Thomas Baumann <thomas dot baumann at ch dot tum dot de>
|
2008-03-14 13:22:03 -04:00
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2008-05-06 08:45:52 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-03-14 13:22:03 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:45:52 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-03-14 13:22:03 -04:00
|
|
|
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 08:45:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-14 13:22:03 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-03-21 12:10:23 -04:00
|
|
|
;; This file implements links to BBDB database entries from within Org-mode.
|
2008-03-14 13:22:03 -04:00
|
|
|
;; Org-mode loads this module by default - if this is not what you want,
|
|
|
|
;; configure the variable `org-modules'.
|
|
|
|
|
2008-04-19 01:21:33 -04:00
|
|
|
;; It also implements an interface (based on Ivar Rummelhoff's
|
|
|
|
;; bbdb-anniv.el) for those org-mode users, who do not use the diary
|
|
|
|
;; but who do want to include the anniversaries stored in the BBDB
|
|
|
|
;; into the org-agenda. If you already include the `diary' into the
|
|
|
|
;; agenda, you might want to prefer to include the anniversaries in
|
|
|
|
;; the diary using bbdb-anniv.el.
|
2008-04-24 04:29:47 -04:00
|
|
|
;;
|
2008-04-13 15:04:21 -04:00
|
|
|
;; Put the following in /somewhere/at/home/diary.org and make sure
|
|
|
|
;; that this file is in `org-agenda-files`
|
|
|
|
;;
|
|
|
|
;; %%(org-bbdb-anniversaries)
|
|
|
|
;;
|
|
|
|
;; For example my diary.org looks like:
|
|
|
|
;; * Anniversaries
|
|
|
|
;; #+CATEGORY: Anniv
|
|
|
|
;; %%(org-bbdb-anniversaries)
|
|
|
|
;;
|
|
|
|
;;
|
2009-02-27 02:27:44 -05:00
|
|
|
;; To add an anniversary to a BBDB record, press `C-o' in the record.
|
|
|
|
;; You will be prompted for the field name, in this case it must be
|
|
|
|
;; "anniversary". If this is the first time you are using this field,
|
|
|
|
;; you need to confirm that it should be created.
|
2008-04-13 15:04:21 -04:00
|
|
|
;;
|
2009-02-27 02:27:44 -05:00
|
|
|
;; The format of an anniversary field stored in BBDB is the following
|
|
|
|
;; (items in {} are optional):
|
|
|
|
;;
|
|
|
|
;; YYYY-MM-DD{ CLASS-OR-FORMAT-STRING}
|
|
|
|
;; {\nYYYY-MM-DD CLASS-OR-FORMAT-STRING}...
|
2008-04-13 15:04:21 -04:00
|
|
|
;;
|
|
|
|
;; CLASS-OR-FORMAT-STRING is one of two things:
|
|
|
|
;;
|
2009-02-27 02:27:44 -05:00
|
|
|
;; - an identifier for a class of anniversaries (eg. birthday or
|
|
|
|
;; wedding) from `org-bbdb-anniversary-format-alist' which then
|
2009-11-12 07:39:29 -05:00
|
|
|
;; defines the format string for this class
|
2009-02-27 02:27:44 -05:00
|
|
|
;; - the (format) string displayed in the diary.
|
|
|
|
;;
|
|
|
|
;; You can enter multiple anniversaries for a single BBDB record by
|
|
|
|
;; separating them with a newline character. At the BBDB prompt for
|
|
|
|
;; the field value, type `C-q C-j' to enter a newline between two
|
|
|
|
;; anniversaries.
|
2008-04-13 15:04:21 -04:00
|
|
|
;;
|
2009-02-27 02:27:44 -05:00
|
|
|
;; If you omit the CLASS-OR-FORMAT-STRING entirely, it defaults to the
|
|
|
|
;; value of `org-bbdb-default-anniversary-format' ("birthday" by
|
|
|
|
;; default).
|
2008-04-13 15:04:21 -04:00
|
|
|
;;
|
|
|
|
;; The substitutions in the format string are (in order):
|
2009-02-27 02:27:44 -05:00
|
|
|
;; - the name of the record containing this anniversary
|
|
|
|
;; - the number of years
|
|
|
|
;; - an ordinal suffix (st, nd, rd, th) for the year
|
2008-04-13 15:04:21 -04:00
|
|
|
;;
|
|
|
|
;; See the documentation of `org-bbdb-anniversary-format-alist' for
|
|
|
|
;; further options.
|
|
|
|
;;
|
|
|
|
;; Example
|
|
|
|
;;
|
|
|
|
;; 1973-06-22
|
|
|
|
;; 20??-??-?? wedding
|
|
|
|
;; 1998-03-12 %s created bbdb-anniv.el %d years ago
|
2008-06-12 09:09:03 -04:00
|
|
|
;;
|
|
|
|
;; From Org's agenda, you can use `C-c C-o' to jump to the BBDB
|
|
|
|
;; link from which the entry at point originates.
|
|
|
|
;;
|
2008-03-21 12:10:23 -04:00
|
|
|
;;; Code:
|
|
|
|
|
2008-03-14 13:22:03 -04:00
|
|
|
(require 'org)
|
2008-04-13 15:04:21 -04:00
|
|
|
(eval-when-compile
|
|
|
|
(require 'cl))
|
2008-03-14 13:22:03 -04:00
|
|
|
|
|
|
|
;; Declare external functions and variables
|
2008-03-21 12:10:23 -04:00
|
|
|
|
2008-03-14 13:22:03 -04:00
|
|
|
(declare-function bbdb "ext:bbdb-com" (string elidep))
|
|
|
|
(declare-function bbdb-company "ext:bbdb-com" (string elidep))
|
2008-03-21 12:10:23 -04:00
|
|
|
(declare-function bbdb-current-record "ext:bbdb-com"
|
2008-03-14 13:22:03 -04:00
|
|
|
(&optional planning-on-modifying))
|
|
|
|
(declare-function bbdb-name "ext:bbdb-com" (string elidep))
|
2009-05-10 03:15:13 -04:00
|
|
|
(declare-function bbdb-completing-read-record "ext:bbdb-com"
|
|
|
|
(prompt &optional omit-records))
|
2008-03-14 13:22:03 -04:00
|
|
|
(declare-function bbdb-record-getprop "ext:bbdb" (record property))
|
|
|
|
(declare-function bbdb-record-name "ext:bbdb" (record))
|
2008-04-13 15:04:21 -04:00
|
|
|
(declare-function bbdb-records "ext:bbdb"
|
|
|
|
(&optional dont-check-disk already-in-db-buffer))
|
|
|
|
(declare-function bbdb-split "ext:bbdb" (string separators))
|
|
|
|
(declare-function bbdb-string-trim "ext:bbdb" (string))
|
2009-05-10 03:15:13 -04:00
|
|
|
|
2008-04-13 15:04:21 -04:00
|
|
|
(declare-function calendar-leap-year-p "calendar" (year))
|
|
|
|
(declare-function diary-ordinal-suffix "diary-lib" (n))
|
|
|
|
|
2008-05-06 06:46:51 -04:00
|
|
|
(defvar date) ;; dynamically scoped from Org
|
2008-04-13 15:04:21 -04:00
|
|
|
|
2011-12-31 11:04:27 -05:00
|
|
|
;; Support for version 2.35
|
|
|
|
(defvar org-bbdb-old (fboundp 'bbdb-record-get-field-internal))
|
|
|
|
|
2008-04-19 01:21:33 -04:00
|
|
|
;; Customization
|
|
|
|
|
2008-04-13 15:04:21 -04:00
|
|
|
(defgroup org-bbdb-anniversaries nil
|
|
|
|
"Customizations for including anniversaries from BBDB into Agenda."
|
|
|
|
:group 'org-bbdb)
|
|
|
|
|
|
|
|
(defcustom org-bbdb-default-anniversary-format "birthday"
|
|
|
|
"Default anniversary class."
|
|
|
|
:type 'string
|
|
|
|
:group 'org-bbdb-anniversaries
|
|
|
|
:require 'bbdb)
|
|
|
|
|
|
|
|
(defcustom org-bbdb-anniversary-format-alist
|
2008-06-12 10:30:35 -04:00
|
|
|
'(("birthday" lambda
|
|
|
|
(name years suffix)
|
|
|
|
(concat "Birthday: [[bbdb:" name "][" name " ("
|
2011-02-07 11:43:15 -05:00
|
|
|
(format "%s" years) ; handles numbers as well as strings
|
2008-06-12 10:30:35 -04:00
|
|
|
suffix ")]]"))
|
|
|
|
("wedding" lambda
|
|
|
|
(name years suffix)
|
|
|
|
(concat "[[bbdb:" name "][" name "'s "
|
2011-02-07 11:43:15 -05:00
|
|
|
(format "%s" years)
|
2008-06-12 10:30:35 -04:00
|
|
|
suffix " wedding anniversary]]")))
|
2008-04-13 15:04:21 -04:00
|
|
|
"How different types of anniversaries should be formatted.
|
|
|
|
An alist of elements (STRING . FORMAT) where STRING is the name of an
|
|
|
|
anniversary class and format is either:
|
|
|
|
1) A format string with the following substitutions (in order):
|
|
|
|
* the name of the record containing this anniversary
|
|
|
|
* the number of years
|
|
|
|
* an ordinal suffix (st, nd, rd, th) for the year
|
|
|
|
|
|
|
|
2) A function to be called with three arguments: NAME YEARS SUFFIX
|
|
|
|
(string int string) returning a string for the diary or nil.
|
|
|
|
|
|
|
|
3) An Emacs Lisp form that should evaluate to a string (or nil) in the
|
|
|
|
scope of variables NAME, YEARS and SUFFIX (among others)."
|
|
|
|
:type 'sexp
|
|
|
|
:group 'org-bbdb-anniversaries
|
|
|
|
:require 'bbdb)
|
|
|
|
|
|
|
|
(defcustom org-bbdb-anniversary-field 'anniversary
|
|
|
|
"The BBDB field which contains anniversaries.
|
|
|
|
The anniversaries are stored in the following format
|
|
|
|
|
|
|
|
YYYY-MM-DD Class-or-Format-String
|
|
|
|
|
|
|
|
where class is one of the customized classes for anniversaries;
|
|
|
|
birthday and wedding are predefined. Format-String can take three
|
|
|
|
substitutions 1) the name of the record containing this
|
|
|
|
anniversary, 2) the number of years, and 3) an ordinal suffix for
|
|
|
|
the year.
|
|
|
|
|
2008-05-09 00:08:45 -04:00
|
|
|
Multiple anniversaries can be separated by \\n."
|
2008-04-13 15:04:21 -04:00
|
|
|
:type 'symbol
|
|
|
|
:group 'org-bbdb-anniversaries
|
|
|
|
:require 'bbdb)
|
|
|
|
|
|
|
|
(defcustom org-bbdb-extract-date-fun 'org-bbdb-anniv-extract-date
|
|
|
|
"How to retrieve `month date year' from the anniversary field.
|
|
|
|
|
2008-05-09 00:08:45 -04:00
|
|
|
Customize if you have already filled your BBDB with dates
|
2008-04-13 15:04:21 -04:00
|
|
|
different from YYYY-MM-DD. The function must return a list (month
|
2008-05-09 00:08:45 -04:00
|
|
|
date year)."
|
2008-04-13 15:04:21 -04:00
|
|
|
:type 'function
|
|
|
|
:group 'org-bbdb-anniversaries
|
|
|
|
:require 'bbdb)
|
|
|
|
|
2008-03-14 13:22:03 -04:00
|
|
|
|
|
|
|
;; Install the link type
|
|
|
|
(org-add-link-type "bbdb" 'org-bbdb-open 'org-bbdb-export)
|
|
|
|
(add-hook 'org-store-link-functions 'org-bbdb-store-link)
|
|
|
|
|
|
|
|
;; Implementation
|
|
|
|
(defun org-bbdb-store-link ()
|
2008-03-21 12:10:23 -04:00
|
|
|
"Store a link to a BBDB database entry."
|
2008-03-14 13:22:03 -04:00
|
|
|
(when (eq major-mode 'bbdb-mode)
|
|
|
|
;; This is BBDB, we make this link!
|
2011-12-31 11:04:27 -05:00
|
|
|
(let* ((rec (bbdb-current-record))
|
|
|
|
(name (bbdb-record-name rec))
|
|
|
|
(company (if org-bbdb-old
|
|
|
|
(bbdb-record-getprop rec 'company)
|
|
|
|
(car (bbdb-record-get-field rec 'organization))))
|
2008-03-14 13:22:03 -04:00
|
|
|
(link (org-make-link "bbdb:" name)))
|
|
|
|
(org-store-link-props :type "bbdb" :name name :company company
|
2008-03-15 16:34:06 -04:00
|
|
|
:link link :description name)
|
|
|
|
link)))
|
2008-03-14 13:22:03 -04:00
|
|
|
|
|
|
|
(defun org-bbdb-export (path desc format)
|
2008-03-21 12:10:23 -04:00
|
|
|
"Create the export version of a BBDB link specified by PATH or DESC.
|
|
|
|
If exporting to either HTML or LaTeX FORMAT the link will be
|
2010-07-15 16:26:51 -04:00
|
|
|
italicized, in all other cases it is left unchanged."
|
2011-02-14 23:37:17 -05:00
|
|
|
(when (string= desc (format "bbdb:%s" path))
|
|
|
|
(setq desc path))
|
2008-03-14 13:22:03 -04:00
|
|
|
(cond
|
2011-02-14 23:37:17 -05:00
|
|
|
((eq format 'html) (format "<i>%s</i>" desc))
|
|
|
|
((eq format 'latex) (format "\\textit{%s}" desc))
|
|
|
|
(t desc)))
|
2008-03-14 13:22:03 -04:00
|
|
|
|
|
|
|
(defun org-bbdb-open (name)
|
|
|
|
"Follow a BBDB link to NAME."
|
|
|
|
(require 'bbdb)
|
|
|
|
(let ((inhibit-redisplay (not debug-on-error))
|
|
|
|
(bbdb-electric-p nil))
|
2011-12-31 11:04:27 -05:00
|
|
|
(if org-bbdb-old
|
|
|
|
(org-bbdb-open-old)
|
|
|
|
(org-bbdb-open-new))))
|
|
|
|
|
|
|
|
(defun org-bbdb-open-old ()
|
|
|
|
(catch 'exit
|
|
|
|
;; Exact match on name
|
|
|
|
(bbdb-name (concat "\\`" name "\\'") nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Exact match on name
|
|
|
|
(bbdb-company (concat "\\`" name "\\'") nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Partial match on name
|
|
|
|
(bbdb-name name nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Partial match on company
|
|
|
|
(bbdb-company name nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; General match including network address and notes
|
|
|
|
(bbdb name nil)
|
|
|
|
(when (= 0 (buffer-size (get-buffer "*BBDB*")))
|
|
|
|
(delete-window (get-buffer-window "*BBDB*"))
|
|
|
|
(error "No matching BBDB record"))))
|
|
|
|
|
|
|
|
(defun org-bbdb-open-new ()
|
|
|
|
(catch 'exit
|
|
|
|
;; Exact match on name
|
|
|
|
(bbdb-search-name (concat "\\`" name "\\'") nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Exact match on name
|
|
|
|
(bbdb-search-organization (concat "\\`" name "\\'") nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Partial match on name
|
|
|
|
(bbdb-search-name name nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; Partial match on company
|
|
|
|
(bbdb-search-organization name nil)
|
|
|
|
(if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
|
|
|
|
;; General match including network address and notes
|
|
|
|
(bbdb name nil)
|
|
|
|
(when (= 0 (buffer-size (get-buffer "*BBDB*")))
|
|
|
|
(delete-window (get-buffer-window "*BBDB*"))
|
|
|
|
(error "No matching BBDB record"))))
|
2008-03-14 13:22:03 -04:00
|
|
|
|
2008-04-13 15:04:21 -04:00
|
|
|
(defun org-bbdb-anniv-extract-date (time-str)
|
|
|
|
"Convert YYYY-MM-DD to (month date year).
|
2011-02-07 11:43:15 -05:00
|
|
|
Argument TIME-STR is the value retrieved from BBDB. If YYYY- is omitted
|
|
|
|
it will be considered unknown."
|
|
|
|
(multiple-value-bind (a b c) (values-list (bbdb-split time-str "-"))
|
|
|
|
(if (eq c nil)
|
|
|
|
(list (string-to-number a)
|
|
|
|
(string-to-number b)
|
|
|
|
nil)
|
|
|
|
(list (string-to-number b)
|
|
|
|
(string-to-number c)
|
|
|
|
(string-to-number a)))))
|
2008-04-13 15:04:21 -04:00
|
|
|
|
|
|
|
(defun org-bbdb-anniv-split (str)
|
2008-05-09 00:08:45 -04:00
|
|
|
"Split multiple entries in the BBDB anniversary field.
|
2008-04-13 15:04:21 -04:00
|
|
|
Argument STR is the anniversary field in BBDB."
|
|
|
|
(let ((pos (string-match "[ \t]" str)))
|
|
|
|
(if pos (list (substring str 0 pos)
|
|
|
|
(bbdb-string-trim (substring str pos)))
|
|
|
|
(list str nil))))
|
|
|
|
|
2008-05-06 06:46:51 -04:00
|
|
|
(defvar org-bbdb-anniv-hash nil
|
|
|
|
"A hash holding anniversaries extracted from BBDB.
|
|
|
|
The hash table is created on first use.")
|
2008-04-13 15:04:21 -04:00
|
|
|
|
2008-05-06 06:46:51 -04:00
|
|
|
(defvar org-bbdb-updated-p t
|
|
|
|
"This is non-nil if BBDB has been updated since we last built the hash.")
|
|
|
|
|
|
|
|
(defun org-bbdb-make-anniv-hash ()
|
|
|
|
"Create a hash with anniversaries extracted from BBDB, for fast access.
|
|
|
|
The anniversaries are assumed to be stored `org-bbdb-anniversary-field'."
|
|
|
|
|
|
|
|
(let (split tmp annivs)
|
|
|
|
(clrhash org-bbdb-anniv-hash)
|
2008-04-13 15:04:21 -04:00
|
|
|
(dolist (rec (bbdb-records))
|
|
|
|
(when (setq annivs (bbdb-record-getprop
|
|
|
|
rec org-bbdb-anniversary-field))
|
|
|
|
(setq annivs (bbdb-split annivs "\n"))
|
|
|
|
(while annivs
|
|
|
|
(setq split (org-bbdb-anniv-split (pop annivs)))
|
|
|
|
(multiple-value-bind (m d y)
|
2009-03-14 03:50:11 -04:00
|
|
|
(values-list (funcall org-bbdb-extract-date-fun (car split)))
|
2008-05-06 06:46:51 -04:00
|
|
|
(setq tmp (gethash (list m d) org-bbdb-anniv-hash))
|
2008-12-04 09:33:43 -05:00
|
|
|
(puthash (list m d) (cons (list y
|
|
|
|
(bbdb-record-name rec)
|
2008-05-06 06:46:51 -04:00
|
|
|
(cadr split))
|
|
|
|
tmp)
|
|
|
|
org-bbdb-anniv-hash))))))
|
|
|
|
(setq org-bbdb-updated-p nil))
|
2008-04-24 04:29:47 -04:00
|
|
|
|
2008-05-06 06:46:51 -04:00
|
|
|
(defun org-bbdb-updated (rec)
|
|
|
|
"Record the fact that BBDB has been updated.
|
|
|
|
This is used by Org to re-create the anniversary hash table."
|
|
|
|
(setq org-bbdb-updated-p t))
|
|
|
|
|
|
|
|
(add-hook 'bbdb-after-change-hook 'org-bbdb-updated)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun org-bbdb-anniversaries()
|
|
|
|
"Extract anniversaries from BBDB for display in the agenda."
|
2008-09-26 12:38:27 -04:00
|
|
|
(require 'bbdb)
|
2008-05-06 06:46:51 -04:00
|
|
|
(require 'diary-lib)
|
|
|
|
(unless (hash-table-p org-bbdb-anniv-hash)
|
|
|
|
(setq org-bbdb-anniv-hash
|
|
|
|
(make-hash-table :test 'equal :size 366)))
|
|
|
|
|
|
|
|
(when (or org-bbdb-updated-p
|
|
|
|
(= 0 (hash-table-count org-bbdb-anniv-hash)))
|
|
|
|
(org-bbdb-make-anniv-hash))
|
|
|
|
|
|
|
|
(let* ((m (car date)) ; month
|
|
|
|
(d (nth 1 date)) ; day
|
|
|
|
(y (nth 2 date)) ; year
|
|
|
|
(annivs (gethash (list m d) org-bbdb-anniv-hash))
|
|
|
|
(text ())
|
2009-01-26 03:42:33 -05:00
|
|
|
rec recs)
|
2008-12-04 09:33:43 -05:00
|
|
|
|
2008-05-06 06:46:51 -04:00
|
|
|
;; we don't want to miss people born on Feb. 29th
|
2008-10-06 14:45:02 -04:00
|
|
|
(when (and (= m 3) (= d 1)
|
|
|
|
(not (null (gethash (list 2 29) org-bbdb-anniv-hash)))
|
|
|
|
(not (calendar-leap-year-p y)))
|
|
|
|
(setq recs (gethash (list 2 29) org-bbdb-anniv-hash))
|
|
|
|
(while (setq rec (pop recs))
|
|
|
|
(push rec annivs)))
|
2008-05-06 06:46:51 -04:00
|
|
|
|
|
|
|
(when annivs
|
|
|
|
(while (setq rec (pop annivs))
|
2008-12-04 09:33:43 -05:00
|
|
|
(when rec
|
2008-05-06 06:46:51 -04:00
|
|
|
(let* ((class (or (nth 2 rec)
|
|
|
|
org-bbdb-default-anniversary-format))
|
2010-08-12 05:03:07 -04:00
|
|
|
(form (or (cdr (assoc-string
|
|
|
|
class org-bbdb-anniversary-format-alist t))
|
2008-05-06 06:46:51 -04:00
|
|
|
class)) ; (as format string)
|
|
|
|
(name (nth 1 rec))
|
2011-02-07 11:43:15 -05:00
|
|
|
(years (if (eq (car rec) nil)
|
|
|
|
"unknown"
|
|
|
|
(- y (car rec))))
|
|
|
|
(suffix (if (eq (car rec) nil)
|
|
|
|
""
|
|
|
|
(diary-ordinal-suffix years)))
|
2008-05-06 06:46:51 -04:00
|
|
|
(tmp (cond
|
|
|
|
((functionp form)
|
|
|
|
(funcall form name years suffix))
|
|
|
|
((listp form) (eval form))
|
|
|
|
(t (format form name years suffix)))))
|
2008-06-12 09:09:03 -04:00
|
|
|
(org-add-props tmp nil 'org-bbdb-name name)
|
2008-05-06 06:46:51 -04:00
|
|
|
(if text
|
|
|
|
(setq text (append text (list tmp)))
|
|
|
|
(setq text (list tmp)))))
|
|
|
|
))
|
2010-10-24 16:01:47 -04:00
|
|
|
text))
|
2008-04-24 04:29:47 -04:00
|
|
|
|
2009-05-10 02:51:18 -04:00
|
|
|
(defun org-bbdb-complete-link ()
|
|
|
|
"Read a bbdb link with name completion."
|
2009-05-10 03:15:13 -04:00
|
|
|
(require 'bbdb-com)
|
2009-05-10 02:51:18 -04:00
|
|
|
(concat "bbdb:"
|
|
|
|
(bbdb-record-name (car (bbdb-completing-read-record "Name: ")))))
|
|
|
|
|
2009-06-11 11:42:28 -04:00
|
|
|
(defun org-bbdb-anniv-export-ical ()
|
2009-06-11 16:18:47 -04:00
|
|
|
"Extract anniversaries from BBDB and convert them to icalendar format."
|
|
|
|
(require 'bbdb)
|
|
|
|
(require 'diary-lib)
|
|
|
|
(unless (hash-table-p org-bbdb-anniv-hash)
|
|
|
|
(setq org-bbdb-anniv-hash
|
2009-06-11 11:42:28 -04:00
|
|
|
(make-hash-table :test 'equal :size 366)))
|
2009-06-11 16:18:47 -04:00
|
|
|
(when (or org-bbdb-updated-p
|
|
|
|
(= 0 (hash-table-count org-bbdb-anniv-hash)))
|
|
|
|
(org-bbdb-make-anniv-hash))
|
|
|
|
(maphash 'org-bbdb-format-vevent org-bbdb-anniv-hash))
|
|
|
|
|
|
|
|
(defun org-bbdb-format-vevent (key recs)
|
|
|
|
(let (rec categ)
|
|
|
|
(while (setq rec (pop recs))
|
2009-06-22 15:59:21 -04:00
|
|
|
(setq categ (or (nth 2 rec) org-bbdb-default-anniversary-format))
|
2009-06-11 16:18:47 -04:00
|
|
|
(princ (format "BEGIN:VEVENT
|
2009-06-11 11:42:28 -04:00
|
|
|
UID: ANNIV-%4i%02i%02i-%s
|
|
|
|
DTSTART:%4i%02i%02i
|
2009-06-22 15:59:21 -04:00
|
|
|
SUMMARY:%s
|
|
|
|
DESCRIPTION:%s
|
|
|
|
CATEGORIES:%s
|
|
|
|
RRULE:FREQ=YEARLY
|
|
|
|
END:VEVENT\n"
|
|
|
|
(nth 0 rec) (nth 0 key) (nth 1 key)
|
2009-06-11 16:18:47 -04:00
|
|
|
(mapconcat 'identity
|
|
|
|
(org-split-string (nth 1 rec) "[^a-zA-Z0-90]+")
|
|
|
|
"-")
|
2009-06-22 15:59:21 -04:00
|
|
|
(nth 0 rec) (nth 0 key) (nth 1 key)
|
2009-08-03 11:30:30 -04:00
|
|
|
(nth 1 rec)
|
2009-06-22 15:59:21 -04:00
|
|
|
(concat (capitalize categ) " " (nth 1 rec))
|
2009-06-23 12:20:30 -04:00
|
|
|
categ)))))
|
2009-06-11 11:42:28 -04:00
|
|
|
|
2008-03-14 13:22:03 -04:00
|
|
|
(provide 'org-bbdb)
|
|
|
|
|
|
|
|
;;; org-bbdb.el ends here
|