org-bbdb.el 3.5 KB

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