From: Fabián Ezequiel Gallina Date: Thu, 17 May 2012 03:03:22 +0000 (-0300) Subject: Refactored run-python and run-python-internal. X-Git-Tag: emacs-24.2.90~1199^2~545 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=77afb61ab38a795508b0e7767442ae8fea64fbc2;p=emacs.git 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 --- 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. 'python-shell-completion-complete-or-indent) (compilation-shell-minor-mode 1)) +(defun python-shell-make-comint (cmd proc-name) + "Create a python shell comint buffer. +CMD is the pythone command to be executed and PROC-NAME is the +process name the comint buffer will get. After the comint buffer +is created the `inferior-python-mode' is activated and the buffer +is shown." + (save-excursion + (let* ((proc-buffer-name (format "*%s*" proc-name)) + (process-environment (python-shell-calculate-process-enviroment)) + (exec-path (python-shell-calculate-exec-path))) + (when (not (comint-check-proc proc-buffer-name)) + (let ((cmdlist (split-string-and-unquote cmd))) + (set-buffer + (apply 'make-comint proc-name (car cmdlist) nil + (cdr cmdlist))) + (inferior-python-mode))) + (pop-to-buffer proc-buffer-name)))) + (defun run-python (dedicated cmd) "Run an inferior Python process. Input and output via buffer named after @@ -1264,17 +1282,7 @@ run). (y-or-n-p "Make dedicated process? ") (read-string "Run Python: " (python-shell-parse-command))) (list nil (python-shell-parse-command)))) - (let* ((proc-name (python-shell-get-process-name dedicated)) - (proc-buffer-name (format "*%s*" proc-name)) - (process-environment (python-shell-calculate-process-enviroment)) - (exec-path (python-shell-calculate-exec-path))) - (when (not (comint-check-proc proc-buffer-name)) - (let ((cmdlist (split-string-and-unquote cmd))) - (set-buffer - (apply 'make-comint proc-name (car cmdlist) nil - (cdr cmdlist))) - (inferior-python-mode))) - (pop-to-buffer proc-buffer-name)) + (python-shell-make-comint cmd (python-shell-get-process-name dedicated)) dedicated) (defun run-python-internal () @@ -1292,18 +1300,9 @@ with user shells. Runs the hook run). \(Type \\[describe-mode] in the process buffer for a list of commands.)" (interactive) - (save-excursion - (let* ((cmd (python-shell-parse-command)) - (proc-name (python-shell-internal-get-process-name)) - (proc-buffer-name (format "*%s*" proc-name)) - (process-environment (python-shell-calculate-process-enviroment)) - (exec-path (python-shell-calculate-exec-path))) - (when (not (comint-check-proc proc-buffer-name)) - (let ((cmdlist (split-string-and-unquote cmd))) - (set-buffer - (apply 'make-comint proc-name (car cmdlist) nil - (cdr cmdlist))) - (inferior-python-mode)))))) + (python-shell-make-comint + (python-shell-parse-command) + (python-shell-internal-get-process-name))) (defun python-shell-get-process () "Get inferior Python process for current buffer and return it."