* font-lock-add-keywords frustrations
@ 2003-05-18 3:16 Jesse Sheidlower
2003-05-18 4:17 ` Stefan Monnier
2003-05-18 10:14 ` Glenn Morris
0 siblings, 2 replies; 9+ messages in thread
From: Jesse Sheidlower @ 2003-05-18 3:16 UTC (permalink / raw)
I've been trying to learn how to use some font features, and
have managed to get stuck at the very start of the project I
was trying to do. I cannot seem to get font-lock-add-keywords
working the way I expect.
After trying some slightly more elaborate setups with keeping
the keywords in a separate variable and so forth, I reduced
the relevant part of my .emacs to a short test case:
(defface test-face
'((((class color) (background dark))
(:background "red" :foreground "black" bold t))
(((class color) (background light))
(:background "red" :foreground "black" bold t))
(t (:background "green")))
"Test face."
)
(font-lock-add-keywords 'psgml-mode
'(("slam" . test-face)))
My intention was to have all instances of "slam" in a text
viewed in psgml-mode to appear in the face test-face. It does
not work. I have tried a number of variations (trying
different words in case "slam" was being superseded by some
other keyword; trying the same thing in cperl-mode and other
modes that support font-locking; trying built-in fonts; etc.)
and none of them have worked. test-face does show up in
list-faces-display, gaudy as intended. I've looked through
the archives of this list, as well as the Manual, the Emacs
Wiki, and other places, and I can't see what I'm missing.
I would be grateful for any suggestions. I'm using GNU Emacs
21.2.1 on FreeBSD in an X environment.
Thank you.
Jesse Sheidlower
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-18 3:16 font-lock-add-keywords frustrations Jesse Sheidlower
@ 2003-05-18 4:17 ` Stefan Monnier
2003-05-18 10:14 ` Glenn Morris
1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2003-05-18 4:17 UTC (permalink / raw)
>>>>> "Jesse" == Jesse Sheidlower <jester@panix.com> writes:
> (font-lock-add-keywords 'psgml-mode
> '(("slam" . test-face)))
^^^^^^^^^
font-lock expects this to be an elisp expression that will
return the face to use, but since `test-face' is not a bound
variable, it fails. Try
(font-lock-add-keywords 'psgml-mode
'(("slam" (0 'test-face))))
or
(defvar test-face 'test-face)
(font-lock-add-keywords 'psgml-mode
'(("slam" (0 test-face))))
I'd also recommend
(add-hook 'psgml-mode-hook
(lambda ()
(font-lock-add-keywords nil '(("slam" (0 'test-face))))))
because the implementation of `font-lock-add-keywords' in the case
where the mode is not nil is pretty ugly ;-)
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-18 3:16 font-lock-add-keywords frustrations Jesse Sheidlower
2003-05-18 4:17 ` Stefan Monnier
@ 2003-05-18 10:14 ` Glenn Morris
2003-05-19 1:06 ` Jesse Sheidlower
1 sibling, 1 reply; 9+ messages in thread
From: Glenn Morris @ 2003-05-18 10:14 UTC (permalink / raw)
Jesse Sheidlower wrote:
> (defface test-face
[...]
> (font-lock-add-keywords 'psgml-mode
> '(("slam" . test-face)))
Try quoting test-face:
(font-lock-add-keywords 'psgml-mode
'(("slam" . 'test-face)))
Though I do not have psgml-mode, that works for me in lisp-mode, etc.
In the documentation of the variable `font-lock-keywords', you will
find
FACENAME is an expression whose *value* is the face name to use.
(my emphasis). Thus, in your version, the font-lock machinery was
trying to evaluate test-face as a variable. The examples given in the
documentation for the function `font-lock-add-keywords' make use of
the fact that `font-lock-variable-name-face' etc are also variables
whose values are faces of the same name. Perhaps this is unfortunate
in the context of an example. So, another way round your problem would
be
(setq test-face 'test-face)
ie make test-face's variable definition be the face test-face.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-18 10:14 ` Glenn Morris
@ 2003-05-19 1:06 ` Jesse Sheidlower
2003-05-19 2:27 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Jesse Sheidlower @ 2003-05-19 1:06 UTC (permalink / raw)
(posted and e-mailed to original poster)
In article <xehe7sef36.fsf@xpc14.ast.cam.ac.uk>,
Glenn Morris <gmorris+news@ast.cam.ac.uk> wrote:
>Jesse Sheidlower wrote:
>
>> (defface test-face
>[...]
>> (font-lock-add-keywords 'psgml-mode
>> '(("slam" . test-face)))
>
>Try quoting test-face:
>
>(font-lock-add-keywords 'psgml-mode
> '(("slam" . 'test-face)))
>
>Though I do not have psgml-mode, that works for me in lisp-mode, etc.
>In the documentation of the variable `font-lock-keywords', you will
>find
>
> FACENAME is an expression whose *value* is the face name to use.
>
>(my emphasis). [...]
Thanks very much. This and Stefan's similar comments were helpful, and
you're quite right that I was confused by the coincidence of the names
of the variables and the faces like `font-lock-variable-name-face'.
However--and after much further experimentation--I seem to be coming
to the conclusion that there's something about psgml that's causing
the problem. After quoting "test-face" properly, it _still_ didn't work,
so I tried it with other font-lock-supporting modes, including lisp-mode,
c-mode, and cperl-mode, and it worked in all of them. I tried different
keywords as well, also with no problem--as soon as I typed "barfoo" or
whatever in c-mode, it highlighted in test-face as I defined above.
But in psgml-mode, it just didn't work. I looked through the psgml-mode
manual, to no avail, and though I'm working on it I still don't know
enough Emacs Lisp to make it through the source code.
Anyone have further suggestions? Thanks very much.
Jesse Sheidlower
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-19 1:06 ` Jesse Sheidlower
@ 2003-05-19 2:27 ` Stefan Monnier
2003-05-22 20:29 ` Martin Stemplinger
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2003-05-19 2:27 UTC (permalink / raw)
>>>>> "Jesse" == Jesse Sheidlower <jester@panix.com> writes:
> However--and after much further experimentation--I seem to be coming
> to the conclusion that there's something about psgml that's causing
> the problem. After quoting "test-face" properly, it _still_ didn't work,
IIRC, psgml doesn't use font-lock.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-19 2:27 ` Stefan Monnier
@ 2003-05-22 20:29 ` Martin Stemplinger
2003-05-22 21:02 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: Martin Stemplinger @ 2003-05-22 20:29 UTC (permalink / raw)
On Mo Mai 19 2003 at 04:27, "Stefan Monnier"
<monnier+gnu.emacs.help/news/@flint.cs.yale.edu> wrote:
>> However--and after much further experimentation--I seem to be coming
>> to the conclusion that there's something about psgml that's causing
>> the problem. After quoting "test-face" properly, it _still_ didn't work,
Markus Hoenicka wrote a tutorial on writing docbook with emacs
(http://ourworld.compuserve.com/homepages/hoenicka_markus/ntsgml.html)
which includes samples for setting up custom faces. Maybe you could
this as a starting point?
> IIRC, psgml doesn't use font-lock.
I don't think so, psgml shows my XML code with lots of colors.
Cheers
Martin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-22 20:29 ` Martin Stemplinger
@ 2003-05-22 21:02 ` Stefan Monnier
2003-05-30 4:32 ` John L Fjellstad
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2003-05-22 21:02 UTC (permalink / raw)
>> IIRC, psgml doesn't use font-lock.
> I don't think so, psgml shows my XML code with lots of colors.
You're confusing font-lock and faces.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-22 21:02 ` Stefan Monnier
@ 2003-05-30 4:32 ` John L Fjellstad
2003-05-30 13:46 ` Stefan Monnier
0 siblings, 1 reply; 9+ messages in thread
From: John L Fjellstad @ 2003-05-30 4:32 UTC (permalink / raw)
Stefan Monnier wrote:
> You're confusing font-lock and faces.
What is the difference? (newbie question. Be gentle:-)
--
John L. Fjellstad
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: font-lock-add-keywords frustrations
2003-05-30 4:32 ` John L Fjellstad
@ 2003-05-30 13:46 ` Stefan Monnier
0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2003-05-30 13:46 UTC (permalink / raw)
>> You're confusing font-lock and faces.
> What is the difference? (newbie question. Be gentle:-)
Font-lock is a package that uses various mode-provided rules to determine
where to put faces in your buffer. `faces' are annotations used by the
redisplay engine to affect how things look on your screen.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2003-05-30 13:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-18 3:16 font-lock-add-keywords frustrations Jesse Sheidlower
2003-05-18 4:17 ` Stefan Monnier
2003-05-18 10:14 ` Glenn Morris
2003-05-19 1:06 ` Jesse Sheidlower
2003-05-19 2:27 ` Stefan Monnier
2003-05-22 20:29 ` Martin Stemplinger
2003-05-22 21:02 ` Stefan Monnier
2003-05-30 4:32 ` John L Fjellstad
2003-05-30 13:46 ` Stefan Monnier
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).