Part 3: lists and color

Continued from Emacs Lisp programming pt. 2.

Going through a list

ELISP> (setq bar '("do" "re" "mi" "fa"))
("do" "re" "mi" "fa")

ELISP> (dolist (note bar)
	 (insert note))
nil
ELISP> doremifa

Lists within lists

ELISP> (setq foo '(("hello" 5)
		   ("bye" 2)
		   ("later" 7)))
(("hello" 5)
 ("bye" 2)
 ("later" 7))

ELISP> (dolist (item foo)
	 (dotimes (x (nth 1 item))
	   (insert (nth 0 item)))
	 (newline))
nil
ELISP> hellohellohellohellohello
byebye
laterlaterlaterlaterlaterlaterlater

Using color:

(insert (propertize "bar" 'face '(:foreground "red")))
(insert (propertize "bar" 'face '(:background "gray30")))
(insert (propertize "bar" 'face '(:foreground "#33AAFF")))
(insert (propertize "bar" 'face '(:foreground "orange" :background "purple")))

To make this work in ielm, first type M-x font-lock-mode. You should see a message at the bottom of the screen Font-Lock mode disabled (if it says enabled, type M-x font-lock-mode again).

Continued in Emacs Lisp programming pt. 4.