[Top][All Lists]

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

Re: Background colors in font-lock-keywords

From: Oliver Scholz
Subject: Re: Background colors in font-lock-keywords
Date: Wed, 28 May 2003 00:23:57 +0200
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3.50 (windows-nt)

address@hidden (Jesse Sheidlower) writes:
> First, I'd like certain faces to use as a background any other
> element they happen to be on. For example, in my font-lock-keywords
> section I define entity references for this application as:
>   ("&[a-zA-z]+;" . (0 my-entity-face t))
> I've defined my-entity-face with a red foreground color and a
> weight of bold. What I would like is for the background to
> match whatever it's on, so that if there's an entity reference
> in text that happens to be white, it will be red with a white
> background, but if, in another font-lock-keywords expression,
> I have defined
>   ("<title>\\(.*?\\)</title>" 1 my-title-face t)
> , with my-title-face having a light-green background, then I
> would like an entity reference used in a <title> to be red but
> also with a light-green background. Is there any way of
> accomplishing this? I've been experimenting to no avail.

Use the `prepend' or `append' keyword. For example:

(defface example-l-word-face
     (:background "Seagreen4")))
  "Face used for words beginning with \"l\".")

(defvar example-font-lock-keywords
  '(("\\<lirum\\>" . 'font-lock-warning-face)
    ("\\<larum\\>" . 'font-lock-keyword-face)
    ("\\<l\\w+" (0 'example-l-word-face append))))

(define-derived-mode example-mode text-mode "EXAMPLE"
  "Example mode for testing font lock keywords."
  (setq font-lock-defaults '(example-font-lock-keywords)))

> Second, is there a way to associate a background color with a particular
> buffer only? 

Unfortunately there isn't a way to do this. The thing that comes
closest to this is something like:

(set (make-local-variable 'default-text-properties)
     '(face example-l-word-face))

The disadvantages are obvious.

9 Prairial an 211 de la Révolution
Liberté, Egalité, Fraternité!

reply via email to

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