unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Adding font-lock keywords
@ 2003-04-21 21:05 Brendan Van Horn
  2003-04-22 10:05 ` Glenn Morris
  0 siblings, 1 reply; 3+ messages in thread
From: Brendan Van Horn @ 2003-04-21 21:05 UTC (permalink / raw)


Greetings!  I spent some time reading FAQs and posts I could find and
I still seem to be missing something.  I'm trying to add some extra
keywords so that they are highlighted while editing.  Here is what I
came up with:

;; windows constants
(setq my-win32-constant-keywords
      (regexp-opt
       '("COINIT_MULTITHREADED" "ICC_COOL_CLASSES" "NULL"
"SW_SHOWDEFAULT"
	 "VT_BSTR" "VT_I4")))

(font-lock-add-keywords
 'c++-mode
 '((my-win32-constant-keywords . font-lock-constant-face)))

Where am I going wrong???

Thanks!
Brendan

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

* Re: Adding font-lock keywords
  2003-04-21 21:05 Adding font-lock keywords Brendan Van Horn
@ 2003-04-22 10:05 ` Glenn Morris
  2003-04-22 17:10   ` Brendan Van Horn
  0 siblings, 1 reply; 3+ messages in thread
From: Glenn Morris @ 2003-04-22 10:05 UTC (permalink / raw)


Brendan Van Horn wrote:

> (setq my-win32-constant-keywords
>       (regexp-opt
>        '("COINIT_MULTITHREADED" "ICC_COOL_CLASSES" "NULL" "SW_SHOWDEFAULT"
> 	 "VT_BSTR" "VT_I4")))
>
> (font-lock-add-keywords
>  'c++-mode
>  '((my-win32-constant-keywords . font-lock-constant-face)))

Use of a single-quote ' prevents symbols from being evaluated.

Compare:

my-win32-constant-keywords

with

'my-win32-constant-keywords

by putting the cursor at the end of the line and using C-x C-e. What
you are doing is adding the symbol my-win32-constant-keywords to the
keywords list, rather than its value.

You could use

(font-lock-add-keywords
 'c++-mode
 `((,my-win32-constant-keywords . font-lock-constant-face)))

because ` acts like ' except that anything preceded by a comma gets
evaluated. Or you could use:

(font-lock-add-keywords
 'c++-mode
 (list
  (cons my-win32-constant-keywords font-lock-constant-face)))

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

* Re: Adding font-lock keywords
  2003-04-22 10:05 ` Glenn Morris
@ 2003-04-22 17:10   ` Brendan Van Horn
  0 siblings, 0 replies; 3+ messages in thread
From: Brendan Van Horn @ 2003-04-22 17:10 UTC (permalink / raw)


Glenn Morris <gmorris+news@ast.cam.ac.uk> wrote...

> What you are doing is adding the symbol my-win32-constant-keywords
> to the keywords list, rather than its value.

Ahh...

> (font-lock-add-keywords
>  'c++-mode
>  `((,my-win32-constant-keywords . font-lock-constant-face)))

Just the ticket.  Here's is what I have that is (mostly) working:

(setq my-win32-constant-keywords
      (regexp-opt
       '("COINIT_MULTITHREADED" "ICC_COOL_CLASSES" "NULL"
	 "SW_SHOWDEFAULT" "VT_BSTR" "VT_ERROR" "VT_I4"
	 "vtEmpty" "vtError" "vtMissing")))

(defun my-add-keywords ()
  (font-lock-add-keywords 'c++-mode
   `(("@\\(?:TODO\\|todo\\)" . font-lock-warning-face)
     (,my-win32-constant-keywords . font-lock-constant-face))))
(add-hook 'c++-mode-hook 'my-add-keywords)
 
> because ` acts like ' except that anything preceded by a comma gets
> evaluated.

I see that now.  Thanks for the help!

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

end of thread, other threads:[~2003-04-22 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-21 21:05 Adding font-lock keywords Brendan Van Horn
2003-04-22 10:05 ` Glenn Morris
2003-04-22 17:10   ` Brendan Van Horn

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