unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: regexp font-lock highlighting
Date: Mon, 06 Jun 2005 16:05:25 +0300	[thread overview]
Message-ID: <87ll5npre2.fsf@jurta.org> (raw)
In-Reply-To: <429AD1B5.1020408@gmx.at> (martin rudalics's message of "Mon, 30 May 2005 10:41:25 +0200")

> Note that I removed the "\\(\\?:\\)?" since I find it distracting to
> put yet another face here.  If you believe that you _really_ need it
> you will have to reinsert it, but in that case you have to modify
> match-data cropping as well.  (I do have to modify match-data since
> redisplay wants some valid buffer positions for highlighting.)

I fixed shy group handling in this regexp by allowing ?: to be only
before `(' instead of before any of `(', `|' or `)'.  You may need to
adjust your code before submitting your final patch.

Also I tried to extend this regexp to highlight other special backslash
constructs like `\<', `\_<', `\w', `\sC', but soon discovered that
sometimes there are similar constructs in non-regexp strings that become
inappropriately highlighted.  Unless it's possible to detect whether
a given string is a regexp or not, I think the regexp highlighting
code should be split into multi-level font-lock variables
font-lock-regexp-keywords-1 and font-lock-regexp-keywords-2.
The first variable would highlight only `\\(?:', `\\|' and `\\)' constructs,
but the second - all other regexp constructs.  Everyone agreed to see
regexp constructs sometimes highlighted in wrong places could use
the second level variable.

> Finally, I would use three distinct font-lock faces for regexps:
>
> - One face for highlighting the "\\"s which by default should inherit
>   from `font-lock-string-face' with a dimmed foreground - I'm using
>   Green4 for strings and PaleGreen3 for the "\\"s.  Anyone who doesn't
    =====                      =====

I see everyone tends to change the default color of `font-lock-string-face'
(which is barely visible on light backgrounds) to a green color.
Currently on tty strings are fontified in green, so maybe this is one
of the reasons why people prefer green strings.  This indicates that
we should change the current "RosyBrown" default to one of the shades
of green.

>   like the highlighting could revert to `font-lock-string-face'.
>
> - One face for highlighting the "(", "|" and ")" in these expressions.
>   I find `bold' good here but again would leave it to the user whether
>   she wants to turn off highlighting this.  Moreover, such a face could
>   allow paren-highlighting to _never_ match a paren with that face with
>   a paren with another face.  Consequently, paren-matching could finally
>   provide more trustable information within regular expressions.

I added two new faces: for a backslash and regexp constructs after
a backslash.  The former inherits from escape-glyph to be highlighted
like a backslash in escape sequences, the latter is bold by default.
I think there is no need for a face for shy groups.  It is fontified
now in the same face as other regexp constructs (bold).

> - One face for highlighting the innermost grouping.  Basically,
>   `underline' is not bad here but appears a bit noisy in multiline
>   expressions or things like
>
>   (concat "\\("
>           some-string
>           "\\)")

You could add this face after implementing correct highlighting of
nested groups.

-- 
Juri Linkov
http://www.jurta.org/emacs/

  parent reply	other threads:[~2005-06-06 13:05 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-30  8:41 regexp font-lock highlighting martin rudalics
2005-05-31  2:45 ` Daniel Brockman
2005-06-01  9:39 ` Richard Stallman
2005-06-04  8:11   ` martin rudalics
2005-06-04 17:59     ` Richard Stallman
2005-06-06  9:33       ` martin rudalics
2005-06-11 23:17         ` Richard Stallman
2005-06-15 16:00           ` martin rudalics
2005-07-03  0:09             ` Juri Linkov
2005-07-03  4:10               ` Luc Teirlinck
2005-07-03  6:03               ` Eli Zaretskii
2005-07-03  9:10                 ` martin rudalics
2005-07-04  0:09                   ` Miles Bader
2005-06-06 13:05 ` Juri Linkov [this message]
2005-06-08 15:13   ` martin rudalics
2005-06-08 20:34     ` Juri Linkov
2005-06-08 22:42       ` Stefan Monnier
2005-06-08 23:32         ` Juri Linkov

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=87ll5npre2.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /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).