Elisp Notes

Elementary

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.
M-:
eval any expression in the minibuffer.

Some elementary functions

(buffer-name)
(buffer-file-name)
(current-buffer)
(other-buffer)
(switch-to-buffer (other-buffer))
(buffer-size)
(point)
(point-min)
(point-max)

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 () 
    (interactive)
    (switch-to-buffer (other-buffer))))

a less useful one:

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

Function definitions

About document string:

Variables

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.