help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: .c file has no color for most of code in functions, is this normal?


From: jianli zhao
Subject: Re: .c file has no color for most of code in functions, is this normal?
Date: Thu, 15 Oct 2009 00:56:59 -0700 (PDT)
User-agent: G2/1.0

On Oct 15, 7:22 am, jpkotta <jpko...@gmail.com> wrote:
> On Oct 13, 2:16 am, jianli zhao <jianlizh...@gmail.com> wrote:
>
> > main ()
> > {int a,b
> > a=b; <------the text color of this line is black, no face and color
> > for(a=0;a<8;a++) <--------only "for" has color.
> >    a=b;
>
> > }
>
> > Emacs must have way to color these code lines, but how to enable it?
> > Please help!
>
> I think the default syntax highlighting is a bit flat too.  I added
> highlighting for brackets, operators, "warning words", and types.  The
> types should be working by default; I can't remember why I bothered
> with them.
>
> ;;; begin lisp code
> ;; extra syntax highlighting
> (defface font-lock-bracket-face
>   '((t (:foreground "cyan3")))
>   "Font lock mode face for brackets, e.g. '(', ']', etc."
>   :group 'font-lock-faces)
> (defvar font-lock-bracket-face 'font-lock-bracket-face
>   "Font lock mode face for backets.  Changing this directly
>   affects only new buffers.")
>
> (setq c-operators-regexp
>       (regexp-opt '("+" "-" "*" "/" "%" "!"
>                     "&" "^" "~" "|"
>                     "=" "<" ">"
>                     "." "," ";" ":")))
> (setq c-brackets-regexp
>       (regexp-opt '("(" ")" "[" "]" "{" "}")))
> (setq c-types-regexp
>       (concat
>        "\\<[_a-zA-Z][_a-zA-Z0-9]*_t\\>" "\\|"
>        (regexp-opt '("unsigned" "int" "char" "float" "void") 'words)))
>
> (setq warning-words-regexp
>       (regexp-opt '("FIXME" "TODO" "BUG" "XXX" "DEBUG")))
>
> (eval-after-load "cc-mode"
>   '(progn
>      (font-lock-add-keywords
>       'c-mode
>       (list
>        (cons c-operators-regexp 'font-lock-builtin-face)
>        (cons c-brackets-regexp 'font-lock-bracket-face)
>        (cons c-types-regexp 'font-lock-type-face)
>        (cons warning-words-regexp 'font-lock-warning-face)))
>      ))
> ;;; end lisp code
>
> - jpkotta

Thanks, works for me.
I will try to add more keywords.
I wll let you know if I have some result.


reply via email to

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