aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el43
1 files changed, 38 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 93ef7fe9db6..fbe5b8b0743 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2605,6 +2605,40 @@ With argument MSG show activation/deactivation message."
2605 (python-shell-font-lock-turn-off msg)) 2605 (python-shell-font-lock-turn-off msg))
2606 python-shell-font-lock-enable)) 2606 python-shell-font-lock-enable))
2607 2607
2608(defvar python-shell--first-prompt-received-output-buffer nil)
2609(defvar python-shell--first-prompt-received nil)
2610
2611(defcustom python-shell-first-prompt-hook nil
2612 "Hook run upon first (non-pdb) shell prompt detection.
2613This is the place for shell setup functions that need to wait for
2614output. Since the first prompt is ensured, this helps the
2615current process to not hang waiting for output by safeguarding
2616interactive actions can be performed. This is useful to safely
2617attach setup code for long-running processes that eventually
2618provide a shell."
2619 :type 'hook
2620 :group 'python)
2621
2622(defun python-shell-comint-watch-for-first-prompt-output-filter (output)
2623 "Run `python-shell-first-prompt-hook' when first prompt is found in OUTPUT."
2624 (when (not python-shell--first-prompt-received)
2625 (set (make-local-variable 'python-shell--first-prompt-received-output-buffer)
2626 (concat python-shell--first-prompt-received-output-buffer
2627 (ansi-color-filter-apply output)))
2628 (when (python-shell-comint-end-of-output-p
2629 python-shell--first-prompt-received-output-buffer)
2630 (if (string-match-p
2631 (concat python-shell-prompt-pdb-regexp (rx eos))
2632 (or python-shell--first-prompt-received-output-buffer ""))
2633 ;; Skip pdb prompts and reset the buffer.
2634 (setq python-shell--first-prompt-received-output-buffer nil)
2635 (set (make-local-variable 'python-shell--first-prompt-received) t)
2636 (setq python-shell--first-prompt-received-output-buffer nil)
2637 (with-current-buffer (current-buffer)
2638 (let ((inhibit-quit nil))
2639 (run-hooks 'python-shell-first-prompt-hook))))))
2640 output)
2641
2608;; Used to hold user interactive overrides to 2642;; Used to hold user interactive overrides to
2609;; `python-shell-interpreter' and `python-shell-interpreter-args' that 2643;; `python-shell-interpreter' and `python-shell-interpreter-args' that
2610;; will be made buffer-local by `inferior-python-mode': 2644;; will be made buffer-local by `inferior-python-mode':
@@ -2654,6 +2688,7 @@ variable.
2654 (setq mode-line-process '(":%s")) 2688 (setq mode-line-process '(":%s"))
2655 (set (make-local-variable 'comint-output-filter-functions) 2689 (set (make-local-variable 'comint-output-filter-functions)
2656 '(ansi-color-process-output 2690 '(ansi-color-process-output
2691 python-shell-comint-watch-for-first-prompt-output-filter
2657 python-pdbtrack-comint-output-filter-function 2692 python-pdbtrack-comint-output-filter-function
2658 python-comint-postoutput-scroll-to-bottom)) 2693 python-comint-postoutput-scroll-to-bottom))
2659 (set (make-local-variable 'compilation-error-regexp-alist) 2694 (set (make-local-variable 'compilation-error-regexp-alist)
@@ -2667,9 +2702,7 @@ variable.
2667 (make-local-variable 'python-shell-internal-last-output) 2702 (make-local-variable 'python-shell-internal-last-output)
2668 (when python-shell-font-lock-enable 2703 (when python-shell-font-lock-enable
2669 (python-shell-font-lock-turn-on)) 2704 (python-shell-font-lock-turn-on))
2670 (compilation-shell-minor-mode 1) 2705 (compilation-shell-minor-mode 1))
2671 (python-shell-accept-process-output
2672 (get-buffer-process (current-buffer))))
2673 2706
2674(defun python-shell-make-comint (cmd proc-name &optional show internal) 2707(defun python-shell-make-comint (cmd proc-name &optional show internal)
2675 "Create a Python shell comint buffer. 2708 "Create a Python shell comint buffer.
@@ -3131,7 +3164,7 @@ This function takes the list of setup code to send from the
3131 (python-shell-send-string code process) 3164 (python-shell-send-string code process)
3132 (python-shell-accept-process-output process)))) 3165 (python-shell-accept-process-output process))))
3133 3166
3134(add-hook 'inferior-python-mode-hook 3167(add-hook 'python-shell-first-prompt-hook
3135 #'python-shell-send-setup-code) 3168 #'python-shell-send-setup-code)
3136 3169
3137 3170
@@ -3415,7 +3448,7 @@ With argument MSG show activation/deactivation message."
3415 "Like `python-shell-completion-native-turn-on-maybe' but force messages." 3448 "Like `python-shell-completion-native-turn-on-maybe' but force messages."
3416 (python-shell-completion-native-turn-on-maybe t)) 3449 (python-shell-completion-native-turn-on-maybe t))
3417 3450
3418(add-hook 'inferior-python-mode-hook 3451(add-hook 'python-shell-first-prompt-hook
3419 #'python-shell-completion-native-turn-on-maybe-with-msg) 3452 #'python-shell-completion-native-turn-on-maybe-with-msg)
3420 3453
3421(defun python-shell-completion-native-toggle (&optional msg) 3454(defun python-shell-completion-native-toggle (&optional msg)