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.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14481 in the body.
You can then email your comments to 14481 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14481
; Package
emacs
.
(Mon, 27 May 2013 05:57:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 27 May 2013 05:57:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14481
; Package
emacs
.
(Mon, 27 May 2013 14:18:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 14481 <at> debbugs.gnu.org (full text, mbox):
> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14481
; Package
emacs
.
(Mon, 27 May 2013 14:43:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 14481 <at> debbugs.gnu.org (full text, mbox):
On 27.05.2013 18:16, Drew Adams wrote:
> 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).
I can't imagine why someone would want to highlight hex escapes, yet
keep octals and others unhighlighted. If we're going to support some
languages that only support a few escape sequences, then modifying this
regexp might be the way to go, yes, although writing separate, smaller
specialized regexp(s) might be better.
> 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.
That's nice, but we really need regexp here. And there's no point
relying on third-party library, the code is small as it is.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#14481
; Package
emacs
.
(Tue, 28 May 2013 20:48:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 14481 <at> debbugs.gnu.org (full text, mbox):
Dmitry Gutov <dgutov <at> yandex.ru> writes:
> Do we want it in other language modes? <...>
> 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.
So, no other replies? I can release it as a third-party minor mode, no
problem.
Reply sent
to
Dmitry Gutov <raaahh <at> gmail.com>
:
You have taken responsibility.
(Sat, 29 Oct 2016 09:12:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Dmitry Gutov <dgutov <at> yandex.ru>
:
bug acknowledged by developer.
(Sat, 29 Oct 2016 09:12:02 GMT)
Full text and
rfc822 format available.
Message #19 received at 14481-done <at> debbugs.gnu.org (full text, mbox):
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
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 26 Nov 2016 12:24:03 GMT)
Full text and
rfc822 format available.
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.