all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* .c file has no color for most of code in functions, is this normal?
@ 2009-10-13  7:16 jianli zhao
  2009-10-14 23:22 ` jpkotta
  0 siblings, 1 reply; 3+ messages in thread
From: jianli zhao @ 2009-10-13  7:16 UTC (permalink / raw
  To: help-gnu-emacs

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!


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

* Re: .c file has no color for most of code in functions, is this  normal?
  2009-10-13  7:16 .c file has no color for most of code in functions, is this normal? jianli zhao
@ 2009-10-14 23:22 ` jpkotta
  2009-10-15  7:56   ` jianli zhao
  0 siblings, 1 reply; 3+ messages in thread
From: jpkotta @ 2009-10-14 23:22 UTC (permalink / raw
  To: help-gnu-emacs

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


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

* Re: .c file has no color for most of code in functions, is this  normal?
  2009-10-14 23:22 ` jpkotta
@ 2009-10-15  7:56   ` jianli zhao
  0 siblings, 0 replies; 3+ messages in thread
From: jianli zhao @ 2009-10-15  7:56 UTC (permalink / raw
  To: help-gnu-emacs

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.


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

end of thread, other threads:[~2009-10-15  7:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-13  7:16 .c file has no color for most of code in functions, is this normal? jianli zhao
2009-10-14 23:22 ` jpkotta
2009-10-15  7:56   ` jianli zhao

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.