From 8b308258a0deafcfa3846c52efc651f09154ea9e Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Tue, 15 Oct 2024 15:04:48 -0400 Subject: [PATCH] Prevent incorrect error message when calling read inside load Previously, if `load' eval'd a `read' expression which raised end-of-file, the error would include load-true-file-name, even though the `read' may be reading something completely different. Now, end-of-file errors raised by `read' will only include load-true-file-name if it's actually reading that file. We do this by having read include read-end-of-file-data in the error instead of load-true-file-name, and only binding read-end-of-file-data around the "read" parts of readevalloop, not the "eval" parts. (load-true-file-name is still bound throughout) Also, when reading a file (or some other source), it is now possible to bind read-end-of-file-data so that end-of-file errors raised by read will include the filename (or the string of your choice). Previously, an end-of-file error raised by read outside of load would never include the filename. * src/lread.c (syms_of_lread): Add read-end-of-file-data. (readevalloop): Bind read-end-of-file-data to load-true-file-name around read. (end_of_file_error): Use read-end-of-file-data instead of load-true-file-name. (bug#68546) --- src/lread.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lread.c b/src/lread.c index 95c6891c205..ec0c68e1843 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2329,8 +2329,8 @@ readevalloop_1 (int old) static AVOID end_of_file_error (void) { - if (STRINGP (Vload_true_file_name)) - xsignal1 (Qend_of_file, Vload_true_file_name); + if (!NILP (Vread_end_of_file_data)) + xsignal1 (Qend_of_file, Vread_end_of_file_data); xsignal0 (Qend_of_file); } @@ -2434,6 +2434,8 @@ readevalloop (Lisp_Object readcharfun, while (continue_reading_p) { specpdl_ref count1 = SPECPDL_INDEX (); + if (NILP (Vread_end_of_file_data)) + specbind (Qread_end_of_file_name, Vload_true_file_name); if (b != 0 && !BUFFER_LIVE_P (b)) error ("Reading from killed buffer"); @@ -2529,7 +2531,7 @@ readevalloop (Lisp_Object readcharfun, if (!NILP (start) && continue_reading_p) start = Fpoint_marker (); - /* Restore saved point and BEGV. */ + /* Restore saved point and BEGV, and unbind read_end_of_file_data. */ unbind_to (count1, Qnil); /* Now eval what we just read. */ @@ -2661,7 +2663,10 @@ DEFUN ("read", Fread, Sread, 0, 1, 0, call it with a char as argument to push a char back) a string (takes text from string, starting at the beginning) t (read text line using minibuffer and use it, or read from - standard input in batch mode). */) + standard input in batch mode). + +If an unterminated list, vector, or string is encountered, signal +`end-of-file' with `read-end-of-file-data'. */) (Lisp_Object stream) { if (NILP (stream)) @@ -5963,6 +5968,12 @@ syms_of_lread (void) doc: /* Full name of file being loaded by `load'. */); Vload_true_file_name = Qnil; + DEFVAR_LISP ("read-end-of-file-data", Vread_end_of_file_data, + doc: /* When `read' signals `end-of-file', it passes this to `signal' as DATA. +When loading a file, this is bound to `load-true-file-name'. */); + Vread_end_of_file_data = Qnil; + DEFSYM (Qread_end_of_file_data, "read-end-of-file-data"); + DEFVAR_LISP ("user-init-file", Vuser_init_file, doc: /* File name, including directory, of user's initialization file. If the file loaded had extension `.elc', and the corresponding source file -- 2.39.3