syntax highlightening

Harry George harry.g.george at boeing.com
Fri Oct 31 04:15:36 EST 2003


mis6 at pitt.edu (Michele Simionato) writes:

> I would like to change the pre-defined colors in the Emacs
> python mode, but I don't have any clue on how to do it. 
> Somebody can help here?
> TIA,
> 
>                 Michele


The coloring is controlled by "font-lock".  python-mode.el (found in
e.g., share/emacs/21.3/lisp/progmodes) maps specific words to
font-lock attributes.  E.g., "if" is a font-lock-keyword., "print" is
a font-lock-builtin.  However, you can probably guess the attributes
you want to change from the font-lock.el, without having to look at
python-mode.el:

(defvar font-lock-comment-face		'font-lock-comment-face
  "Face name to use for comments.")

(defvar font-lock-string-face		'font-lock-string-face
  "Face name to use for strings.")

(defvar font-lock-doc-face		'font-lock-doc-face
  "Face name to use for documentation.")

(defvar font-lock-keyword-face		'font-lock-keyword-face
  "Face name to use for keywords.")

(defvar font-lock-builtin-face		'font-lock-builtin-face
  "Face name to use for builtins.")

(defvar font-lock-function-name-face	'font-lock-function-name-face
  "Face name to use for function names.")

(defvar font-lock-variable-name-face	'font-lock-variable-name-face
  "Face name to use for variable names.")

(defvar font-lock-type-face		'font-lock-type-face
  "Face name to use for type and class names.")

(defvar font-lock-constant-face		'font-lock-constant-face
  "Face name to use for constant and label names.")

(defvar font-lock-warning-face		'font-lock-warning-face
  "Face name to use for things that should stand out.")

(defvar font-lock-reference-face	'font-lock-constant-face
  "This variable is obsolete.  Use `font-lock-constant-face'.")


Once you know the proper font-lock attribute, you can change the color
by settings in you personal .emacs, e.g.:


(defun python-initialise ()
  (interactive)
  (setq default-tab-width 4)
  (setq indent-tabs-mode nil)
  (set-face-foreground `font-lock-comment-face "green")
  (set-face-background `font-lock-comment-face "red")
)

-- 
harry.g.george at boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601




More information about the Python-list mailing list