See Bug#31676.
* lisp/emacs-lisp/byte-run.el
(byte-run--unescaped-character-literals-warning): New defun.
* src/lread.c (load_warn_unescaped_character_literals): Use new defun.
(syms_of_lread): Define symbol for new defun.
* lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Use new
defun.
* test/src/lread-tests.el (lread-tests--unescaped-char-literals):
test/lisp/emacs-lisp/bytecomp-tests.el
(bytecomp-tests--unescaped-char-literals): Adapt unit tests.
;; The implementation for the interpreter is basically trivial.
(car (last body)))
+\f
+(defun byte-run--unescaped-character-literals-warning ()
+ "Return a warning about unescaped character literals.
+If there were any unescaped character literals in the last form
+read, return an appropriate warning message as a string.
+Otherwise, return nil. For internal use only."
+ ;; This is called from lread.c and therefore needs to be preloaded.
+ (if lread--unescaped-character-literals
+ (let ((sorted (sort lread--unescaped-character-literals #'<)))
+ (format-message "unescaped character literals %s detected, %s expected!"
+ (mapconcat (lambda (char) (format "`?%c'" char))
+ sorted ", ")
+ (mapconcat (lambda (char) (format "`?\\%c'" char))
+ sorted ", ")))))
+
\f
;; I nuked this because it's not a good idea for users to think of using it.
;; These options are a matter of installation preference, and have nothing to
(not (eobp)))
(setq byte-compile-read-position (point)
byte-compile-last-position byte-compile-read-position)
- (let* ((lread--unescaped-character-literals nil)
- (form (read inbuffer)))
- (when lread--unescaped-character-literals
- (byte-compile-warn
- "unescaped character literals %s detected!"
- (mapconcat (lambda (char) (format "`?%c'" char))
- (sort lread--unescaped-character-literals #'<)
- ", ")))
+ (let ((form (read inbuffer))
+ (warning (byte-run--unescaped-character-literals-warning)))
+ (when warning (byte-compile-warn "%s" warning))
(byte-compile-toplevel-file-form form)))
;; Compile pending forms at end of file.
(byte-compile-flush-pending)
static void
load_warn_unescaped_character_literals (Lisp_Object file)
{
- if (NILP (Vlread_unescaped_character_literals)) return;
- CHECK_CONS (Vlread_unescaped_character_literals);
- Lisp_Object format =
- build_string ("Loading `%s': unescaped character literals %s detected!");
- Lisp_Object separator = build_string (", ");
- Lisp_Object inner_format = build_string ("`?%c'");
- CALLN (Fmessage,
- format, file,
- Fmapconcat (list3 (Qlambda, list1 (Qchar),
- list3 (Qformat, inner_format, Qchar)),
- Fsort (Vlread_unescaped_character_literals, Qlss),
- separator));
+ Lisp_Object warning
+ = call0 (Qbyte_run_unescaped_character_literals_warning);
+ if (NILP (warning))
+ return;
+ Lisp_Object format = build_string ("Loading `%s': %s");
+ CALLN (Fmessage, format, file, warning);
}
DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
DEFSYM (Qlread_unescaped_character_literals,
"lread--unescaped-character-literals");
- DEFSYM (Qlss, "<");
- DEFSYM (Qchar, "char");
- DEFSYM (Qformat, "format");
+ /* Defined in lisp/emacs-lisp/byte-run.el. */
+ DEFSYM (Qbyte_run_unescaped_character_literals_warning,
+ "byte-run--unescaped-character-literals-warning");
DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer,
doc: /* Non-nil means `load' prefers the newest version of a file.
(should (equal (cdr err)
(list (concat "unescaped character literals "
"`?\"', `?(', `?)', `?;', `?[', `?]' "
- "detected!"))))))))
+ "detected, "
+ "`?\\\"', `?\\(', `?\\)', `?\\;', `?\\[', "
+ "`?\\]' expected!"))))))))
(ert-deftest bytecomp-tests--old-style-backquotes ()
"Check that byte compiling warns about old-style backquotes."
(should (equal (lread-tests--last-message)
(concat (format-message "Loading `%s': " file-name)
"unescaped character literals "
- "`?\"', `?(', `?)', `?;', `?[', `?]' detected!")))))
+ "`?\"', `?(', `?)', `?;', `?[', `?]' detected, "
+ "`?\\\"', `?\\(', `?\\)', `?\\;', `?\\[', `?\\]' "
+ "expected!")))))
(ert-deftest lread-tests--funny-quote-symbols ()
"Check that 'smart quotes' or similar trigger errors in symbol names."