1+ .. py :currentmodule :: emacs.elisp.ast
2+
3+
14 Representing Emacs lisp code in Python
25======================================
36
@@ -50,8 +53,18 @@ Python lists are converted to quoted Elisp lists, while tuples are left unquoted
5053 <el ("a" "b" "c")>
5154
5255
53- Elements of lists/tuples are recursively converted using :meth: `to_elisp ` if
54- they are not already instances of :class: `ElispAstNode `.
56+ Python dicts and other mapping types are converted using :func: `make_alist ` (see
57+ below):
58+
59+ .. doctest ::
60+
61+ >>> el.to_elisp({' a' : 1 , ' b' : 2 })
62+ <el ((cons a 1) (cons b 2))>
63+
64+
65+ Elements of composite data types (lists, tuples, dicts) are recursively
66+ converted using :meth: `to_elisp ` if they are not already instances of
67+ :class: `ElispAstNode `.
5568
5669You can use :func: `quote ` to quote a value. It will also convert strings to
5770quoted symbols:
@@ -69,14 +82,22 @@ quoted symbols:
6982 <el 'foo>
7083
7184
72- Other shortcuts are :func: ` cons ` to create a cons cell, or :func: ` symbols ` to
73- create a list of symbols :
85+ A a form that must be constructed directly because it has no Python equivalent
86+ is the cons cell, represented with the class :class: ` Cons ` :
7487
7588.. doctest ::
7689
77- >>> el.cons (el.Symbol(' a' ), 1 )
90+ >>> el.Cons (el.Symbol(' a' ), 1 )
7891 <el (cons a 1)>
7992
93+ >>> el.quote(el.Cons(el.Symbol(' a' ), 1 ))
94+ <el '(a . 1)>
95+
96+
97+ The :func: `symbols ` function can be used to create a list of symbols:
98+
99+ .. doctest ::
100+
80101 >>> el.symbols(' a' , ' b' , ' c' )
81102 <el (a b c)>
82103
@@ -109,17 +130,23 @@ be inserted verbatim in the given location:
109130Using Elisp forms
110131-----------------
111132
112- Elisp forms can be passed to :meth: `Elisp.eval ` and :meth: `Elisp.getresult ` for
133+ .. py :currentmodule :: emacs.emacs
134+
135+
136+ Elisp forms can be passed to :meth: `Emacs.eval ` and :meth: `Emacs.getresult ` for
113137execution. You can also convert them to strings to produce (hopefully)
114138syntactically-correct Elisp code.
115139
116140
117141Elisp DSL
118142---------
119143
144+ .. py :currentmodule :: emacs.elisp.ast
145+
146+
120147 This package also includes an unholy abomination of a DSL that lets you write
121148Elisp code in Python. The DSL is implemented through a singleton object which
122- is importable as :data: `emacs.elisp.E `::
149+ is importable as :data: `emacs.elisp.E <emacs.elisp.dsl.E> `::
123150
124151 >>> from emacs.elisp import E
125152
@@ -163,7 +190,7 @@ Symbols can be called as functions, generating Elisp function calls:
163190
164191
165192Additionally, the ``Q ``, ``C ``, ``S ``, and ``R `` methods are aliases for the
166- :func: `quote `, :func: ` cons `, :func: `symbols `, and :class: `Raw `, respectively.
193+ :func: `quote `, :class: ` Cons `, :func: `symbols `, and :class: `Raw `, respectively.
167194
168195Using just the ``E `` object, it is possible to write complex Elisp forms:
169196
0 commit comments