From: Eli Zaretskii Date: Sat, 3 May 2025 13:26:44 +0000 (+0300) Subject: Avoid warnings about 'lexical-binding' in 'eval-buffer' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d06feebb438cc3ad780b9bc0a73b405c4f232dd2;p=emacs.git Avoid warnings about 'lexical-binding' in 'eval-buffer' * src/lread.c (Feval_buffer): Don't emit a lexbind warning if the buffer already has a local value of 'lexical-binding'. Doc fix. (Bug#77883) (cherry picked from commit 8a097aede53dfb8f595d79824c784c188b210093) --- diff --git a/src/lread.c b/src/lread.c index 5c8bbe7da9f..95c9e711130 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2589,11 +2589,14 @@ DO-ALLOW-PRINT, if non-nil, specifies that output functions in the evaluated code should work normally even if PRINTFLAG is nil, in which case the output is displayed in the echo area. -This function ignores the current value of the `lexical-binding' -variable. Instead it will heed any +This function ignores the global value of the `lexical-binding' +variable. Instead it will heed the buffer-local value of that +variable and any -*- lexical-binding: t -*- -settings in the buffer, and if there is no such setting, the buffer -will be evaluated without lexical binding. +settings in the buffer; if there is no such setting, and the +buffer-local value of the variable is nil, the buffer will be +evaluated with the value of `lexical binding' equal to its +top-level default value, as returned by `default-toplevel-value'. This function preserves the position of point. */) (Lisp_Object buffer, Lisp_Object printflag, Lisp_Object filename, @@ -2621,7 +2624,10 @@ This function preserves the position of point. */) specbind (Qstandard_output, tem); record_unwind_protect_excursion (); BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); - specbind (Qlexical_binding, get_lexical_binding (buf, buf)); + /* Don't emit a warning about 'lexical-binding' if it already has a + local binding in the buffer. */ + if (NILP (Flocal_variable_p (Qlexical_binding, buf))) + specbind (Qlexical_binding, get_lexical_binding (buf, buf)); BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); readevalloop (buf, 0, filename, !NILP (printflag), unibyte, Qnil, Qnil, Qnil);