summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2018-06-02 11:59:02 +0200
committerPhilipp Stephani <phst@google.com>2019-04-19 19:19:35 +0200
commit0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca (patch)
treed48cd46b86ff19c609dd16f7ef799dd720014ef3 /lisp/emacs-lisp
parent8aadf6e415b7801cb9fa4c5670b1750da207cf87 (diff)
downloademacs-0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca.tar.gz
emacs-0b4b380ce4989afc59848d2b6a350bd1dd7dc7ca.tar.bz2
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.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/byte-run.el15
-rw-r--r--lisp/emacs-lisp/bytecomp.el11
2 files changed, 18 insertions, 8 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."
(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 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."
(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)