]> code.delx.au - gnu-emacs/commitdiff
Refactored run-python and run-python-internal.
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:22 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:22 +0000 (00:03 -0300)
Created new function python-shell-make-comint that takes care of
creating comint processes.

New Function:
    * python-shell-make-comint

lisp/progmodes/python.el

index 03524812a2de60642b8b58a1ed53bd67ddc79824..3f53d25e0d3a8da74b8dc23f8ba3f095b49150d3 100644 (file)
@@ -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."