all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: jpkotta <jpkotta@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: .c file has no color for most of code in functions, is this  normal?
Date: Wed, 14 Oct 2009 16:22:43 -0700 (PDT)	[thread overview]
Message-ID: <2c6114e6-edd4-4796-83a6-9d60906d2ffa@a31g2000yqn.googlegroups.com> (raw)
In-Reply-To: c869e13d-9c9a-450b-8435-8e8d8a4d3c56@v37g2000prg.googlegroups.com

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


  reply	other threads:[~2009-10-14 23:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2009-10-15  7:56   ` jianli zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2c6114e6-edd4-4796-83a6-9d60906d2ffa@a31g2000yqn.googlegroups.com \
    --to=jpkotta@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.