unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* different font-lock faces for different modes
@ 2005-07-17  3:30 Christopher C. Stacy
  2005-07-17  3:52 ` Joe Corneli
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher C. Stacy @ 2005-07-17  3:30 UTC (permalink / raw)


I want to change the face used for comments,
depending on which mode (language) I am in.

I'm already doing something like this:

(custom-set-faces
 '(font-lock-comment-face
     ((t ( :foreground "red")))))

For example, in C, I want keywords to be colored in red,
and in Lisp, I want keywords to be colored as blue.
How can I do that?

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

* Re: different font-lock faces for different modes
  2005-07-17  3:30 different font-lock faces for different modes Christopher C. Stacy
@ 2005-07-17  3:52 ` Joe Corneli
  2005-07-18 15:44   ` Kevin Rodgers
       [not found]   ` <mailman.902.1121701980.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Joe Corneli @ 2005-07-17  3:52 UTC (permalink / raw)


Sketch:

  Make a variable that hold the alternate definition of the face you
want to use.  Add to your `lisp-mode-hook' a function to set the
buffer-local value of `font-lock-comment-face' to the value of that
variable.

Details:

 (setq ugly-face '((t ( :foreground "blue"))))

 (add-hook 'lisp-mode-hook 
           (lambda () (make-local-variable font-lock-comment-face)
                      (setq font-lock-comment-face ugly-face)))

 ;; Yep, it works.

If for some ungodly reason you desire to switch between lisp mode and
C mode in the same buffer, you will have to continue slightly further
in the same vein.

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

* Re: different font-lock faces for different modes
  2005-07-17  3:52 ` Joe Corneli
@ 2005-07-18 15:44   ` Kevin Rodgers
       [not found]   ` <mailman.902.1121701980.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2005-07-18 15:44 UTC (permalink / raw)


Joe Corneli wrote:
 >  (add-hook 'lisp-mode-hook
 >            (lambda () (make-local-variable font-lock-comment-face)
 >                       (setq font-lock-comment-face ugly-face)))

That can be simplified just a bit:

(add-hook 'lisp-mode-hook
           (lambda ()
             (set (make-local-variable font-lock-comment-face) ugly-face)))

-- 
Kevin Rodgers

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

* Re: different font-lock faces for different modes
       [not found]   ` <mailman.902.1121701980.20277.help-gnu-emacs@gnu.org>
@ 2005-07-19 15:16     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2005-07-19 15:16 UTC (permalink / raw)


> (add-hook 'lisp-mode-hook
>            (lambda ()
>              (set (make-local-variable font-lock-comment-face) ugly-face)))
                                        ^^^
                                         '

And there was probably a quote missing in front of `ugly-face' as well.


        Stefan

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

end of thread, other threads:[~2005-07-19 15:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-17  3:30 different font-lock faces for different modes Christopher C. Stacy
2005-07-17  3:52 ` Joe Corneli
2005-07-18 15:44   ` Kevin Rodgers
     [not found]   ` <mailman.902.1121701980.20277.help-gnu-emacs@gnu.org>
2005-07-19 15:16     ` 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).