diff options
| author | Mattias EngdegÄrd | 2024-05-04 10:08:19 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-05-04 10:35:24 +0200 |
| commit | 1121f17d7c4bc3b71edcd0799b894f50aa3a715e (patch) | |
| tree | 87c80b72614ae2e2e53ee3c697d0479bc482ba1c /src | |
| parent | 41dd78cd362a80f1becc006a37f163119b93df10 (diff) | |
| download | emacs-1121f17d7c4bc3b71edcd0799b894f50aa3a715e.tar.gz emacs-1121f17d7c4bc3b71edcd0799b894f50aa3a715e.zip | |
Only issue lexical cookie warning for elisp files
* src/lread.c (string_suffix_p): New.
(warn_missing_cookie): Suppress warning for files not ending in ".el",
except ".emacs".
* etc/NEWS: Update accordingly, and mention how the warning can be
suppressed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/lread.c b/src/lread.c index a8ea52a888d..ba890cb673d 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1342,20 +1342,33 @@ close_file_unwind_android_fd (void *ptr) | |||
| 1342 | 1342 | ||
| 1343 | #endif | 1343 | #endif |
| 1344 | 1344 | ||
| 1345 | static bool | ||
| 1346 | string_suffix_p (const char *string, ptrdiff_t string_len, | ||
| 1347 | const char *suffix, ptrdiff_t suffix_len) | ||
| 1348 | { | ||
| 1349 | return string_len >= suffix_len && memcmp (string + string_len - suffix_len, | ||
| 1350 | suffix, suffix_len) == 0; | ||
| 1351 | } | ||
| 1352 | |||
| 1345 | static void | 1353 | static void |
| 1346 | warn_missing_cookie (Lisp_Object file) | 1354 | warn_missing_cookie (Lisp_Object file) |
| 1347 | { | 1355 | { |
| 1348 | Lisp_Object msg; | 1356 | /* Only warn for files whose name end in .el, to suppress loading of |
| 1349 | 1357 | data-as-code. ".emacs" is an exception, since it does tend to contain | |
| 1350 | /* The user init file should not be subject to these warnings, as | 1358 | actual hand-written code. */ |
| 1351 | Emacs doesn't insert cookies into generated init files. */ | 1359 | if (!STRINGP (file)) |
| 1352 | if (!NILP (Fequal (file, Vuser_init_file))) | 1360 | return; |
| 1361 | const char *name = SSDATA (file); | ||
| 1362 | ptrdiff_t nb = SBYTES (file); | ||
| 1363 | if (!(string_suffix_p (name, nb, ".el", 3) | ||
| 1364 | || (string_suffix_p (name, nb, ".emacs", 6) | ||
| 1365 | && (nb == 6 || SREF (file, nb - 7) == '/')))) | ||
| 1353 | return; | 1366 | return; |
| 1354 | 1367 | ||
| 1355 | msg = CALLN (Fformat, | 1368 | Lisp_Object msg = CALLN (Fformat, |
| 1356 | build_string ("File %s lacks `lexical-binding'" | 1369 | build_string ("File %s lacks `lexical-binding'" |
| 1357 | " directive on its first line"), | 1370 | " directive on its first line"), |
| 1358 | file); | 1371 | file); |
| 1359 | Vdelayed_warnings_list = Fcons (list2 (Qlexical_binding, msg), | 1372 | Vdelayed_warnings_list = Fcons (list2 (Qlexical_binding, msg), |
| 1360 | Vdelayed_warnings_list); | 1373 | Vdelayed_warnings_list); |
| 1361 | } | 1374 | } |