aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2025-04-07 21:41:35 -0400
committerStefan Monnier2025-04-07 21:41:35 -0400
commit9f25d46568bf0a4d617145537db4c8aaf5e0219b (patch)
treefb2737b7bf42af0ec7635c20d0ff5395a0667276 /src
parent9663c959c73d6cca0c56f833d80ff1d9e9708b70 (diff)
downloademacs-9f25d46568bf0a4d617145537db4c8aaf5e0219b.tar.gz
emacs-9f25d46568bf0a4d617145537db4c8aaf5e0219b.zip
(Fload, Feval_buffer): Emit a warning when lexbind is unset (bug#74145)
This emits a warning at run-time rather than at compile time. * src/lread.c (get_lexical_binding): New function. (Fload, Feval_buffer): Use it. (syms_of_lread): New var `internal--get-default-lexical-binding-function`. * lisp/files.el: Set it. (internal--get-default-lexical-binding): New function.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/lread.c b/src/lread.c
index add8deb3954..445e5cd1fba 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1271,6 +1271,18 @@ close_file_unwind_android_fd (void *ptr)
1271 1271
1272#endif 1272#endif
1273 1273
1274static Lisp_Object
1275get_lexical_binding (Lisp_Object stream, Lisp_Object from)
1276{
1277 lexical_cookie_t lexc = lisp_file_lexical_cookie (stream);
1278 return (lexc == Cookie_Lex ? Qt
1279 : lexc == Cookie_Dyn ? Qnil
1280 : (NILP (from) /* Loading a byte-compiled file. */
1281 || NILP (Vinternal__get_default_lexical_binding_function)
1282 ? Fdefault_toplevel_value (Qlexical_binding)
1283 : calln (Vinternal__get_default_lexical_binding_function, from)));
1284}
1285
1274DEFUN ("load", Fload, Sload, 1, 5, 0, 1286DEFUN ("load", Fload, Sload, 1, 5, 0,
1275 doc: /* Execute a file of Lisp code named FILE. 1287 doc: /* Execute a file of Lisp code named FILE.
1276First try FILE with `.elc' appended, then try with `.el', then try 1288First try FILE with `.elc' appended, then try with `.el', then try
@@ -1720,11 +1732,8 @@ Return t if the file exists and loads successfully. */)
1720 } 1732 }
1721 else 1733 else
1722 { 1734 {
1723 lexical_cookie_t lexc = lisp_file_lexical_cookie (Qget_file_char);
1724 Fset (Qlexical_binding, 1735 Fset (Qlexical_binding,
1725 (lexc == Cookie_Lex ? Qt 1736 get_lexical_binding (Qget_file_char, compiled ? Qnil : file));
1726 : lexc == Cookie_Dyn ? Qnil
1727 : Fdefault_toplevel_value (Qlexical_binding)));
1728 1737
1729 if (! version || version >= 22) 1738 if (! version || version >= 22)
1730 readevalloop (Qget_file_char, &input, hist_file_name, 1739 readevalloop (Qget_file_char, &input, hist_file_name,
@@ -2609,11 +2618,7 @@ This function preserves the position of point. */)
2609 specbind (Qstandard_output, tem); 2618 specbind (Qstandard_output, tem);
2610 record_unwind_protect_excursion (); 2619 record_unwind_protect_excursion ();
2611 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); 2620 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
2612 lexical_cookie_t lexc = lisp_file_lexical_cookie (buf); 2621 specbind (Qlexical_binding, get_lexical_binding (buf, buf));
2613 specbind (Qlexical_binding,
2614 lexc == Cookie_Lex ? Qt
2615 : lexc == Cookie_Dyn ? Qnil
2616 : Fdefault_toplevel_value (Qlexical_binding));
2617 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf))); 2622 BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
2618 readevalloop (buf, 0, filename, 2623 readevalloop (buf, 0, filename,
2619 !NILP (printflag), unibyte, Qnil, Qnil, Qnil); 2624 !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
@@ -5169,7 +5174,7 @@ obarray_index (struct Lisp_Obarray *oa, const char *str, ptrdiff_t size_byte)
5169 return knuth_hash (reduce_emacs_uint_to_hash_hash (hash), oa->size_bits); 5174 return knuth_hash (reduce_emacs_uint_to_hash_hash (hash), oa->size_bits);
5170} 5175}
5171 5176
5172/* Return the symbol in OBARRAY whose names matches the string 5177/* Return the symbol in OBARRAY whose name matches the string
5173 of SIZE characters (SIZE_BYTE bytes) at PTR. 5178 of SIZE characters (SIZE_BYTE bytes) at PTR.
5174 If there is no such symbol, return the integer bucket number of 5179 If there is no such symbol, return the integer bucket number of
5175 where the symbol would be if it were present. 5180 where the symbol would be if it were present.
@@ -6145,6 +6150,11 @@ through `require'. */);
6145 6150
6146 DEFSYM (Qchar_from_name, "char-from-name"); 6151 DEFSYM (Qchar_from_name, "char-from-name");
6147 6152
6153 DEFVAR_LISP ("internal--get-default-lexical-binding-function",
6154 Vinternal__get_default_lexical_binding_function,
6155 doc: /* Function to decide default lexical-binding. */);
6156 Vinternal__get_default_lexical_binding_function = Qnil;
6157
6148 DEFVAR_LISP ("read-symbol-shorthands", Vread_symbol_shorthands, 6158 DEFVAR_LISP ("read-symbol-shorthands", Vread_symbol_shorthands,
6149 doc: /* Alist of known symbol-name shorthands. 6159 doc: /* Alist of known symbol-name shorthands.
6150This variable's value can only be set via file-local variables. 6160This variable's value can only be set via file-local variables.