# Emacs highlighting, keywords

**URL:** <https://www.ruby-forum.com/t/emacs-highlighting-keywords/119179>\
**Category:** Ruby\
**Created:** [November 4, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/emacs-highlighting-keywords/119179 "2007-11-04T13:45:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rolfa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@rolfa](https://www.ruby-forum.com/u/rolfa)\
**Post date:** [November 4, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/emacs-highlighting-keywords/119179/1 "2007-11-04T13:45:09Z")

</div>

Hi,

I’m a new user trying to set up a Ruby dev environment. I’ve gotten to  
the point where emacs is willing to highlight some syntax, but not all.  
Specifically, I get strings in grey and comments in red, but keywords  
(‘class’, ‘def’, ‘end’) stay stubbornly black, as do class and variable  
names. Keywords do get highlighted in .C files, so it does not seem to  
be a global emacs issue.

I wonder if the issue can be that font-lock-defaults is not getting  
defined properly, for its value is nil in my test.rb file. Can anyone  
help me understand how to get it properly set?

Background information: I am using GNU Emacs 21.3.1  
(i386-mingw-nt5.1.2600), on Windows XP, and Ruby version 1.8.6. I am  
loading ruby mode with the following lines in my .emacs:

(setq load-path (append load-path  
'(“D:/ruby/doc/ruby/ruby-1.8.6/misc”)))  
(autoload 'ruby-mode “ruby-mode” “Major mode for editing ruby scripts.”  
t)  
(setq auto-mode-alist (cons '("\.rb$" . ruby-mode) auto-mode-alist))  
(setq interpreter-mode-alist (append '((“ruby” . ruby-mode))  
interpreter-mode-alist))

Thanks,

Rolf A…

---

<div class="post-metadata">

**Author:** ![rolfa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/779978/32.png) [@rolfa](https://www.ruby-forum.com/u/rolfa)\
**Post date:** [November 4, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/emacs-highlighting-keywords/119179/2 "2007-11-04T16:16:29Z")

</div>

On Nov 4, 2007, at 7:45 AM, Rolf A. wrote:

> (autoload 'ruby-mode “ruby-mode” “Major mode for editing ruby  
> scripts.”  
> t)  
> (setq auto-mode-alist (cons '(“\.rb$” . ruby-mode) auto-mode-alist))  
> (setq interpreter-mode-alist (append '((“ruby” . ruby-mode))  
> interpreter-mode-alist))
> 
> Thanks,
> 
> Rolf A…

I set these font faces before I autoload the ruby-mode. It’s old  
'cause I’ve been using Emacs for a looong time, but my keywords in  
ruby-mode are now cyan (and have been for ages so I have no clue what  
they were normally). I use a black background so you may have to  
change some of the colors if you prefer a light background.

(require 'font-core)  
(require 'font-lock)

(setq font-lock-maximum-decoration t)  
(global-font-lock-mode t nil) ; this is what I want! (8/26/01)

(setq font-lock-face-attributes  
(list  
'(font-lock-comment-face “firebrick” nil nil nil nil)  
'(font-lock-function-name-face “orange” nil nil nil nil)  
'(font-lock-keyword-face “cyan” nil nil nil nil)  
;; '(font-lock-reference-face “red” nil nil nil nil)  
'(font-lock-string-face “blue” nil nil nil nil)  
'(font-lock-type-face “magenta” nil nil nil nil)  
'(font-lock-variable-name-face “green” nil nil nil nil)  
))

I also have this bit (probably from a couple years ago) that, I think,  
shows a better way to set fonts that are at least minimally aware of  
the lightness or darkness of the background. (e.g., the '(background  
light) list)

(custom-set-faces  
;; custom-set-faces was added by Custom.  
;; If you edit it by hand, you could mess it up, so be careful.  
;; Your init file should contain only one such instance.  
;; If there is more than one, they won’t work right.  
'(cperl-array ((((class color) (background light)) (:background  
“lightyellow2” :foreground “Blue”))))  
'(cperl-hash ((((class color) (background light)) (:background  
“lightyellow2” :foreground “Red” :slant italic))))  
)

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
