diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d39d7a3aa41..433dbc1dafd 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2397,7 +2397,6 @@ killed." | |||
| 2397 | (mapconcat #'identity args " "))) | 2397 | (mapconcat #'identity args " "))) |
| 2398 | (with-current-buffer buffer | 2398 | (with-current-buffer buffer |
| 2399 | (inferior-python-mode)) | 2399 | (inferior-python-mode)) |
| 2400 | (accept-process-output process) | ||
| 2401 | (and pop (pop-to-buffer buffer t)) | 2400 | (and pop (pop-to-buffer buffer t)) |
| 2402 | (and internal (set-process-query-on-exit-flag process nil)))) | 2401 | (and internal (set-process-query-on-exit-flag process nil)))) |
| 2403 | proc-buffer-name))) | 2402 | proc-buffer-name))) |
| @@ -2451,16 +2450,19 @@ startup." | |||
| 2451 | (python-shell-internal-get-process-name) nil t)))) | 2450 | (python-shell-internal-get-process-name) nil t)))) |
| 2452 | 2451 | ||
| 2453 | (defun python-shell-get-buffer () | 2452 | (defun python-shell-get-buffer () |
| 2454 | "Return inferior Python buffer for current buffer." | 2453 | "Return inferior Python buffer for current buffer. |
| 2455 | (let* ((dedicated-proc-name (python-shell-get-process-name t)) | 2454 | If current buffer is in `inferior-python-mode', return it." |
| 2456 | (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name)) | 2455 | (if (eq major-mode 'inferior-python-mode) |
| 2457 | (global-proc-name (python-shell-get-process-name nil)) | 2456 | (current-buffer) |
| 2458 | (global-proc-buffer-name (format "*%s*" global-proc-name)) | 2457 | (let* ((dedicated-proc-name (python-shell-get-process-name t)) |
| 2459 | (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) | 2458 | (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name)) |
| 2460 | (global-running (comint-check-proc global-proc-buffer-name))) | 2459 | (global-proc-name (python-shell-get-process-name nil)) |
| 2461 | ;; Always prefer dedicated | 2460 | (global-proc-buffer-name (format "*%s*" global-proc-name)) |
| 2462 | (or (and dedicated-running dedicated-proc-buffer-name) | 2461 | (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) |
| 2463 | (and global-running global-proc-buffer-name)))) | 2462 | (global-running (comint-check-proc global-proc-buffer-name))) |
| 2463 | ;; Always prefer dedicated | ||
| 2464 | (or (and dedicated-running dedicated-proc-buffer-name) | ||
| 2465 | (and global-running global-proc-buffer-name))))) | ||
| 2464 | 2466 | ||
| 2465 | (defun python-shell-get-process () | 2467 | (defun python-shell-get-process () |
| 2466 | "Return inferior Python process for current buffer." | 2468 | "Return inferior Python process for current buffer." |
| @@ -2472,24 +2474,14 @@ Arguments CMD, DEDICATED and SHOW are those of `run-python' and | |||
| 2472 | are used to start the shell. If those arguments are not | 2474 | are used to start the shell. If those arguments are not |
| 2473 | provided, `run-python' is called interactively and the user will | 2475 | provided, `run-python' is called interactively and the user will |
| 2474 | be asked for their values." | 2476 | be asked for their values." |
| 2475 | (let* ((dedicated-proc-name (python-shell-get-process-name t)) | 2477 | (let ((shell-process (python-shell-get-process))) |
| 2476 | (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name)) | 2478 | (when (not shell-process) |
| 2477 | (global-proc-name (python-shell-get-process-name nil)) | 2479 | (if (not cmd) |
| 2478 | (global-proc-buffer-name (format "*%s*" global-proc-name)) | 2480 | ;; XXX: Refactor code such that calling `run-python' |
| 2479 | (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) | 2481 | ;; interactively is not needed anymore. |
| 2480 | (global-running (comint-check-proc global-proc-buffer-name))) | 2482 | (call-interactively 'run-python) |
| 2481 | (when (and (not dedicated-running) (not global-running)) | 2483 | (run-python cmd dedicated show))) |
| 2482 | (if (if (not cmd) | 2484 | (or shell-process (python-shell-get-process)))) |
| 2483 | ;; XXX: Refactor code such that calling `run-python' | ||
| 2484 | ;; interactively is not needed anymore. | ||
| 2485 | (call-interactively 'run-python) | ||
| 2486 | (run-python cmd dedicated show)) | ||
| 2487 | (setq dedicated-running t) | ||
| 2488 | (setq global-running t))) | ||
| 2489 | ;; Always prefer dedicated | ||
| 2490 | (get-buffer-process (if dedicated-running | ||
| 2491 | dedicated-proc-buffer-name | ||
| 2492 | global-proc-buffer-name)))) | ||
| 2493 | 2485 | ||
| 2494 | (defvar python-shell-internal-buffer nil | 2486 | (defvar python-shell-internal-buffer nil |
| 2495 | "Current internal shell buffer for the current buffer. | 2487 | "Current internal shell buffer for the current buffer. |
| @@ -2769,12 +2761,18 @@ If DELETE is non-nil, delete the file afterwards." | |||
| 2769 | "Send all setup code for shell. | 2761 | "Send all setup code for shell. |
| 2770 | This function takes the list of setup code to send from the | 2762 | This function takes the list of setup code to send from the |
| 2771 | `python-shell-setup-codes' list." | 2763 | `python-shell-setup-codes' list." |
| 2772 | (let ((process (get-buffer-process (current-buffer)))) | 2764 | (let ((process (python-shell-get-process)) |
| 2773 | (dolist (code python-shell-setup-codes) | 2765 | (code (concat |
| 2774 | (when code | 2766 | (mapconcat |
| 2775 | (message "Sent %s" code) | 2767 | (lambda (elt) |
| 2776 | (python-shell-send-string | 2768 | (cond ((stringp elt) elt) |
| 2777 | (symbol-value code) process))))) | 2769 | ((symbolp elt) (symbol-value elt)) |
| 2770 | (t ""))) | ||
| 2771 | python-shell-setup-codes | ||
| 2772 | "\n\n") | ||
| 2773 | "\n\nprint ('python.el: sent setup code')"))) | ||
| 2774 | (python-shell-send-string code) | ||
| 2775 | (accept-process-output process))) | ||
| 2778 | 2776 | ||
| 2779 | (add-hook 'inferior-python-mode-hook | 2777 | (add-hook 'inferior-python-mode-hook |
| 2780 | #'python-shell-send-setup-code) | 2778 | #'python-shell-send-setup-code) |