emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: With lexical-binding t, how do I bind an external symbol dynamicall?


From: Philipp Stephani
Subject: Re: With lexical-binding t, how do I bind an external symbol dynamicall?
Date: Sat, 29 Aug 2015 17:30:20 +0000



Alan Mackenzie <address@hidden> schrieb am Sa., 29. Aug. 2015 um 18:34 Uhr:
Hello, Emacs!

In some Elisp with no knowledge of the variable `some-flag', which will
be defined elsewhere, I want to write

        (let (some-flag) ....)

to bind `some-flag' dynamically.  The byte-compiler give me the warning:

    Unused lexical variable `some-flag'

.  Somehow, I need to tell the byte-compiler that `some-flag' will be an
external dynamic variable.  How do I do this?


Use (defvar some-flag) before using some-flag. That will do nothing except marking some-flag as special (dynamic).
 
I've had a look around the "Variables" page, and its sub-pages, in the
elisp manual, yet didn't find any instructions on how to get round this
problem.  Where in the manual is it described?


It's mentioned in 16.6 Compiler Errors, but without mentioning dynamic binding. I discovered the behavior by looking at the Emacs source code; but this should be stated more prominently in the Elisp manual because it can lead to subtle errors if the warning is ignored or silenced.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]