[ESS] Enhanced syntax highlighting (R-wiki style)

Vitalie Spinu vitosmail at rambler.ru
Mon Jul 7 12:01:03 CEST 2008

Dear ESS useRs,

I changed the predefined keywords for syntax highlighting in R so that the  
functions face (and optionally data.frames and vectors) could be  

In case somebody is also interested in improving his/her code salad I  
provide the following lines which should be placed in .emacs file.

A short description:
First, a new face font-lock-my-functions-face is defined (you can  
customise it here or interactively, see EDIT>Text Properties> Display  
Faces ). To change into R-wiki style place (:foreground "ForestGreen"  
:weight bold ) in the font definition section below.

Second, the reg expression is defined.
If you also wish to highlight data.frames and vectors, preceding "[",  
change the regexp string to :    

Finally the highlight pattern is appended to lists of keywords for  
ess-mode and inferior-ess-mode.



;;Declaration of new font face in font-lock-faces group.
;;You can customize it directly below, or via [Edit][Text  
Properties][Display Faces]
;;To see all valid colors go to [Edit][Text Properties][Display Colors]

(defface font-lock-my-functions-face
   '((((class color) (min-colors 88) (background light))
      (:foreground "RoyalBlue4"  ) ;;see customisation buffer for vald keys
     ;(:foreground "ForestGreen" :weight bold :slant italic) ;R-wiki style
  "Font Lock mode face used to highlight function names."
     :group 'font-lock-faces)

(defvar font-lock-my-functions-face		'font-lock-my-functions-face
   "Face name to use for functions.")

(defvar ess-R-my-functions-name-regexp
   "Regexp for function names")

(defvar functions-color  ;;define the highlighter
    (cons ess-R-my-functions-name-regexp	 '(1 font-lock-my-functions-face  
keep) ))
   "Defines highlighting pattern for functions")

;; Append the highlighter to lists of predefined patterns:
(setq ess-R-mode-font-lock-keywords
       (append  ess-R-mode-font-lock-keywords    functions-color ))
(setq inferior-ess-R-font-lock-keywords
       (append inferior-ess-R-font-lock-keywords functions-color))

More information about the ESS-help mailing list