How to Learn Emacs Lisp?

By Xah Lee. Date: . Last updated: .

A few people have expressed this problem of learning elisp. It goes like this:

I've read the basic of elisp, but how do you actually stick to it?

Here's a suggestion. Suppose you code in Ruby (or C, PHP, Perl, Python, …). Now, begin by stop using the default major mode. Roll your own! This is actually easier than it sounds. You can begin by writing a very basic mode, that does nothing but syntax coloring of the keywords. This is very easy. If you know the basic syntax of elisp, you can do this in a hour. See: How to Write a Emacs Major Mode for Syntax Coloring.

Once you have that, setup emacs to use your own mode. [see Emacs: Set Default Major Mode]

Now, you will start to find problems. For example, keyword completion, function templates, reference lookup, indentation. You can now gradually add features, add commands.

Soon, you'll have learned a ton of elisp. If you keep at it, after a year, you'll end up with your own robust mode. You'll also start to understand all the useful packages you installed. Maybe fixed some bugs or added features. And maybe write something useful that doesn't exist yet.

My Path to Emacs Lisp

My path to elisp is similar to this. I code HTML raw since 1996, by manually typing each tag. I started to use emacs in 1998. Emacs's HTML mode is very basic, i started to master that mode, to insert tags, delete tags. I started to learn elisp in 2006. I started to write many commands to help me code and maintain my websites, that's about 5 thousand hand-coded HTML pages (with the help of emacs automation, and some perl, python, scripts. (vast majority of these scripts are now emacs lisp)).

Here's one of my first elisp code. I was actually overjoyed when i learned it.

(defun insert-p-tag ()
  "Insert <p></p> at cursor point."
  (insert "<p></p>")
  (backward-char 4))

Today, this code went thru many versions, and now is a full html mode of 5k lines. Emacs: Xah HTML Mode

I have close to a hundred other commands for HTML. For example:

And any CSS related needs, HTML5, … anything i need or want. After some 5 years, i started my own HTML mode, the way i wanted things to work. [see Emacs: Xah HTML Mode]

When you use a light-weight markup system, you type a few chars to markup, such as =title= or ==title==. [see Markdown Tutorial] But with my own system, i press ONE KEY to transfrom text under cursor to a customized HTML markup i want. I can confidently say that writing raw HTML is actually faster than using any light-weight markup (such as org-mode or markdown) or any web site framework, plus, i have complete control of the raw HTML code, and can use full HTML features, any tag, not limited to what light-weight markup supports, and the generated HTML are all W3C valid HTML. [see HTML Correctness and Validators]

Interesting? Start your own mode today!

Non-Technical Essays on Emacs Lisp