Try bugfix linking mhe
[org-mode.git] / org-bbdb.el
blob8883cf8e036fdaf1f3b5ad2046fdb134fac628e1
1 ;;; org-bbdb.el - Support for links to bbdb entries in Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
8 ;; Version: 1.0
9 ;;
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file implements links to BBDB database entries for Org-mode.
31 ;; Org-mode loads this module by default - if this is not what you want,
32 ;; configure the variable `org-modules'.
34 (require 'org)
36 ;; Declare external functions and variables
37 (declare-function bbdb "ext:bbdb-com" (string elidep))
38 (declare-function bbdb-company "ext:bbdb-com" (string elidep))
39 (declare-function bbdb-current-record "ext:bbdb-com"
40 (&optional planning-on-modifying))
41 (declare-function bbdb-name "ext:bbdb-com" (string elidep))
42 (declare-function bbdb-record-getprop "ext:bbdb" (record property))
43 (declare-function bbdb-record-name "ext:bbdb" (record))
45 ;; Install the link type
46 (org-add-link-type "bbdb" 'org-bbdb-open 'org-bbdb-export)
47 (add-hook 'org-store-link-functions 'org-bbdb-store-link)
49 ;; Implementation
50 (defun org-bbdb-store-link ()
51 "Store a link to a README file."
52 (when (eq major-mode 'bbdb-mode)
53 ;; This is BBDB, we make this link!
54 (let* ((name (bbdb-record-name (bbdb-current-record)))
55 (company (bbdb-record-getprop (bbdb-current-record) 'company))
56 (link (org-make-link "bbdb:" name)))
57 (org-store-link-props :type "bbdb" :name name :company company
58 :link link :description name))))
60 (defun org-bbdb-export (path desc format)
61 "Create the exprt verison of a bbdb link."
62 (cond
63 ((eq format 'html) (format "<i>%s</i>" (or desc path)))
64 ((eq format 'latex) (format "\\textit{%s}" (or desc path)))
65 (t (or desc path))))
67 (defun org-bbdb-open (name)
68 "Follow a BBDB link to NAME."
69 (require 'bbdb)
70 (let ((inhibit-redisplay (not debug-on-error))
71 (bbdb-electric-p nil))
72 (catch 'exit
73 ;; Exact match on name
74 (bbdb-name (concat "\\`" name "\\'") nil)
75 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
76 ;; Exact match on name
77 (bbdb-company (concat "\\`" name "\\'") nil)
78 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
79 ;; Partial match on name
80 (bbdb-name name nil)
81 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
82 ;; Partial match on company
83 (bbdb-company name nil)
84 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
85 ;; General match including network address and notes
86 (bbdb name nil)
87 (when (= 0 (buffer-size (get-buffer "*BBDB*")))
88 (delete-window (get-buffer-window "*BBDB*"))
89 (error "No matching BBDB record")))))
91 (provide 'org-bbdb)
93 ;;; org-bbdb.el ends here