unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Free variable warning about bbdb-version (bug#19678)
@ 2015-03-06  8:48 Thomas Fitzsimmons
  2015-03-06  9:09 ` Tassilo Horn
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Thomas Fitzsimmons @ 2015-03-06  8:48 UTC (permalink / raw)
  To: emacs-devel

Hi,

I'm trying to make eudcb-bbdb.el compatible with BBDB 2 and BBDB 3.  To
check the version, I need something like:

(if (version<= "3" bbdb-version) ...)

but the byte compiler warns:

Warning: reference to free variable `bbdb-version'

I'd rather not introduce a new warning.  Is there a good way to handle
this?  Adding (defvar bbdb-version) to eudcb-bbdb.el seems wrong, since
the version check is assuming it's a constant defined by the external
BBDB package.

(The best solution would be to bundle BBDB 3 into Emacs -- I'm working
toward this with Roland Winkler.)

Thanks,
Thomas



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-06  8:48 Free variable warning about bbdb-version (bug#19678) Thomas Fitzsimmons
@ 2015-03-06  9:09 ` Tassilo Horn
  2015-03-06 17:42 ` Stefan Monnier
  2015-03-07 17:27 ` Roland Winkler
  2 siblings, 0 replies; 7+ messages in thread
From: Tassilo Horn @ 2015-03-06  9:09 UTC (permalink / raw)
  To: Thomas Fitzsimmons; +Cc: emacs-devel

Thomas Fitzsimmons <fitzsim@fitzsim.org> writes:

Hi Thomas,

> I'm trying to make eudcb-bbdb.el compatible with BBDB 2 and BBDB 3.
> To check the version, I need something like:
>
> (if (version<= "3" bbdb-version) ...)
>
> but the byte compiler warns:
>
> Warning: reference to free variable `bbdb-version'
>
> I'd rather not introduce a new warning.  Is there a good way to handle
> this?  Adding (defvar bbdb-version) to eudcb-bbdb.el seems wrong,
> since the version check is assuming it's a constant defined by the
> external BBDB package.

(defvar bbdb-version) is exactly what you are looking for.  The defvar
without init-value just tells the byte-compiler that you make sure this
variable will be there at the right time so he hasn't to worry about it.

,----[ (info "(elisp)Warning Tips") ]
|    • Try to avoid compiler warnings about undefined free variables, by
|      adding dummy ‘defvar’ definitions for these variables, like this:
| 
|           (defvar foo)
| 
|      Such a definition has no effect except to tell the compiler not to
|      warn about uses of the variable ‘foo’ in this file.
`----

Since you require bbdb on top of the file anyway, you can be sure that
`bbdb-version' is correctly initialized from the external bbdb package
when the version check takes place.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-06  8:48 Free variable warning about bbdb-version (bug#19678) Thomas Fitzsimmons
  2015-03-06  9:09 ` Tassilo Horn
@ 2015-03-06 17:42 ` Stefan Monnier
  2015-03-07 17:27 ` Roland Winkler
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2015-03-06 17:42 UTC (permalink / raw)
  To: Thomas Fitzsimmons; +Cc: emacs-devel

> (if (version<= "3" bbdb-version) ...)

BTW, in many cases instead of checking such a version variable, you can
use a test of the form (fboundp '<somefunctionyouneed>).


        Stefan



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-06  8:48 Free variable warning about bbdb-version (bug#19678) Thomas Fitzsimmons
  2015-03-06  9:09 ` Tassilo Horn
  2015-03-06 17:42 ` Stefan Monnier
@ 2015-03-07 17:27 ` Roland Winkler
  2015-03-08  2:10   ` Thomas Fitzsimmons
  2 siblings, 1 reply; 7+ messages in thread
From: Roland Winkler @ 2015-03-07 17:27 UTC (permalink / raw)
  To: emacs-devel

On Fri, Mar 06 2015, Thomas Fitzsimmons wrote:
> I'm trying to make eudcb-bbdb.el compatible with BBDB 2 and BBDB 3.

I guess I would not try to be compatible with both versions.

Roland




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-07 17:27 ` Roland Winkler
@ 2015-03-08  2:10   ` Thomas Fitzsimmons
  2015-03-08  3:14     ` Roland Winkler
  0 siblings, 1 reply; 7+ messages in thread
From: Thomas Fitzsimmons @ 2015-03-08  2:10 UTC (permalink / raw)
  To: Roland Winkler; +Cc: emacs-devel

Roland Winkler <winkler@gnu.org> writes:

> On Fri, Mar 06 2015, Thomas Fitzsimmons wrote:
>> I'm trying to make eudcb-bbdb.el compatible with BBDB 2 and BBDB 3.
>
> I guess I would not try to be compatible with both versions.

Do you see any harm in being compatible with both versions?  The patch
is already written and tested, so I figure I might as well push it.

Thomas



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-08  2:10   ` Thomas Fitzsimmons
@ 2015-03-08  3:14     ` Roland Winkler
  2015-03-08 16:00       ` Thomas Fitzsimmons
  0 siblings, 1 reply; 7+ messages in thread
From: Roland Winkler @ 2015-03-08  3:14 UTC (permalink / raw)
  To: Thomas Fitzsimmons; +Cc: emacs-devel

> > I guess I would not try to be compatible with both versions.
> 
> Do you see any harm in being compatible with both versions?  The
> patch is already written and tested, so I figure I might as well
> push it.

No, I do not see any (direct) harm.  Merely, I find that such things
can significantly decrease readability of the code and thus make
maintanence more difficult.  (Yet I do not know how intensely the
code you talk about is linked to BBDB.  With just a few function
calls from BBDB there should not be too much a problem.)

Also, features in BBDB 3 have been significantly expanded.  I do not
know either whether your code might benefit from that.

Roland



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Free variable warning about bbdb-version (bug#19678)
  2015-03-08  3:14     ` Roland Winkler
@ 2015-03-08 16:00       ` Thomas Fitzsimmons
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Fitzsimmons @ 2015-03-08 16:00 UTC (permalink / raw)
  To: Roland Winkler; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]

"Roland Winkler" <winkler@gnu.org> writes:

>> > I guess I would not try to be compatible with both versions.
>> 
>> Do you see any harm in being compatible with both versions?  The
>> patch is already written and tested, so I figure I might as well
>> push it.
>
> No, I do not see any (direct) harm.  Merely, I find that such things
> can significantly decrease readability of the code and thus make
> maintanence more difficult.  (Yet I do not know how intensely the
> code you talk about is linked to BBDB.  With just a few function
> calls from BBDB there should not be too much a problem.)

The patch isn't too bad (see attached), but the version check is ugly.
I'm trying to make the 2.x to 3.x transition as smooth as possible for
EUDC users.

I agree that it would nice to be able to avoid this type of check.
There are lots of references to BBDB throughout Emacs that might have
version dependencies though.  That's why, once the copyrights are clear,
I'd like to see BBDB bundled in Emacs, rather than added to GNU ELPA.
Is that the plan?  Are the Emacs maintainers on board with bundling?

> Also, features in BBDB 3 have been significantly expanded.  I do not
> know either whether your code might benefit from that.

For now, I'm just trying to maintain status quo for eudcb-bbdb.el.
If/when your BBDB version is bundled it'll be easier to take advantage
of the new features.

Thomas

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bbdb-version-check.patch --]
[-- Type: text/x-patch, Size: 2005 bytes --]

diff --git a/lisp/net/eudcb-bbdb.el b/lisp/net/eudcb-bbdb.el
index 5be2bec..bd5d453 100644
--- a/lisp/net/eudcb-bbdb.el
+++ b/lisp/net/eudcb-bbdb.el
@@ -42,6 +42,24 @@ (require 'bbdb-com nil t)
 (defvar eudc-bbdb-current-query nil)
 (defvar eudc-bbdb-current-return-attributes nil)
 
+(defvar bbdb-version)
+
+(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)
+	   (or
+	    ;; MELPA versions of BBDB may have a bad package version,
+	    ;; but they're all version 3 or later.
+	    (equal bbdb-version "@PACKAGE_VERSION@")
+	    ;; Development versions of BBDB can have the format "X.YZ
+	    ;; devo".  Split the string just in case.
+	    (version<= "3" (car (split-string bbdb-version)))))
+      'mail
+    field-symbol))
+
 (defvar eudc-bbdb-attributes-translation-alist
   '((name . lastname)
     (email . net)
@@ -85,7 +103,9 @@ (defun eudc-bbdb-filter-non-matching-record (record)
                    (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
@@ -168,7 +188,7 @@ (defun eudc-bbdb-format-record-as-result (record)
 	(setq val (eval
 		   (list (intern
 			  (concat "bbdb-record-"
-				  (symbol-name attr)))
+				  (symbol-name (eudc-bbdb-field attr))))
 			 'record))))
        (t
 	(error "Unknown BBDB attribute")))

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-08 16:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-06  8:48 Free variable warning about bbdb-version (bug#19678) Thomas Fitzsimmons
2015-03-06  9:09 ` Tassilo Horn
2015-03-06 17:42 ` Stefan Monnier
2015-03-07 17:27 ` Roland Winkler
2015-03-08  2:10   ` Thomas Fitzsimmons
2015-03-08  3:14     ` Roland Winkler
2015-03-08 16:00       ` Thomas Fitzsimmons

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).