]> git.eshelyaron.com Git - emacs.git/commitdiff
Highlight useless backslashes in Elisp strings
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 11 Mar 2017 16:35:14 +0000 (11:35 -0500)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sat, 11 Mar 2017 16:35:14 +0000 (11:35 -0500)
* lisp/emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-2):
Put warning face on backslashes that have no effect.

lisp/emacs-lisp/lisp-mode.el

index d720e0bc573e41f809ded8dde442df8208a37a91..3ed0d062e34eba15b1fbaaf7943842246559a310 100644 (file)
@@ -411,6 +411,15 @@ This will generate compile-time constants from BINDINGS."
          ;; Words inside \\[] tend to be for `substitute-command-keys'.
          (,(concat "\\\\\\\\\\[\\(" lisp-mode-symbol-regexp "\\)\\]")
           (1 font-lock-constant-face prepend))
+         ;; Ineffective backslashes (typically in need of doubling).
+         ("\\(?:[^\\]\\|^\\)\\(?:\\\\\\\\\\)*\\(\\(\\\\\\)\\([^\"\\]\\)\\)"
+          (2 (and (nth 3 (syntax-ppss))
+                  (equal (ignore-errors
+                           (car (read-from-string
+                                 (format "\"%s\"" (match-string 1)))))
+                         (match-string 3))
+                  font-lock-warning-face)
+             prepend))
          ;; Words inside ‘’ and `' tend to be symbol names.
          (,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)"
                    lisp-mode-symbol-regexp "\\)['’]")