;;; eudc-export.el --- functions to export EUDC query results
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2016 Free Software Foundation, Inc.
;; Author: Oscar Figueiredo <oscar@cpe.fr>
-;; Maintainer: Pavel Janík <Pavel@Janik.cz>
+;; Pavel Janík <Pavel@Janik.cz>
+;; Maintainer: Thomas Fitzsimmons <fitzsim@fitzsim.org>
;; Keywords: comm
+;; Package: eudc
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, 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
;; 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.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(require 'eudc)
-(if (not (featurep 'bbdb))
- (load-library "bbdb"))
-(if (not (featurep 'bbdb-com))
- (load-library "bbdb-com"))
+;; NOERROR is so we can compile it.
+(require 'bbdb nil t)
+(require 'bbdb-com nil t)
(defun eudc-create-bbdb-record (record &optional silent)
"Create a BBDB record using the RECORD alist.
RECORD is an alist of (KEY . VALUE) where KEY is a directory attribute name
symbol and VALUE is the corresponding value for the record.
If SILENT is non-nil then the created BBDB record is not displayed."
+ (require 'bbdb)
;; This function runs in a special context where lisp symbols corresponding
;; to field names in record are bound to the corresponding values
(eval
- `(let* (,@(mapcar '(lambda (c)
+ `(let* (,@(mapcar (lambda (c)
(list (car c) (if (listp (cdr c))
(list 'quote (cdr c))
(cdr c))))
(cons (car mapping) value))))
conversion-alist)))
(setq bbdb-notes (delq nil bbdb-notes))
- (setq bbdb-record (bbdb-create-internal bbdb-name
- bbdb-company
- bbdb-net
- bbdb-address
- bbdb-phones
- bbdb-notes))
+ (setq bbdb-record (bbdb-create-internal
+ bbdb-name
+ ,@(when (eudc--using-bbdb-3-or-newer-p)
+ '(nil
+ nil))
+ bbdb-company
+ bbdb-net
+ ,@(if (eudc--using-bbdb-3-or-newer-p)
+ '(bbdb-phones
+ bbdb-address)
+ '(bbdb-address
+ bbdb-phones))
+ bbdb-notes))
(or silent
(bbdb-display-records (list bbdb-record))))))
(void-variable nil)))
((and recurse
(listp spec))
- (mapcar '(lambda (spec-elem)
+ (mapcar (lambda (spec-elem)
(eudc-parse-spec spec-elem record nil))
spec))
(t
zip city state)
(setq addr-components (nreverse addr-components))
;; If not containing the zip code the last line is supposed to contain a
- ;; country name and the addres is supposed to be in european style
+ ;; country name and the address is supposed to be in european style
(if (not (string-match "[0-9][0-9][0-9]" last1))
(progn
(setq state last1)
(or state "")
zip)))
+;; External.
+(declare-function bbdb-parse-phone-number "ext:bbdb-com"
+ (string &optional number-type))
+(declare-function bbdb-parse-phone "ext:bbdb-com" (string &optional style))
+(declare-function bbdb-string-trim "ext:bbdb" (string))
+
+(defun eudc-bbdbify-company (&rest organizations)
+ "Return ORGANIZATIONS as a list compatible with BBDB."
+ organizations)
+
(defun eudc-bbdbify-phone (phone location)
"Parse PHONE into a vector compatible with BBDB.
PHONE is either a string supposedly containing a phone number or
a list of such strings which are concatenated.
LOCATION is used as the phone location for BBDB."
+ (require 'bbdb)
(cond
((stringp phone)
(let (phone-list)
(condition-case err
- (setq phone-list (bbdb-parse-phone-number phone))
+ (setq phone-list (if (eudc--using-bbdb-3-or-newer-p)
+ (bbdb-parse-phone phone)
+ (bbdb-parse-phone-number phone)))
(error
- (if (string= "phone number unparsable." (eudc-cadr err))
+ (if (string= "phone number unparsable." (cadr err))
(if (not (y-or-n-p (format "BBDB claims %S to be unparsable--insert anyway? " phone)))
(error "Phone number unparsable")
(setq phone-list (list (bbdb-string-trim phone))))
(defun eudc-batch-export-records-to-bbdb ()
"Insert all the records returned by a directory query into BBDB."
(interactive)
+ (require 'bbdb)
(goto-char (point-min))
(let ((nbrec 0)
record)
"Insert record at point into the BBDB database.
This function can only be called from a directory query result buffer."
(interactive)
+ (require 'bbdb)
(let ((record (and (overlays-at (point))
(overlay-get (car (overlays-at (point))) 'eudc-record))))
(if (null record)
(defun eudc-try-bbdb-insert ()
"Call `eudc-insert-record-at-point-into-bbdb' if on a record."
(interactive)
- (and (or (featurep 'bbdb)
- (prog1 (locate-library "bbdb") (message "")))
- (overlays-at (point))
+ (require 'bbdb)
+ (and (overlays-at (point))
(overlay-get (car (overlays-at (point))) 'eudc-record)
(eudc-insert-record-at-point-into-bbdb)))
-;;; arch-tag: 8cbda7dc-3163-47e6-921c-6ec5083df2d7
;;; eudc-export.el ends here