Elisp Notes


How to evaluate a sexp?

Many ways:

C-x C-e
eval the sexp and display the result in the echo area.
C-u C-x C-e
eval the sexp and insert the result at point.
eval any expression in the minibuffer.

Some elementary functions

(switch-to-buffer (other-buffer))

a convenient key to switch buffers

(define-prefix-command 'ctl-z-map)
(global-set-key (kbd "C-z") 'ctl-z-map)
(define-key ctl-z-map (kbd "C-z")
  (lambda () 
    (switch-to-buffer (other-buffer))))

a less useful one:

(switch-to-buffer (other-buffer (current-buffer) t))

Function definitions

About document string:


The relationship between setq and defvar

  1. setq and defvar both can bind a variable to a value.
  2. setq can't set document string for variables, but defvar can.
  3. defvar can't set multiple variables, but setq can.
  4. setq returns variable value, but defvar returns variable name.