RE: bbdb-print.el lexical binding breaks bbdb-print-record

Vincent Belaïche <[email protected]>
Newsgroups gmane.emacs.bbdb.user
Message-ID <AM5PR10MB0676F058F15683DD4ED32CD484D20@AM5PR10MB0676.EURPRD10.PROD.OUTLOOK.COM>
Ooops... there was some mistake in the code based on cl-progv which I supplied. Just to be 100% clear about this alternative solution, it would be as in the attached patch bug-1.diff.


   V.

________________________________
De : Vincent Belaïche <[email protected]>
Envoyé : jeudi 29 juin 2017 13:24:53
À : Roland Winkler; BBDB info list
Objet : bbdb-print.el lexical binding breaks bbdb-print-record

Hello Roland,

With lexical binding bbdb-print-record makes a void variable error on address variable.

Attached is a fix. I use a lambda expression to make the binding dynmical so that bbdb-print-require can be evalled in the correct context. An alternative fix would have been to use :

(cl-progv '(first-letter name organization mail phone address xfields) (list first-letter name organization mail phone address xfields)).

Well, to avoid any duplication in this case, it would be better to use some macro like this:

(defmacro bbdb-do-cl-progv (&rest l)
   `(cl-progv (quote ,l) (list ,@l)))

and then in bdbd-print-record:

(bbdb-do-cl-progv first-letter name organization mail phone address xfields)(list first-letter name organization mail phone address xfields)

Anyway, I prefer the lambda trick, I don't like cl-progv and eval. Probably lambdas are more portable to old Emacs versions.

  Vincent.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
[email protected]
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/
bug-1.diff (application/octet-stream, 1 KB)
diff --git a/lisp/bbdb-print.el b/lisp/bbdb-print.el
index f2efef1..5decf37 100644
--- a/lisp/bbdb-print.el
+++ b/lisp/bbdb-print.el
@@ -401,6 +401,9 @@ of the printout, notably the variables `bbdb-print-alist' and
     (goto-char (point-min)))
   (message "Process this file with TeX (not LaTeX)"))
 
+(defmacro bbdb-do-cl-progv (vars &rest body)
+   `(cl-progv (quote ,vars) (list ,@vars) ,@body))
+
 (defun bbdb-print-record (record current-letter
                                  brief pofl n-phones n-addresses)
   "Insert the bbdb RECORD in TeX format in the current buffer.
@@ -437,7 +440,7 @@ The return value is the new CURRENT-LETTER."
         (xfields (bbdb-record-xfields record))
         (bbdb-address-format-list bbdb-print-address-format-list))
 
-    (when (eval bbdb-print-require)
+    (when (bbdb-do-cl-progv (first-letter name organization mail phone address xfields) (eval bbdb-print-require))
       ;; Insert section header, if neccessary.
       (if (or (eq current-letter t)
               (not (string-equal first-letter current-letter)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.