Being Productive With Emacs

http://stuff.mit.edu/iap/2009/emacs/

Phil Sung

MIT, CSAIL; psung@alum.mit.edu

Last time

Today

Why Elisp?

What is elisp used for?

Example: setting a variable

Running elisp

The init file

Example: variables and functions

Key bindings

Example: rebinding keys

Example: rebinding keys

Key binding conventions

Hooks

Example: hooks

Hooks

What's with all the parentheses?

Evaluating expressions

Control flow in elisp

Local variables

Functions

Example: square

Commands vs. functions

Commands vs. functions

Interactive specifications

Interactive specifications

Interactive specifications

Interactive specifications

Manipulating Emacs from elisp

Example: count-words

Example: count-words

(defun count-words ()
  "Print the number of words in the buffer."
  (interactive)
  (let ((count 0))
    (goto-char (point-min))
    (while (???)
      (setq count (1+ count)))
    (message "Buffer contains %d words" count)))

Example: count-words

(defun count-words ()
  "Print the number of words in the buffer."
  (interactive)
  (let ((count 0))
    (goto-char (point-min))
    (while (and (< (point) (point-max))
                (re-search-forward "\\w+\\W*" (point-max) t))
      (setq count (1+ count)))
    (message "Buffer contains %d words" count)))

Example: count-words

Example: count-words

(defun count-words ()
  "Print the number of words in the buffer."
  (interactive)
  (save-excursion
    (let ((count 0))
      (goto-char (point-min))
      (while (and (< (point) (point-max))
                  (re-search-forward "\\w+\\W*" (point-max) t))
        (setq count (1+ count)))
      (message "Buffer contains %d words" count))))

Homework

Manipulating text with elisp

Finding the right functions

Recap

Next steps