summaryrefslogtreecommitdiff
path: root/lisp/org/org-bbdb.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/org-bbdb.el')
-rw-r--r--lisp/org/org-bbdb.el84
1 files changed, 59 insertions, 25 deletions
diff --git a/lisp/org/org-bbdb.el b/lisp/org/org-bbdb.el
index 8401196c81a..3df4c2044e9 100644
--- a/lisp/org/org-bbdb.el
+++ b/lisp/org/org-bbdb.el
@@ -1,12 +1,11 @@
;;; org-bbdb.el --- Support for links to BBDB entries from within Org-mode
-;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten at orgmode dot org>,
;; Thomas Baumann <thomas dot baumann at ch dot tum dot de>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
-;; Version: 7.7
;;
;; This file is part of GNU Emacs.
;;
@@ -113,11 +112,20 @@
(&optional dont-check-disk already-in-db-buffer))
(declare-function bbdb-split "ext:bbdb" (string separators))
(declare-function bbdb-string-trim "ext:bbdb" (string))
+(declare-function bbdb-record-get-field "ext:bbdb"
+ (fn file &optional arglist fileonly))
+;; These two functions below are part of BBDB3:
+(declare-function bbdb-search-name "ext:bbdb" (regexp &optional layout))
+(declare-function bbdb-search-organization "ext:bbdb" (regexp &optional layout))
(declare-function calendar-leap-year-p "calendar" (year))
(declare-function diary-ordinal-suffix "diary-lib" (n))
(defvar date) ;; dynamically scoped from Org
+(defvar name) ;; dynamically scoped from Org
+
+;; Support for version 2.35
+(defvar org-bbdb-old (fboundp 'bbdb-record-get-field-internal))
;; Customization
@@ -196,8 +204,11 @@ date year)."
"Store a link to a BBDB database entry."
(when (eq major-mode 'bbdb-mode)
;; This is BBDB, we make this link!
- (let* ((name (bbdb-record-name (bbdb-current-record)))
- (company (bbdb-record-getprop (bbdb-current-record) 'company))
+ (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))))
(link (org-make-link "bbdb:" name)))
(org-store-link-props :type "bbdb" :name name :company company
:link link :description name)
@@ -219,24 +230,49 @@ italicized, in all other cases it is left unchanged."
(require 'bbdb)
(let ((inhibit-redisplay (not debug-on-error))
(bbdb-electric-p nil))
- (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")))))
+ (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"))))
(defun org-bbdb-anniv-extract-date (time-str)
"Convert YYYY-MM-DD to (month date year).
@@ -357,7 +393,7 @@ This is used by Org to re-create the anniversary hash table."
(bbdb-record-name (car (bbdb-completing-read-record "Name: ")))))
(defun org-bbdb-anniv-export-ical ()
- "Extract anniversaries from BBDB and convert them to iCalendar format."
+ "Extract anniversaries from BBDB and convert them to icalendar format."
(require 'bbdb)
(require 'diary-lib)
(unless (hash-table-p org-bbdb-anniv-hash)
@@ -391,6 +427,4 @@ END:VEVENT\n"
(provide 'org-bbdb)
-
-
;;; org-bbdb.el ends here