aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Stephani2018-06-02 11:59:02 +0200
committerPhilipp Stephani2019-04-19 19:19:35 +0200
commit0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca (patch)
treed48cd46b86ff19c609dd16f7ef799dd720014ef3
parent8aadf6e415b7801cb9fa4c5670b1750da207cf87 (diff)
downloademacs-0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca.tar.gz
emacs-0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca.zip
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.
-rw-r--r--lisp/emacs-lisp/byte-run.el15
-rw-r--r--lisp/emacs-lisp/bytecomp.el11
-rw-r--r--src/lread.c24
-rw-r--r--test/lisp/emacs-lisp/bytecomp-tests.el4
-rw-r--r--test/src/lread-tests.el4
5 files changed, 33 insertions, 25 deletions
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
@@ -495,6 +495,21 @@ is enabled."
495 (car (last body))) 495 (car (last body)))
496 496
497 497
498(defun byte-run--unescaped-character-literals-warning ()
499 "Return a warning about unescaped character literals.
500If there were any unescaped character literals in the last form
501read, return an appropriate warning message as a string.
502Otherwise, return nil. For internal use only."
503 ;; This is called from lread.c and therefore needs to be preloaded.
504 (if lread--unescaped-character-literals
505 (let ((sorted (sort lread--unescaped-character-literals #'<)))
506 (format-message "unescaped character literals %s detected, %s expected!"
507 (mapconcat (lambda (char) (format "`?%c'" char))
508 sorted ", ")
509 (mapconcat (lambda (char) (format "`?\\%c'" char))
510 sorted ", ")))))
511
512
498;; I nuked this because it's not a good idea for users to think of using it. 513;; I nuked this because it's not a good idea for users to think of using it.
499;; These options are a matter of installation preference, and have nothing to 514;; These options are a matter of installation preference, and have nothing to
500;; with particular source files; it's a mistake to suggest to users 515;; with particular source files; it's a mistake to suggest to users
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 8bbe6292d9d..4c61e1a4471 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2082,14 +2082,9 @@ With argument ARG, insert value in current buffer after the form."
2082 (not (eobp))) 2082 (not (eobp)))
2083 (setq byte-compile-read-position (point) 2083 (setq byte-compile-read-position (point)
2084 byte-compile-last-position byte-compile-read-position) 2084 byte-compile-last-position byte-compile-read-position)
2085 (let* ((lread--unescaped-character-literals nil) 2085 (let ((form (read inbuffer))
2086 (form (read inbuffer))) 2086 (warning (byte-run--unescaped-character-literals-warning)))
2087 (when lread--unescaped-character-literals 2087 (when warning (byte-compile-warn "%s" warning))
2088 (byte-compile-warn
2089 "unescaped character literals %s detected!"
2090 (mapconcat (lambda (char) (format "`?%c'" char))
2091 (sort lread--unescaped-character-literals #'<)
2092 ", ")))
2093 (byte-compile-toplevel-file-form form))) 2088 (byte-compile-toplevel-file-form form)))
2094 ;; Compile pending forms at end of file. 2089 ;; Compile pending forms at end of file.
2095 (byte-compile-flush-pending) 2090 (byte-compile-flush-pending)
diff --git a/src/lread.c b/src/lread.c
index 8cb4b63cc3a..8b38cacde07 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1034,18 +1034,12 @@ load_error_old_style_backquotes (void)
1034static void 1034static void
1035load_warn_unescaped_character_literals (Lisp_Object file) 1035load_warn_unescaped_character_literals (Lisp_Object file)
1036{ 1036{
1037 if (NILP (Vlread_unescaped_character_literals)) return; 1037 Lisp_Object warning
1038 CHECK_CONS (Vlread_unescaped_character_literals); 1038 = call0 (Qbyte_run_unescaped_character_literals_warning);
1039 Lisp_Object format = 1039 if (NILP (warning))
1040 build_string ("Loading `%s': unescaped character literals %s detected!"); 1040 return;
1041 Lisp_Object separator = build_string (", "); 1041 Lisp_Object format = build_string ("Loading `%s': %s");
1042 Lisp_Object inner_format = build_string ("`?%c'"); 1042 CALLN (Fmessage, format, file, warning);
1043 CALLN (Fmessage,
1044 format, file,
1045 Fmapconcat (list3 (Qlambda, list1 (Qchar),
1046 list3 (Qformat, inner_format, Qchar)),
1047 Fsort (Vlread_unescaped_character_literals, Qlss),
1048 separator));
1049} 1043}
1050 1044
1051DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0, 1045DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
@@ -5014,9 +5008,9 @@ For internal use only. */);
5014 DEFSYM (Qlread_unescaped_character_literals, 5008 DEFSYM (Qlread_unescaped_character_literals,
5015 "lread--unescaped-character-literals"); 5009 "lread--unescaped-character-literals");
5016 5010
5017 DEFSYM (Qlss, "<"); 5011 /* Defined in lisp/emacs-lisp/byte-run.el. */
5018 DEFSYM (Qchar, "char"); 5012 DEFSYM (Qbyte_run_unescaped_character_literals_warning,
5019 DEFSYM (Qformat, "format"); 5013 "byte-run--unescaped-character-literals-warning");
5020 5014
5021 DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer, 5015 DEFVAR_BOOL ("load-prefer-newer", load_prefer_newer,
5022 doc: /* Non-nil means `load' prefers the newest version of a file. 5016 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 f66a06bc1bc..5fb64ff2881 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -540,7 +540,9 @@ literals (Bug#20852)."
540 (should (equal (cdr err) 540 (should (equal (cdr err)
541 (list (concat "unescaped character literals " 541 (list (concat "unescaped character literals "
542 "`?\"', `?(', `?)', `?;', `?[', `?]' " 542 "`?\"', `?(', `?)', `?;', `?[', `?]' "
543 "detected!")))))))) 543 "detected, "
544 "`?\\\"', `?\\(', `?\\)', `?\\;', `?\\[', "
545 "`?\\]' expected!"))))))))
544 546
545(ert-deftest bytecomp-tests--old-style-backquotes () 547(ert-deftest bytecomp-tests--old-style-backquotes ()
546 "Check that byte compiling warns about old-style backquotes." 548 "Check that byte compiling warns about old-style backquotes."
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index ae918f03120..82b75b195ca 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -140,7 +140,9 @@ literals (Bug#20852)."
140 (should (equal (lread-tests--last-message) 140 (should (equal (lread-tests--last-message)
141 (concat (format-message "Loading `%s': " file-name) 141 (concat (format-message "Loading `%s': " file-name)
142 "unescaped character literals " 142 "unescaped character literals "
143 "`?\"', `?(', `?)', `?;', `?[', `?]' detected!"))))) 143 "`?\"', `?(', `?)', `?;', `?[', `?]' detected, "
144 "`?\\\"', `?\\(', `?\\)', `?\\;', `?\\[', `?\\]' "
145 "expected!")))))
144 146
145(ert-deftest lread-tests--funny-quote-symbols () 147(ert-deftest lread-tests--funny-quote-symbols ()
146 "Check that 'smart quotes' or similar trigger errors in symbol names." 148 "Check that 'smart quotes' or similar trigger errors in symbol names."