diff options
| author | Fabián Ezequiel Gallina | 2012-05-17 00:03:22 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-05-17 00:03:22 -0300 |
| commit | 77afb61ab38a795508b0e7767442ae8fea64fbc2 (patch) | |
| tree | 0304ab2f87aeaea41ba5eea741c867c9a6820450 /lisp/progmodes/python.el | |
| parent | 257b0017ef0d33618554664b999a2a18850a39bd (diff) | |
| download | emacs-77afb61ab38a795508b0e7767442ae8fea64fbc2.tar.gz emacs-77afb61ab38a795508b0e7767442ae8fea64fbc2.zip | |
Refactored run-python and run-python-internal.
Created new function python-shell-make-comint that takes care of
creating comint processes.
New Function:
* python-shell-make-comint
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 03524812a2d..3f53d25e0d3 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1245,6 +1245,24 @@ variable. | |||
| 1245 | 'python-shell-completion-complete-or-indent) | 1245 | 'python-shell-completion-complete-or-indent) |
| 1246 | (compilation-shell-minor-mode 1)) | 1246 | (compilation-shell-minor-mode 1)) |
| 1247 | 1247 | ||
| 1248 | (defun python-shell-make-comint (cmd proc-name) | ||
| 1249 | "Create a python shell comint buffer. | ||
| 1250 | CMD is the pythone command to be executed and PROC-NAME is the | ||
| 1251 | process name the comint buffer will get. After the comint buffer | ||
| 1252 | is created the `inferior-python-mode' is activated and the buffer | ||
| 1253 | is shown." | ||
| 1254 | (save-excursion | ||
| 1255 | (let* ((proc-buffer-name (format "*%s*" proc-name)) | ||
| 1256 | (process-environment (python-shell-calculate-process-enviroment)) | ||
| 1257 | (exec-path (python-shell-calculate-exec-path))) | ||
| 1258 | (when (not (comint-check-proc proc-buffer-name)) | ||
| 1259 | (let ((cmdlist (split-string-and-unquote cmd))) | ||
| 1260 | (set-buffer | ||
| 1261 | (apply 'make-comint proc-name (car cmdlist) nil | ||
| 1262 | (cdr cmdlist))) | ||
| 1263 | (inferior-python-mode))) | ||
| 1264 | (pop-to-buffer proc-buffer-name)))) | ||
| 1265 | |||
| 1248 | (defun run-python (dedicated cmd) | 1266 | (defun run-python (dedicated cmd) |
| 1249 | "Run an inferior Python process. | 1267 | "Run an inferior Python process. |
| 1250 | Input and output via buffer named after | 1268 | Input and output via buffer named after |
| @@ -1264,17 +1282,7 @@ run). | |||
| 1264 | (y-or-n-p "Make dedicated process? ") | 1282 | (y-or-n-p "Make dedicated process? ") |
| 1265 | (read-string "Run Python: " (python-shell-parse-command))) | 1283 | (read-string "Run Python: " (python-shell-parse-command))) |
| 1266 | (list nil (python-shell-parse-command)))) | 1284 | (list nil (python-shell-parse-command)))) |
| 1267 | (let* ((proc-name (python-shell-get-process-name dedicated)) | 1285 | (python-shell-make-comint cmd (python-shell-get-process-name dedicated)) |
| 1268 | (proc-buffer-name (format "*%s*" proc-name)) | ||
| 1269 | (process-environment (python-shell-calculate-process-enviroment)) | ||
| 1270 | (exec-path (python-shell-calculate-exec-path))) | ||
| 1271 | (when (not (comint-check-proc proc-buffer-name)) | ||
| 1272 | (let ((cmdlist (split-string-and-unquote cmd))) | ||
| 1273 | (set-buffer | ||
| 1274 | (apply 'make-comint proc-name (car cmdlist) nil | ||
| 1275 | (cdr cmdlist))) | ||
| 1276 | (inferior-python-mode))) | ||
| 1277 | (pop-to-buffer proc-buffer-name)) | ||
| 1278 | dedicated) | 1286 | dedicated) |
| 1279 | 1287 | ||
| 1280 | (defun run-python-internal () | 1288 | (defun run-python-internal () |
| @@ -1292,18 +1300,9 @@ with user shells. Runs the hook | |||
| 1292 | run). \(Type \\[describe-mode] in the process buffer for a list | 1300 | run). \(Type \\[describe-mode] in the process buffer for a list |
| 1293 | of commands.)" | 1301 | of commands.)" |
| 1294 | (interactive) | 1302 | (interactive) |
| 1295 | (save-excursion | 1303 | (python-shell-make-comint |
| 1296 | (let* ((cmd (python-shell-parse-command)) | 1304 | (python-shell-parse-command) |
| 1297 | (proc-name (python-shell-internal-get-process-name)) | 1305 | (python-shell-internal-get-process-name))) |
| 1298 | (proc-buffer-name (format "*%s*" proc-name)) | ||
| 1299 | (process-environment (python-shell-calculate-process-enviroment)) | ||
| 1300 | (exec-path (python-shell-calculate-exec-path))) | ||
| 1301 | (when (not (comint-check-proc proc-buffer-name)) | ||
| 1302 | (let ((cmdlist (split-string-and-unquote cmd))) | ||
| 1303 | (set-buffer | ||
| 1304 | (apply 'make-comint proc-name (car cmdlist) nil | ||
| 1305 | (cdr cmdlist))) | ||
| 1306 | (inferior-python-mode)))))) | ||
| 1307 | 1306 | ||
| 1308 | (defun python-shell-get-process () | 1307 | (defun python-shell-get-process () |
| 1309 | "Get inferior Python process for current buffer and return it." | 1308 | "Get inferior Python process for current buffer and return it." |