all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#14481: 24.3.50; Highlighting escape sequences
@ 2013-05-27  5:55 Dmitry Gutov
  2013-05-27 14:16 ` Drew Adams
  2013-05-28 20:45 ` Dmitry Gutov
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Gutov @ 2013-05-27  5:55 UTC (permalink / raw)
  To: 14481

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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-10-29  9:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-27  5:55 bug#14481: 24.3.50; Highlighting escape sequences Dmitry Gutov
2013-05-27 14:16 ` Drew Adams
2013-05-27 14:39   ` Dmitry Gutov
2013-05-28 20:45 ` Dmitry Gutov
2016-10-29  9:11   ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.