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:
- You should make the first line a complete sentence since
some commands, such as `apropos', print only the first line
of a multi-line documentation string.
- You should not indent the second line of a documentation
string, if you have one, because that looks odd when you use
`C-h f' (`describe-function').
Variables
The relationship between setq and defvar
- setq and defvar both can bind a variable to a value.
- setq can't set document string for variables, but defvar
can.
- defvar can't set multiple variables, but setq can.
- setq returns variable value, but defvar returns variable
name.