Subject: bug#39373: 27.0.50; [PATCH] mode-local-print-bindings broken with lexical-binding

From: Mattias Engdegård <[email-masked]>
Date: Fri, 31 Jan 2020 21:51:48 +0100

31 jan. 2020 kl. 21.25 skrev Eli Zaretskii <[email-masked]>:

> That's not the "usual" way of fixing problems with lexical-binding,
> and it isn't immediately clear to me why that fixes the problem.

'add-to-list' doesn't work on lexical variables because it's a plain function taking the variable symbol as argument. 'push' works on lexical variables since it is a macro that expands to direct variable reference and setq. I should perhaps have included this in the commit message.

Happily, Emacs provides generalised variable support for 'if' and 'cons', so that they can be used as target for 'push'.

We could sink the pushes to the leaves of the condition tree, if you prefer:

(cond ((get s 'mode-variable-flag)
       (if (get s 'constant-flag) (push s mc) (push s mv)))
      ((get s 'override-flag)
       (if (get s 'constant-flag) (push s fo) (push s ov)))
      (t (push s us)))

Not as elegant or concise, but does not rely on if and cond as GVs in push.