-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
198 lines (124 loc) · 4.96 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
Put the following into your initialization file:
(setq py-install-directory "PATH/TO/PYTHON-MODE/")
(add-to-list 'load-path py-install-directory)
(require 'python-mode)
Unless other libraries depend on python.el, unloading 'python is recommended, as it seems to destroy python-mode user defined abbreviations:
(when (featurep 'python) (unload-feature 'python t))
;;;;;;;;;
Customize default Python shell as `py-shell-name'
`py-shell-name' might be an installed executable as
shell command `type' would display, but also a
PATH/TO/(I)PYTHON, of a virtualenv for example
To change the Python default shell see also INSTALL
Most python-mode.el commands start with prefix `py-'
`M-x py- TAB'
displays a list of them in completion-buffer.
See also commands list delivered in directory doc.
List virtualenv related `M-x virtualenv- TAB'
resp. Pymacs commands `M-x pymacs-'
Commands related to a specific shell start with
it's name as `ipython-complete'.
Open an installed shell by
M-x SHELL
With prefix C-u user is prompted to specify a PATH-TO-LOCAL-SHELL
Also evaluating
(py-shell nil DEDICATED PATH-TO-LOCAL-SHELL)
if DEDICATED is set to `t', shell will get an unique name.
Install a local shell by evaluating
(defun MY-LOCAL-SHELL ()
(interactive)
(py-shell nil DEDICATED PATH-TO-LOCAL-SHELL))
;;;;;;;;;
Python code might be processed by an
- interactive Python shell (DEFAULT)
- non-interactive Python (`py-fast-process-p', if large output)
Both processes might run in
- session, i.e. start from possible previous state (DEFAULT)
- dedicated, (`py-dedicated-process-p') run in separate process
There is also
- python-mode-v5-behavior
;;;;;;;;;
To enable code auto-completion:
(setq py-load-pymacs-p t)
To use auto-complete, just prepend the following lines:
(require 'auto-complete-config)
(ac-config-default)
or for company:
(autoload 'company-mode "company" nil t)
If you do not use one of those visual completion interfaces, key bindings exist:
- C-tab complete symbol
- f1 show help
- S-f1 show signature
- f2 go to
If `py-complete-function' is set, it takes precedence
;;;;;;;;;
smart-operator minor mode
for example with key "+"
inserts " + "
smart-operator extended by augmented-assigments
C-u +
inserts " += "
customizable boolean `py-smart-operator-mode-p'
;;;;;;;;;
Beside common moves like `defun', `statement' specific Python-mode edits are delivered:
`py-expression' and `py-partial-expression'.
Statement below is considered composed of two `py-expression'
a = ['spam', 'eggs', 100, 1234]
|_| |_________________________|
Assigment operator and all inside comments is ignored.
`py-partial-expression' would match six sections
a = ['spam', 'eggs', 100, 1234]
|_| |_____| |____| |__| |__|
|_________________________|
When traversing code, `py-partial-expression' climbs down and up
all levels encountered, i.e. at opening `[' `py-expression' would return ['spam', 'eggs', 100, 1234], while one char behind at `''
it yields `'spam','
- py-sexp-function,
When set, it's value is called instead of `forward-sexp', `backward-sexp
Choices are py-partial-expression, py-expression, default nil
;;;;;;;;;
Moving, copying, deleting
When moving over or mark code, commands with suffix
"-bol" take the correspond beginning of line as start
resp. end. Commands without that suffix take the
indentation at the beginning resp. the last printable
character the end - see in menu PyEdit whats implemented.
While commands "py-beginning..." resp. "py-end..." compute the context,
selecting the corresponding beginning or end
new "py-up...", "py-down..." jump regexp-based to the
next element in buffer.
Listed in PyMenu.
;;;;;;;;;
Customize boolean `py-set-fill-column-p'
If `t', enables use Python specific `fill-column' according to
`py-docstring-fill-column', default is 72
and `py-comment-fill-column, default is 79
Comment- and docstring settings might be disabled by
any non-integer value, which means: do not use a
different value of `fill-column' than emacs-wide
;;;;;;;;;
- customizable `py-output-buffer'.
`py-execute-...'-commands arrive in buffer created by
`py-shell'. It's name is composed WRT to Python
version used, it's path etc. If boolean
`py-enforce-output-buffer-p' is non-nil, value of
`py-output-buffer' is taken instead.
;;;;;;;;;
Python and IPython
Start IPython shell after loading python-mode via M-x
ipython, not from plain shell.
Executing code through IPython should work as with
regular Python, also getting completions from. However,
with IPython, it feels a demi-second slower. Also when
starting a session, first completion might fail, while
succeeding afterwards. Any bug reports, which might
help truck down the issue, are highly appreciated.
;;;;;;;;;
Troubleshooting
Start with Emacs -Q from the directory where python-mode.el lives.
Open python-mode.el and evaluate it.
Open a file with ending ".py".
M-x python RET
a regular Python-shell should appear
M-x IPython RET
an IPython-shell should be opened