unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Unexpected font face in C mode
@ 2013-08-09 20:35 Rami A
  2013-08-09 22:37 ` Emanuel Berg
  2013-08-12 18:52 ` Rami A
  0 siblings, 2 replies; 3+ messages in thread
From: Rami A @ 2013-08-09 20:35 UTC (permalink / raw)
  To: help-gnu-emacs

Greetings,
I am trying to have different font face for #define/#include and the rest of preprocessors like #if #endif...etc.

This is what I am including in my .emacs file:

(defconst lconfig-font-lock-faces  
  (list

   '(font-lock-function-name-face
     ((((class color)) (:foreground "DarkBlue"  :bold t))))

   '(font-lock-constant-face
     ((((class color)) (:foreground "Black"     :bold t))))


   '(font-lock-builtin-face
     ((((class color)) (:foreground nil))))

   '(font-lock-preprocessor-face
     ((((class color)) (:foreground nil))))

   )
  )

(autoload 'custom-set-faces "font-lock" "Set the color scheme" t)
(autoload 'font-lock-fontify-buffer "font-lock" "Fontify Buffer" t)
(progn (apply 'custom-set-faces lconfig-font-lock-faces)
       (add-hook 'c-mode-common-hook 'font-lock-fontify-buffer)
       (add-hook 'emacs-lisp-mode-hook 'font-lock-fontify-buffer)
       )
(global-font-lock-mode t)

(font-lock-add-keywords
 'c-mode
 '(
   ("^#[ \t]*\\(ifdef\\|else\\|ifndef\\|if !?defined\\|if\\|elif\\|endif\\|ident\\).*$" 1 font-lock-constant-face)                  ;#defines
   ("\\(^#[ \t]*define\\|^#[ \t]*include\\|^#[ \t]*undef\\).*$" 1 font-lock-function-name-face)                                     ;other #s
 )
)


Unfortunately when opening a c file I see #include and #define being black colored. Although they should match the regular expressions and turn to dark blue. 
Also #ifdef and #endif is in light dark color and not bold.

Not sure what I am doing wrong. Any help is highly appreciated.


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

* Re: Unexpected font face in C mode
  2013-08-09 20:35 Unexpected font face in C mode Rami A
@ 2013-08-09 22:37 ` Emanuel Berg
  2013-08-12 18:52 ` Rami A
  1 sibling, 0 replies; 3+ messages in thread
From: Emanuel Berg @ 2013-08-09 22:37 UTC (permalink / raw)
  To: help-gnu-emacs

Rami A <rami.ammari@gmail.com> writes:

> Unfortunately when opening a c file I see #include and #define
> being black colored.

The faces you look for are, among others:

font-lock-preprocessor-face
font-lock-string-face

You can find that out (and the others) with this function:

(defun what-face (pos)
  (interactive "d")
  (let ((face (or (get-char-property (point) 'read-face-name)
                  (get-char-property (point) 'face))))
    (if face (message "Face: %s" face)
      (message "No face at %d." pos) )))

Or try `describe-char' - possibly, more robust, but also
verbose/disruptive (it opens a new buffer, as opposed to using the
echo area).

Then, in ~/.emacs, set it up like this:

(custom-set-faces
 ;;; gnus face
 '(gnus-cite-1 ((t (:foreground "yellow" :bold nil))))
 '(gnus-cite-2 ((t (:foreground "green"  :bold nil))))
 '(gnus-cite-3 ((t (:foreground "blue"   :bold t  ))))
 ; ...
 )

Only, of course, you are not setting up the Gnus colors.

-- 
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573


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

* Re: Unexpected font face in C mode
  2013-08-09 20:35 Unexpected font face in C mode Rami A
  2013-08-09 22:37 ` Emanuel Berg
@ 2013-08-12 18:52 ` Rami A
  1 sibling, 0 replies; 3+ messages in thread
From: Rami A @ 2013-08-12 18:52 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Emanual,
Thanks for the response.
When I implemented your function it did show that both #define/#include and #if/#endif as being font-lock-preprocessor-face and that's the problem.
I want to have #include/#define of a different color than the rest of preprocessors.


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

end of thread, other threads:[~2013-08-12 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-09 20:35 Unexpected font face in C mode Rami A
2013-08-09 22:37 ` Emanuel Berg
2013-08-12 18:52 ` Rami A

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