Make sure the link-storing function returns non-nil.
[org-mode/org-tableheadings.git] / org-bbdb.el
blob772a1fe2f3440c8e91a77d6524943d10c2df8fe3
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)
59 link)))
61 (defun org-bbdb-export (path desc format)
62 "Create the exprt verison of a bbdb link."
63 (cond
64 ((eq format 'html) (format "<i>%s</i>" (or desc path)))
65 ((eq format 'latex) (format "\\textit{%s}" (or desc path)))
66 (t (or desc path))))
68 (defun org-bbdb-open (name)
69 "Follow a BBDB link to NAME."
70 (require 'bbdb)
71 (let ((inhibit-redisplay (not debug-on-error))
72 (bbdb-electric-p nil))
73 (catch 'exit
74 ;; Exact match on name
75 (bbdb-name (concat "\\`" name "\\'") nil)
76 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
77 ;; Exact match on name
78 (bbdb-company (concat "\\`" name "\\'") nil)
79 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
80 ;; Partial match on name
81 (bbdb-name name nil)
82 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
83 ;; Partial match on company
84 (bbdb-company name nil)
85 (if (< 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
86 ;; General match including network address and notes
87 (bbdb name nil)
88 (when (= 0 (buffer-size (get-buffer "*BBDB*")))
89 (delete-window (get-buffer-window "*BBDB*"))
90 (error "No matching BBDB record")))))
92 (provide 'org-bbdb)
94 ;;; org-bbdb.el ends here