unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Font lock question
@ 2021-03-17  9:40 Joost Kremers
  2021-03-17 13:39 ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2021-03-17  9:40 UTC (permalink / raw)
  To: help-gnu-emacs

Hi list,

I'm trying to add font lock rules to a package of mine and I'm running into an
issue that I can't figure out how to solve. Schematically, I'm trying to match
instances of the following type:

    [aBc]

Here, the square brackets are obligatory and so is the `B`. `a` and `c` are
optional. `B` can be recognised by its form, `a` and `c` can only be recognised
by the fact that they are in between the opening/closing bracket and `B`.

So far, so good. But the complication is that this pattern of `aBc` can be
repeated *within the brackets*, where each instance is separated by a semicolon:

    [aBc; aBc; aBc]

There is no (theoretical) limit to the number of repetitions.

I have no trouble composing a regex that matches this entire thing. I'd add a
shy group that includes an optional semicolon and that is repeated at least
once:

    \[\(?:\(?1:.*?\)B\(?2:.*?\);?\)+\]

However, this does not work for font-lock, it seems.

At this point, I'm unsure what to try next. Is there a way to deal with such
patterns?

TIA

Joost


-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 10+ messages in thread
* Font lock question
@ 2008-05-28 10:34 Shaun Johnson
  0 siblings, 0 replies; 10+ messages in thread
From: Shaun Johnson @ 2008-05-28 10:34 UTC (permalink / raw)
  To: GNU Emacs Help

Hi,

I can define a mode to to render colour names on an appropriate background like so:

   (define-derived-mode sj-colour-words-mode nil "Colour Words"
     "Colour words appropriately."
     (setq font-lock-defaults
           '(
             (("blue" 0 '(face (fixed-pitch (:background "blue"))))
              ("red" 0 '(face (fixed-pitch (:background "red"))))
              ("green"  0 '(face (fixed-pitch (:background "green")))))
             t t)))

These elements of font-lock-keywords correspond to the form described as
(MATCHER . SUBEXP-HIGHLIGHTER) in section '23.6.2 Search Based Fontification' in edition
2.9 of the Elisp manual for emacs 22.2. However I have totally failed to make the form
described as (MATCHER . FACESPEC) where FACESPEC is a list of the form
(face FACE PROP1 VAL1...) work.

I'm sure I'm just misundertanding something and would be happy if someone could show me
a working example of this type of element.

Thanks in advance,

Shaun Johnson.




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

end of thread, other threads:[~2021-03-18 19:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-17  9:40 Font lock question Joost Kremers
2021-03-17 13:39 ` Stefan Monnier
2021-03-17 13:46   ` Joost Kremers
2021-03-17 15:33     ` Stefan Monnier
2021-03-17 16:09       ` Joost Kremers
2021-03-17 16:46         ` Stefan Monnier
2021-03-18 19:41           ` Joost Kremers
2021-03-17 16:31     ` Harald Jörg
2021-03-18 19:53       ` Joost Kremers
  -- strict thread matches above, loose matches on Subject: below --
2008-05-28 10:34 Shaun Johnson

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