From 16004397f40d15d9db6b90632c236c804f38fc40 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sat, 13 May 2017 12:28:48 +0200 Subject: [PATCH] Improve unescaped character literal warnings * src/lread.c (load_warn_unescaped_character_literals) (syms_of_lread): lisp/emacs-lisp/bytecomp.el (byte-compile-from-buffer): Improve formatting of unescaped character literal warnings. * 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/bytecomp.el | 2 +- src/lread.c | 6 +++++- test/lisp/emacs-lisp/bytecomp-tests.el | 3 ++- test/src/lread-tests.el | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 201733ff033..daad93de182 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -2032,7 +2032,7 @@ and will be removed soon. See (elisp)Backquote in the manual.")) (when lread--unescaped-character-literals (byte-compile-warn "unescaped character literals %s detected!" - (mapconcat #'string + (mapconcat (lambda (char) (format "`?%c'" char)) (sort lread--unescaped-character-literals #'<) ", "))) (byte-compile-toplevel-file-form form))) diff --git a/src/lread.c b/src/lread.c index f0ad0c28e56..0e5b476a9a2 100644 --- a/src/lread.c +++ b/src/lread.c @@ -963,9 +963,11 @@ load_warn_unescaped_character_literals (Lisp_Object file) AUTO_STRING (format, "Loading `%s': unescaped character literals %s detected!"); AUTO_STRING (separator, ", "); + AUTO_STRING (inner_format, "`?%c'"); CALLN (Fmessage, format, file, - Fmapconcat (Qstring, + Fmapconcat (list3 (Qlambda, list1 (Qchar), + list3 (Qformat, inner_format, Qchar)), Fsort (Vlread_unescaped_character_literals, Qlss), separator)); } @@ -4855,6 +4857,8 @@ For internal use only. */); "lread--unescaped-character-literals"); DEFSYM (Qlss, "<"); + DEFSYM (Qchar, "char"); + DEFSYM (Qformat, "format"); DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer, doc: /* Non-nil means `load' prefers the newest version of a file. diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el index 3624904753c..84004a9264a 100644 --- a/test/lisp/emacs-lisp/bytecomp-tests.el +++ b/test/lisp/emacs-lisp/bytecomp-tests.el @@ -527,7 +527,8 @@ literals (Bug#20852)." (err (should-error (byte-compile-file source)))) (should (equal (cdr err) (list (concat "unescaped character literals " - "\", (, ), ;, [, ] detected!")))))))) + "`?\"', `?(', `?)', `?;', `?[', `?]' " + "detected!")))))))) ;; Local Variables: ;; no-byte-compile: t diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 0427fe64e4a..685ea682e29 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el @@ -140,7 +140,7 @@ literals (Bug#20852)." (should (equal (lread-tests--last-message) (concat (format-message "Loading `%s': " file-name) "unescaped character literals " - "\", (, ), ;, [, ] detected!"))))) + "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) (ert-deftest lread-test-bug26837 () "Test for http://debbugs.gnu.org/26837 ." -- 2.39.2