diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/elisp/using-lexical-binding.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/elisp/using-lexical-binding.html')
| -rw-r--r-- | devdocs/elisp/using-lexical-binding.html | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/devdocs/elisp/using-lexical-binding.html b/devdocs/elisp/using-lexical-binding.html deleted file mode 100644 index 3607b0f3..00000000 --- a/devdocs/elisp/using-lexical-binding.html +++ /dev/null @@ -1,29 +0,0 @@ - <h4 class="subsection">Using Lexical Binding</h4> <p>When loading an Emacs Lisp file or evaluating a Lisp buffer, lexical binding is enabled if the buffer-local variable <code>lexical-binding</code> is non-<code>nil</code>: </p> <dl> <dt id="lexical-binding">Variable: <strong>lexical-binding</strong> -</dt> <dd><p>If this buffer-local variable is non-<code>nil</code>, Emacs Lisp files and buffers are evaluated using lexical binding instead of dynamic binding. (However, special variables are still dynamically bound; see below.) If <code>nil</code>, dynamic binding is used for all local variables. This variable is typically set for a whole Emacs Lisp file, as a file local variable (see <a href="file-local-variables">File Local Variables</a>). Note that unlike other such variables, this one must be set in the first line of a file. </p></dd> -</dl> <p>When evaluating Emacs Lisp code directly using an <code>eval</code> call, lexical binding is enabled if the <var>lexical</var> argument to <code>eval</code> is non-<code>nil</code>. See <a href="eval">Eval</a>. </p> <p>Lexical binding is also enabled in Lisp Interaction and IELM mode, used in the <samp>*scratch*</samp> and <samp>*ielm*</samp> buffers, and also when evaluating expressions via <kbd>M-:</kbd> (<code>eval-expression</code>) and when processing the <samp>--eval</samp> command-line options of Emacs (see <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Action-Arguments.html#Action-Arguments">Action Arguments</a> in <cite>The GNU Emacs Manual</cite>) and <code>emacsclient</code> (see <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/emacsclient-Options.html#emacsclient-Options">emacsclient Options</a> in <cite>The GNU Emacs Manual</cite>). </p> <p>Even when lexical binding is enabled, certain variables will continue to be dynamically bound. These are called <em>special variables</em>. Every variable that has been defined with <code>defvar</code>, <code>defcustom</code> or <code>defconst</code> is a special variable (see <a href="defining-variables">Defining Variables</a>). All other variables are subject to lexical binding. </p> <p>Using <code>defvar</code> without a value, it is possible to bind a variable dynamically just in one file, or in just one part of a file while still binding it lexically elsewhere. For example: </p> <div class="example"> <pre class="example">(let (_) - (defvar x) ; <span class="roman">Let-bindings of <code>x</code> will be dynamic within this let.</span> - (let ((x -99)) ; <span class="roman">This is a dynamic binding of <code>x</code>.</span> - (defun get-dynamic-x () - x))) - -(let ((x 'lexical)) ; <span class="roman">This is a lexical binding of <code>x</code>.</span> - (defun get-lexical-x () - x)) - -(let (_) - (defvar x) - (let ((x 'dynamic)) - (list (get-lexical-x) - (get-dynamic-x)))) - ⇒ (lexical dynamic) -</pre> -</div> <dl> <dt id="special-variable-p">Function: <strong>special-variable-p</strong> <em>symbol</em> -</dt> <dd> -<p>This function returns non-<code>nil</code> if <var>symbol</var> is a special variable (i.e., it has a <code>defvar</code>, <code>defcustom</code>, or <code>defconst</code> variable definition). Otherwise, the return value is <code>nil</code>. </p> <p>Note that since this is a function, it can only return non-<code>nil</code> for variables which are permanently special, but not for those that are only special in the current lexical scope. </p> -</dd> -</dl> <p>The use of a special variable as a formal argument in a function is not supported. </p><div class="_attribution"> - <p class="_attribution-p"> - Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> - <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Binding.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Binding.html</a> - </p> -</div> |
