Subject: Re: bug#19678: [PATCH] EUDC does not support BBDB 3.x

From: Thomas Fitzsimmons <[email-masked]>
Date: Sun, 25 Jan 2015 18:49:56 -0500

Sergio Durigan Junior <[email-masked]> writes:

> This bug was opened due to a request made at:
>
>   <https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00800.html>
>
> As explained at:
>
>   <https://lists.gnu.org/archive/html/emacs-devel/2015-01/msg00542.html>
>
> With the release of BBDB 3.x, EUDC needs adjustments to properly work
> with it.  Actually, after some investigation, I noticed that the only
> adjustment was to replace the occurrences of 'net' by 'mail' in the
> code.  The second link above contains a patch that does that, but Thomas
> Fitzsimmons correctly noted (in the first link) that the patch breaks
> compatibility with BBDB 2.x.
>
> The following patch is a first attempt to implement the support for both
> BBDB 2.x and 3.x.

Can you see if the attached patch works for you?  It works for me,
introduces minimal changes and allows for upgrading BBDB 2 to BBDB 3
without restarting Emacs.  The defvar change in your patch concerns me
because it will miss if the BBDB version changes after the variable is
first assigned.

I'm also going to experiment with eudc-export which also may need to be
updated for BBDB 3 handling.

Longer term I hope to work toward bundling BBDB in Emacs which would
eliminate the need to support multiple versions.

Thomas
>From 34dbaf966d2875c1f129f35c9866122f88e0ac16 Mon Sep 17 00:00:00 2001
From: Thomas Fitzsimmons <[email-masked]>
Date: Sun, 25 Jan 2015 01:32:52 -0500
Subject: [PATCH 1/2] EUDC: Support BBDB >= 3

* net/eudcb-bbdb.el (eudc-bbdb-field): New function.
(eudc-bbdb-filter-non-matching-record): Call eudc-bbdb-field.
(eudc-bbdb-format-record-as-result): Likewise.
---
 lisp/ChangeLog         |  6 ++++++
 lisp/net/eudcb-bbdb.el | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 70293af..e26e028 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
+2015-01-25  Thomas Fitzsimmons  <[email-masked]>
+
+	* net/eudcb-bbdb.el (eudc-bbdb-field): New function.
+	(eudc-bbdb-filter-non-matching-record): Call eudc-bbdb-field.
+	(eudc-bbdb-format-record-as-result): Likewise.
+
 2015-01-25  Stefan Monnier  <[email-masked]>
 
 	* emacs-lisp/cl-generic.el (cl--generic-no-next-method-function): New fun.
diff --git a/lisp/net/eudcb-bbdb.el b/lisp/net/eudcb-bbdb.el
index 0400e5b..7aed542 100644
--- a/lisp/net/eudcb-bbdb.el
+++ b/lisp/net/eudcb-bbdb.el
@@ -41,6 +41,16 @@
 (defvar eudc-bbdb-current-query nil)
 (defvar eudc-bbdb-current-return-attributes nil)
 
+(defun eudc-bbdb-field (field-symbol)
+  "Convert FIELD-SYMBOL so that it is recognized by the current BBDB version.
+BBDB < 3 used `net'; BBDB >= 3 uses `mail'."
+  ;; This just-in-time translation permits upgrading from BBDB 2 to
+  ;; BBDB 3 without restarting Emacs.
+  (if (and (eq field-symbol 'net)
+	   (version<= "3" bbdb-version))
+      'mail
+    field-symbol))
+
 (defvar eudc-bbdb-attributes-translation-alist
   '((name . lastname)
     (email . net)
@@ -84,7 +94,9 @@
                    (progn
                      (setq bbdb-val
                            (eval (list (intern (concat "bbdb-record-"
-                                                       (symbol-name attr)))
+                                                       (symbol-name
+                                                        (eudc-bbdb-field
+                                                         attr))))
                                        'record)))
                      (if (listp bbdb-val)
                          (if eudc-bbdb-enable-substring-matches
@@ -167,7 +179,7 @@ The record is filtered according to `eudc-bbdb-current-return-attributes'"
 	(setq val (eval
 		   (list (intern
 			  (concat "bbdb-record-"
-				  (symbol-name attr)))
+				  (symbol-name (eudc-bbdb-field attr))))
 			 'record))))
        (t
 	(error "Unknown BBDB attribute")))
-- 
1.8.1.4