GNU bug report logs -
#14481
24.3.50; Highlighting escape sequences
Previous Next
Reported by: Dmitry Gutov <dgutov <at> yandex.ru>
Date: Mon, 27 May 2013 05:57:02 UTC
Severity: wishlist
Found in version 24.3.50
Done: Dmitry Gutov <raaahh <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Most of the other text editors highlight stuff like \\, \t, \123 inside
string and regexp literals. For example, Vim and Sublime Text do.
In Emacs, we only have that in emacs-lisp-mode for grouping expressions,
I'm guessing because of their uncommon syntax.
Do we want it in other language modes? Here's some initial
implementation for ruby-mode and js-mode, using the face
font-lock-regexp-grouping-backslash, because it's the closest we have.
(defconst escape-sequence-re
"\\(\\\\\\(\\(?:[0-9]\\|x\\)\\(?:[0-9]\\(?:[0-9]\\)?\\)?\\|.\\)\\)"
"Regexp to match an escape sequence.
Currently handles octals (\\123), hexadecimals (\\x12) and
backslash followed by anything else.")
(font-lock-add-keywords
'ruby-mode
`((,escape-sequence-re
(1 (let ((term (nth 3 (syntax-ppss))))
(when (or (and (eq term ?')
(member (match-string 2) '("\\" "'")))
(memq term '(?\" ?/ ?\n t)))
'font-lock-regexp-grouping-backslash))
prepend)))
'append)
(font-lock-add-keywords
'js-mode
`((,escape-sequence-re
(1 (when (nth 3 (syntax-ppss))
'font-lock-regexp-grouping-backslash)
prepend)))
'append)
If yes, where should this code live? The regexp itself should be either
the same or quite similar for many modern languages, so I would prefer
to have it in one place.
This bug report was last modified 8 years and 209 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.