From 0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sat, 2 Jun 2018 11:59:02 +0200 Subject: Make warning about unescaped character literals more helpful. 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. --- lisp/emacs-lisp/byte-run.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lisp/emacs-lisp/byte-run.el') diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el index b638b56be1f..7e256f83272 100644 --- a/lisp/emacs-lisp/byte-run.el +++ b/lisp/emacs-lisp/byte-run.el @@ -494,6 +494,21 @@ is enabled." ;; The implementation for the interpreter is basically trivial. (car (last body))) + +(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 ", "))))) + ;; 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 -- cgit v1.2.3