joaotavora / yasnippet

A template system for Emacs
http://joaotavora.github.io/yasnippet/
2.81k stars 311 forks source link

Allow closures in yas-buffer-local-condition #1184

Closed martenlienen closed 10 months ago

martenlienen commented 10 months ago

The change in introduced in 1d0966a checks if yas-buffer-local-condition is a cons before a function but lambdas in lexical environments get converted to closures which are also conses.

ELISP> (setq x (lambda () "hello"))
(closure
    (t)
    nil "hello")

ELISP> (consp x)
t
ELISP> (functionp x)
t
ELISP> (eval x)
Debugger entered--Lisp error: (void-function closure)

This commit checks for functions first, to avoid evaling closures inadvertently. At the moment, yasnippet is broken if you have, e.g.

(setq-default yas-buffer-local-condition yas-not-string-or-comment-condition)
monnier commented 10 months ago

Duh, of course, thanks. Even for good 'old (lambda ...) values the patch is needed (it wouldn't signal an error, but it would still not return the intended value).