1
;;; python-mode-shell-install.el --- Installing python, python3, ipython and other python shells
3
;; Copyright (C) 2011 Andreas Roehler
5
;; Author: Andreas Roehler <andreas.roehler@online.de>
6
;; Keywords: languages, processes, python, oop
8
;; Python-components-mode started from python-mode.el
9
;; and python.el, where Tim Peters, Barry A. Warsaw,
10
;; Skip Montanaro, Ken Manheimer, Dave Love and many
11
;; others wrote major parts. Author of ipython.el's
12
;; stuff merged is Alexander Schmolck.
14
;; This program is free software; you can redistribute it and/or modify
15
;; it under the terms of the GNU General Public License as published by
16
;; the Free Software Foundation, either version 3 of the License, or
17
;; (at your option) any later version.
19
;; This program is distributed in the hope that it will be useful,
20
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
;; GNU General Public License for more details.
24
;; You should have received a copy of the GNU General Public License
25
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
29
;; Provides utilities creating python-mode commands
34
'("python" "python2" "python2.7" "python3" "python3.2" "ipython" "jython")
35
"Python-mode will generate commands opening shells mentioned here. Edit this list \w resp. to your machine. "
36
:type '(repeat string)
39
(setq py-shells '("python" "python2" "python2.7" "python3" "python3.2" "ipython" "jython"))
41
(defun py-provide-installed-shells-commands ()
42
"Reads py-shells, provides commands opening these shell. "
44
(let ((temp-buffer "*Python Shell Install Buffer*"))
45
(set-buffer (get-buffer-create temp-buffer))
47
(insert ";;; Python named shells")
49
(dolist (ele py-shells)
50
(insert (concat "(defun " ele " (&optional argprompt)
52
(if (string= "ipython" ele)
54
(insert (capitalize ele)))
55
(insert (concat " interpreter in another window.
56
With optional \\\\[universal-argument] user is prompted
57
for options to pass to the "))
58
(if (string= "ipython" ele)
60
(insert (capitalize ele)))
61
(insert (concat " interpreter. \"
63
(py-set-shell-completion-environment)
64
(py-shell argprompt nil \"" ele "\"))\n\n")))
65
(insert ";; dedicated\n")
66
(dolist (ele py-shells)
67
(insert (concat "(defun " ele "-dedicated (&optional argprompt)
69
(if (string= "ipython" ele)
71
(insert (capitalize ele)))
72
(insert (concat " dedicated interpreter in another window.
73
With optional \\\\[universal-argument] user is prompted
74
for options to pass to the "))
75
(if (string= "ipython" ele)
77
(insert (capitalize ele)))
78
(insert (concat " interpreter. \"
80
(py-set-shell-completion-environment)
81
(py-shell argprompt t \"" ele "\"))\n\n"))))
83
(switch-to-buffer (current-buffer)))
85
(defun py-write-beginning-position-forms ()
87
(set-buffer (get-buffer-create "py-write-beginning-position-forms"))
89
(dolist (ele py-shift-forms)
91
(defun py-beginning-of-" ele "-position ()
92
\"Returns beginning of " ele " position. \"
95
(let ((erg (py-beginning-of-" ele ")))
96
(when (interactive-p) (message \"%s\" erg))
100
(defun py-write-end-position-forms ()
102
(set-buffer (get-buffer-create "py-write-end-position-forms"))
104
(dolist (ele py-shift-forms)
106
(defun py-end-of-" ele "-position ()
107
\"Returns end of " ele " position. \"
110
(let ((erg (py-end-of-" ele ")))
111
(when (interactive-p) (message \"%s\" erg))
115
(setq py-shift-forms (list "paragraph" "block" "clause" "def" "class" "line" "statement"))
117
(defun py-write-shift-forms ()
120
(set-buffer (get-buffer-create "py-shift-forms"))
122
(dolist (ele py-shift-forms)
124
\(defun py-shift-" ele "-right (&optional arg)
125
\"Indent " ele " by COUNT spaces.
127
COUNT defaults to `py-indent-offset',
128
use \\[universal-argument] to specify a different value.
130
Returns outmost indentation reached. \"
131
(interactive \"\*P\")
132
(let ((erg (py-shift-forms-base \"" ele "\" (or arg py-indent-offset))))
133
(when (interactive-p) (message \"%s\" erg))
136
\(defun py-shift-" ele "-left (&optional arg)
137
\"Dedent " ele " by COUNT spaces.
139
COUNT defaults to `py-indent-offset',
140
use \\[universal-argument] to specify a different value.
142
Returns outmost indentation reached. \"
143
(interactive \"\*P\")
144
(let ((erg (py-shift-forms-base \"" ele "\" (- (or arg py-indent-offset)))))
145
(when (interactive-p) (message \"%s\" erg))
149
(switch-to-buffer (current-buffer))))
151
(setq py-down-forms (list "block" "clause" "block-or-clause" "def" "class" "def-or-class"))
153
(defun py-write-down-forms-lc ()
156
(set-buffer (get-buffer-create "py-down-forms-lc.el"))
158
(dolist (ele py-down-forms)
160
\(defun py-down-" ele "-lc ()
161
\"Goto beginning of line following end of " ele ".
162
Returns position reached, if successful, nil otherwise.
164
\\\"-lc\\\" stands for \\\"left-corner\\\" - a complementary command travelling left, whilst `py-end-of-" ele "' stops at right corner.
166
See also `py-down-" ele "': down from current definition to next beginning of " ele " below. \"
168
(let ((erg (py-end-of-" ele ")))
174
(when (interactive-p) (message \"%s\" erg))
178
(switch-to-buffer (current-buffer))))
180
(defun py-write-down-forms ()
183
(set-buffer (get-buffer-create "py-down-forms.el"))
185
(dolist (ele py-down-forms)
187
\(defun py-down-" ele " ()
188
\"Go to the beginning of next " ele " below in buffer.
190
Returns indentation if " ele " found, nil otherwise. \"
192
(let\* ((orig (point))
196
(while (and (setq erg (py-down-statement))(or (py-in-string-or-comment-p)(not (looking-at py-" ele "-re))))))
197
(when (interactive-p) (message \"%s\" erg))
201
(switch-to-buffer (current-buffer))))
203
(defun py-write-up-forms ()
206
(set-buffer (get-buffer-create "py-up-forms"))
208
(dolist (ele py-down-forms)
210
\(defun py-up-" ele " ()
211
\"Goto end of line preceding beginning of " ele ".
212
Returns position reached, if successful, nil otherwise.
214
A complementary command travelling right, whilst `py-beginning-of-" ele "' stops at left corner. \"
216
(let ((erg (py-beginning-of-" ele ")))
221
(skip-chars-backward \" \\t\\r\\n\\f\")
223
(when (interactive-p) (message \"%s\" erg))
227
(switch-to-buffer (current-buffer))))
229
(defun py-write-specifying-shell-forms ()
232
(set-buffer (get-buffer-create "specifying-shell-forms"))
234
(dolist (ele py-shells)
236
(defun py-execute-region-" ele " (start end &optional async)
237
\"Send the region to a common shell calling the " ele " interpreter. \"
238
(interactive \"r\\nP\")
239
(py-execute-base start end async \"" ele "\"))
241
(defun py-execute-region-" ele "-switch (start end &optional async)
242
\"Send the region to a common shell calling the " ele " interpreter.
243
Ignores setting of `py-shell-switch-buffers-on-execute', output-buffer will being switched to. \"
244
(interactive \"r\\nP\")
245
(let ((py-shell-switch-buffers-on-execute t))
246
(py-execute-base start end async \"" ele "\")))
248
(defun py-execute-region-" ele "-no-switch (start end &optional async)
249
\"Send the region to a common shell calling the " ele " interpreter.
250
Ignores setting of `py-shell-switch-buffers-on-execute', output-buffer will not being switched to.\"
251
(interactive \"r\\nP\")
252
(let ((py-shell-switch-buffers-on-execute))
253
(py-execute-base start end async \"" ele "\")))
256
(switch-to-buffer (current-buffer))))
258
(provide 'python-mode-shell-install)
259
;;; python-mode-shell-install.el ends here