GNU bug report logs - #45831
28.0.50; list-colors-display callback arg needs to evaluate to a function?

Previous Next

Package: emacs;

Reported by: Mauro Aranda <maurooaranda <at> gmail.com>

Date: Tue, 12 Jan 2021 23:28:02 UTC

Severity: normal

Tags: fixed, patch

Found in version 28.0.50

Fixed in version 28.1

Done: Mauro Aranda <maurooaranda <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #16 received at 45831 <at> debbugs.gnu.org (full text, mbox):

From: Mauro Aranda <maurooaranda <at> gmail.com>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 45831 <at> debbugs.gnu.org
Subject: Re: bug#45831: 28.0.50; list-colors-display callback arg needs to
 evaluate to a function?
Date: Sat, 16 Jan 2021 08:42:19 -0300
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:

> Mauro Aranda <maurooaranda <at> gmail.com> writes:
>
>>  (defun list-colors-print (list &optional callback)
>>    (let ((callback-fn
>> -	 (if callback
>> -	     `(lambda (button)
>> -		(funcall ,callback (button-get button 'color-name))))))
>> +         ;; Expect CALLBACK to be a function, but allow it to be a form that
>> +         ;; evaluates to a function, for backward-compatibility.  (Bug#45831)
>> +         (cond ((functionp callback)
>> +                (lambda (button)
>> +                  (funcall callback (button-get button 'color-name))))
>> +               (callback
>> +                `(lambda (button)
>> +                  (funcall ,callback (button-get button 'color-name)))))))
>
> Why not a single evaluated closure, e.g. like the following?
>
>   (let ((callback-fn
>          (when callback
>            ;; Expect CALLBACK to be a function, but allow it to be a form that
>            ;; evaluates to a function, for backward-compatibility (bug#45831).
>            (or (functionp callback)
>                (setq callback (eval callback lexical-binding)))
>            (lambda (button)
>              (funcall callback (button-get button 'color-name))))))
>     ...)

Just because I didn't want to change the original code too much, in case
someone thought the backward-compatible change wasn't necessary.  But of
course, your sample code looks better.

> Thanks,

Thanks for taking a look.




This bug report was last modified 3 years and 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.