From b2790db049da98b541d07bac21ca7d7c220d3be0 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 10 Mar 2018 18:12:55 -0500 Subject: Improve errors & warnings due to fancy quoted vars (Bug#32939) Add some hints to the message for byte compiler free & unused variable warnings, and 'void-variable' errors where the variable has confusable quote characters in it. * lisp/help.el (uni-confusables), uni-confusables-regexp): New constants. (help-command-error-confusable-suggestions): New function, added to `command-error-function'. (help-uni-confusable-suggestions): New function. * lisp/emacs-lisp/bytecomp.el (byte-compile-variable-ref): * lisp/emacs-lisp/cconv.el (cconv--analyze-use): Use it. * lisp/emacs-lisp/lisp-mode.el (lisp--match-confusable-symbol-character): New function. (lisp-fdefs): Use it to fontify confusable characters with font-lock-warning-face when they occur in symbol names. * doc/lispref/modes.texi (Faces for Font Lock): * doc/lispref/objects.texi (Basic Char Syntax): Recommend backslash escaping of confusable characters, and mention new fontification. * etc/NEWS: Announce the new fontification behavior. * test/lisp/emacs-lisp/lisp-mode-tests.el (lisp-fontify-confusables): New test. --- test/lisp/emacs-lisp/lisp-mode-tests.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/lisp/emacs-lisp/lisp-mode-tests.el') diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el index e4ba929ecbd..c0dd68c0a0b 100644 --- a/test/lisp/emacs-lisp/lisp-mode-tests.el +++ b/test/lisp/emacs-lisp/lisp-mode-tests.el @@ -20,6 +20,10 @@ (require 'ert) (require 'cl-lib) (require 'lisp-mode) +(require 'faceup) + + +;;; Indentation (defconst lisp-mode-tests--correctly-indented-sexp "\ \(a @@ -290,5 +294,27 @@ Expected initialization file: `%s'\" (insert "\"\n") (lisp-indent-region (point-min) (point-max)))) + +;;; Fontification + +(ert-deftest lisp-fontify-confusables () + "Unescaped 'smart quotes' should be fontified in `font-lock-warning-face'." + (with-temp-buffer + (dolist (ch + '(#x2018 ;; LEFT SINGLE QUOTATION MARK + #x2019 ;; RIGHT SINGLE QUOTATION MARK + #x201B ;; SINGLE HIGH-REVERSED-9 QUOTATION MARK + #x201C ;; LEFT DOUBLE QUOTATION MARK + #x201D ;; RIGHT DOUBLE QUOTATION MARK + #x201F ;; DOUBLE HIGH-REVERSED-9 QUOTATION MARK + #x301E ;; DOUBLE PRIME QUOTATION MARK + #xFF02 ;; FULLWIDTH QUOTATION MARK + #xFF07 ;; FULLWIDTH APOSTROPHE + )) + (insert (format "«w:%c»foo \\%cfoo\n" ch ch))) + (let ((faceup (buffer-string))) + (faceup-clean-buffer) + (should (faceup-test-font-lock-buffer 'emacs-lisp-mode faceup))))) + (provide 'lisp-mode-tests) ;;; lisp-mode-tests.el ends here -- cgit v1.2.1