unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Dmitry Gutov <dgutov@yandex.ru>, 14481@debbugs.gnu.org
Subject: bug#14481: 24.3.50; Highlighting escape sequences
Date: Mon, 27 May 2013 07:16:25 -0700 (PDT)	[thread overview]
Message-ID: <226f0791-6c9a-48ff-ae86-650147a1a622@default> (raw)
In-Reply-To: <87li71ynkb.fsf@yandex.ru>

> 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 
addition.

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 
buffers.

http://www.emacswiki.org/emacs-en/download/highlight-chars.el

http://www.emacswiki.org/emacs/ShowWhiteSpace#toc2






  reply	other threads:[~2013-05-27 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27  5:55 bug#14481: 24.3.50; Highlighting escape sequences Dmitry Gutov
2013-05-27 14:16 ` Drew Adams [this message]
2013-05-27 14:39   ` Dmitry Gutov
2013-05-28 20:45 ` Dmitry Gutov
2016-10-29  9:11   ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=226f0791-6c9a-48ff-ae86-650147a1a622@default \
    --to=drew.adams@oracle.com \
    --cc=14481@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).