[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#14481: 24.3.50; Highlighting escape sequences

From: Drew Adams
Subject: bug#14481: 24.3.50; Highlighting escape sequences
Date: Mon, 27 May 2013 07:16:25 -0700 (PDT)

> 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.")

Something like this would be useful, IMO.

But consider separating out the escape syntax for the various regexp
parts - e.g., the parts that match more than a single escape char (for
octal etc.).  Using separate regexps (which can still be combined) for
the various parts lets you choose whether to highlight each char group
(e.g., highlight only hex escapes).


FWIW, library highlight-chars.el lets you selectively highlight sets of 
chars.  This works together with font-lock: you can choose whether
other font-lock highlighting overrides, is overridden by, or is merged
with this highlighting (applied after or before it).

You can specify chars to highlight in various ways: (1) individually
(any in a given string), (2) using ranges, (3) using character classes 
(e.g. [:digit:]), and (4) using character sets (e.g. `iso-8859-1' or 
`lao').  You can also specify sets of chars to be excluded from such 
highlighting - IOW, specify a set by subtraction as well as by 

You can thus, for example, highlight all characters in char set
`greek-iso8859-7' except `GREEK SMALL LETTER LAMBDA'.  Or all
characters in class `[:space:]' (whitespace) except `tab'.  Or
all Unicode characters in the range ?\u2190 through ?\u21ff
(mathematical arrows) except ?\u21b6, ?\u21b7, ?\u21ba, and
?\u21bb (curved arrows).

You can use any faces for the highlighting.  You can choose whether
to add such highlighting automatically whenever font-lock mode is
on in a buffer (via `font-lock-mode-hook').  You can use
`(after-)change-major-mode-hook' to make the highlighting
mode-specific.  Or you can use the highlighting only in certain 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]