Subject: bug#14481: closed (Re: bug#14481: 24.3.50; Highlighting escape sequences)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 29 Oct 2016 09:12:02 +0000

Your bug report

#14481: 24.3.50; Highlighting escape sequences

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
14481: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14481
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#14481: 24.3.50; Highlighting escape sequences
From: Dmitry Gutov <[email-masked]>
To: Dmitry Gutov <[email-masked]>, [email-masked]
Date: Sat, 29 Oct 2016 12:11:49 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 29.05.2013 00:45, Dmitry Gutov wrote:

> I can release it as a third-party minor mode, no problem.

Now published in GNU ELPA: 
http://elpa.gnu.org/packages/highlight-escape-sequences.html

Subject: 24.3.50; Highlighting escape sequences
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Mon, 27 May 2013 09:55:00 +0400
List-Id: <debbugs-submit.debbugs.gnu.org>

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.