1 feb. 2020 kl. 08.48 skrev Eli Zaretskii : > If that's the case, then why don't we say that loud and clear in the > ELisp manual? (The doc string of add-to-list has some vague > recommendation, not sure if it really talks about this aspect, but > that's definitely not enough for such a serious issue.) > > And doesn't it mean we should audit all the gazillion uses of > add-to-list in our sources, and do that urgently? Yes, I agree, but it's not quite as simple as I thought at first. A mechanised scan of the source for uses of add-to-list on lexical variables revealed a handful: lisp/cedet/mode-local.el:823:23: add-to-list to lexical variable mc lisp/net/tramp-cache.el:376:45: add-to-list to lexical variable properties lisp/net/tramp-cache.el:430:25: add-to-list to lexical variable result lisp/net/zeroconf.el:259:40: add-to-list to lexical variable result lisp/net/zeroconf.el:267:40: add-to-list to lexical variable result lisp/net/zeroconf.el:281:23: add-to-list to lexical variable result lisp/org/org.el:18685:49: add-to-list to lexical variable load-uncore lisp/autoinsert.el:174:47: add-to-list to lexical variable modes lisp/whitespace.el:1687:33: add-to-list to lexical variable style test/lisp/emacs-lisp/map-tests.el:230:30: add-to-list to lexical variable result However, add-to-list has a compiler macro which tries to make it work even for lexical variables, and it mostly does -- specifically, when the LIST-VAR parameter is on the form (quote VARIABLE), which is the case in all the above cases except the one i mode-local.el. The macro (which apparently works in non-compiled code as well) attempts to warn about lexical variables but somehow this warning doesn't always trigger. I haven't researched this further. It all seems rather fragile to me, and I'd rather add a note about not using add-to-list for lexical variables to its doc string and the manual, and fix all the calls listed above. However, this last point is not strictly necessary for correctness. Two patches attached: a doc update, and a replacement of add-to-list in the cases listed above.