elisp

Posted by Deetch on October 29, 2020

EmacsManual.pdf

8.2 Defining Symbols

定义变量

defvar   定义全局变量
defconst 定义全局变量
defcustom(这是一个宏)
setq

定义宏

defmacro

函数定义

defun
defsubst
defalias

5 Lists

'(1 2 (+ 1 2))         ----> (1 2 (+ 1 2))
(list 1 2 (+ 1 2))     ----> (1 2 3)

9 Evaluation

Emacs has three different kinds of form that are evaluated differently: symbols, lists, and “all other types”.

self-evaluating forms

A self-evaluating form is any form that is not a list or symbol. Self-evaluating forms evaluate
to themselves: the result of evaluation is the same object that was evaluated. Thus, the
number 25 evaluates to 25, and the string "foo" evaluates to the string "foo". Likewise,
evaluating a vector does not cause evaluation of the elements of the vector—it returns the
same vector with its contents unchanged.

symbol forms

classification of list forms

A form that is a nonempty list is either a function call, a macro call, or a special form,
according to its first element. These three kinds of forms are evaluated in different ways,
described below. The remaining list elements constitute the arguments for the function,
macro, or special form.

Quoting

Backquote

10 Control Structures

10.1 Sequencing

(progn a b c ...)

11 Variables

let
let*

Dynamic Binding

Lexical Binding

Note that functions like symbol-value, boundp, and set only retrieve or modify a
variable’s dynamic binding (i.e., the contents of its symbol’s value cell). Also, the code in
the body of a defun or defmacro cannot refer to surrounding lexical variables.

When loading an Emacs Lisp file or evaluating a Lisp buffer, lexical binding is enabled if
the buffer-local variable lexical-binding is non-nil
开启词法绑定,文件第一行
;;; -*- lexical-binding: t; -*-
使用 defcustom、defvar 以及 defconst 定义的变量被称为特殊变量,不论词法绑定是否启用,它们都将使用动态绑定
使用 let 或者函数参数绑定的局部变量会遵循由 lexical-binding 变量定义的查找规则,
但使用 defvar、defconst 或 defcustom 定义的全局变量,能够沿着调用栈在 let 表达式中被修改

Buffer-Local Variables

File Local Variables

Function

#' is a short-hand for using function.
The following forms are all equivalent:
(lambda (x) (* x x))
(function (lambda (x) (* x x)))
#’(lambda (x) (* x x))

13 Macros

quote
'()

backquote `()

13.5.1 Wrong Time

13.5.2 Evaluating Macro Arguments Repeatedly

13.5.3 Local Variables in Macro Expansions

13.5.4 Evaluating Macro Arguments in Expansion

How Many Times is the Macro Expanded

15.5 Autoloading