Search code examples
elisplexical-scope

Where should I add the magic comment of lexical-binding?


The first line of a .el file used to be

;;; foo.el - a foo package

Does it works if the magic comment is added after this?

;;; foo.el - a foo package
;;; -*- lexical-binding: t -*-

Or even later in the file?


Solution

    • C-hig (elisp) Using Lexical Binding
    • C-hig (emacs) Specifying File Variables

    This must be in the first line. An exception is made for shell scripts (only), where it may alternatively be on the second line.

    Note that, unlike other file-local vars, lexical-binding can only appear in this first-line listing.