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
|
|
|
|
|
|
|
;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
2008-04-10 02:37:43 -04:00
|
|
|
;; Version: 6.00pre-5
|
2008-03-14 13:22:03 -04:00
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;; GNU Emacs 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.
|
|
|
|
|
|
|
|
;; 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
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; 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-03-21 12:10:23 -04:00
|
|
|
;;; Code:
|
|
|
|
|
2008-03-14 13:22:03 -04:00
|
|
|
(require 'org)
|
|
|
|
|
|
|
|
;; 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))
|
|
|
|
(declare-function bbdb-record-getprop "ext:bbdb" (record property))
|
|
|
|
(declare-function bbdb-record-name "ext:bbdb" (record))
|
|
|
|
|
|
|
|
;; 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!
|
|
|
|
(let* ((name (bbdb-record-name (bbdb-current-record)))
|
|
|
|
(company (bbdb-record-getprop (bbdb-current-record) 'company))
|
|
|
|
(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
|
|
|
|
italicised, in all other cases it is left unchanged."
|
2008-03-14 13:22:03 -04:00
|
|
|
"Create the exprt verison of a bbdb link."
|
|
|
|
(cond
|
|
|
|
((eq format 'html) (format "<i>%s</i>" (or desc path)))
|
|
|
|
((eq format 'latex) (format "\\textit{%s}" (or desc path)))
|
|
|
|
(t (or desc path))))
|
|
|
|
|
|
|
|
(defun org-bbdb-open (name)
|
|
|
|
"Follow a BBDB link to NAME."
|
|
|
|
(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")))))
|
|
|
|
|
|
|
|
(provide 'org-bbdb)
|
|
|
|
|
|
|
|
;;; org-bbdb.el ends here
|