[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 0b4b380: Make warning about unescaped character lit
From: |
Philipp Stephani |
Subject: |
[Emacs-diffs] master 0b4b380: Make warning about unescaped character literals more helpful. |
Date: |
Fri, 19 Apr 2019 13:20:56 -0400 (EDT) |
branch: master
commit 0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>
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 +++++++++++++++
lisp/emacs-lisp/bytecomp.el | 11 +++--------
src/lread.c | 24 +++++++++---------------
test/lisp/emacs-lisp/bytecomp-tests.el | 4 +++-
test/src/lread-tests.el | 4 +++-
5 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index b638b56..7e256f8 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -495,6 +495,21 @@ is enabled."
(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
;; 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 8bbe629..4c61e1a 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."
(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)
diff --git a/src/lread.c b/src/lread.c
index 8cb4b63..8b38cac 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1034,18 +1034,12 @@ load_error_old_style_backquotes (void)
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,
@@ -5014,9 +5008,9 @@ For internal use only. */);
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.
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el
b/test/lisp/emacs-lisp/bytecomp-tests.el
index f66a06b..5fb64ff 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -540,7 +540,9 @@ literals (Bug#20852)."
(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."
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index ae918f0..82b75b1 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -140,7 +140,9 @@ literals (Bug#20852)."
(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."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 0b4b380: Make warning about unescaped character literals more helpful.,
Philipp Stephani <=