diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5a820f05d77..848a26229e6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3816,6 +3816,16 @@ variable. | |||
| 3816 | (compilation-shell-minor-mode 1) | 3816 | (compilation-shell-minor-mode 1) |
| 3817 | (python-pdbtrack-setup-tracking)) | 3817 | (python-pdbtrack-setup-tracking)) |
| 3818 | 3818 | ||
| 3819 | (defvar-local python-shell--process-cache) | ||
| 3820 | (defvar-local python-shell--process-cache-valid) | ||
| 3821 | |||
| 3822 | (defun python-shell--invalidate-process-cache () | ||
| 3823 | "Invalidate process cache." | ||
| 3824 | (dolist (buffer (buffer-list)) | ||
| 3825 | (with-current-buffer buffer | ||
| 3826 | (setq python-shell--process-cache nil | ||
| 3827 | python-shell--process-cache-valid nil)))) | ||
| 3828 | |||
| 3819 | (defun python-shell-make-comint (cmd proc-name &optional show internal) | 3829 | (defun python-shell-make-comint (cmd proc-name &optional show internal) |
| 3820 | "Create a Python shell comint buffer. | 3830 | "Create a Python shell comint buffer. |
| 3821 | CMD is the Python command to be executed and PROC-NAME is the | 3831 | CMD is the Python command to be executed and PROC-NAME is the |
| @@ -3832,6 +3842,7 @@ killed." | |||
| 3832 | (let* ((proc-buffer-name | 3842 | (let* ((proc-buffer-name |
| 3833 | (format (if (not internal) "*%s*" " *%s*") proc-name))) | 3843 | (format (if (not internal) "*%s*" " *%s*") proc-name))) |
| 3834 | (when (not (comint-check-proc proc-buffer-name)) | 3844 | (when (not (comint-check-proc proc-buffer-name)) |
| 3845 | (python-shell--invalidate-process-cache) | ||
| 3835 | (let* ((cmdlist (split-string-and-unquote cmd)) | 3846 | (let* ((cmdlist (split-string-and-unquote cmd)) |
| 3836 | (interpreter (car cmdlist)) | 3847 | (interpreter (car cmdlist)) |
| 3837 | (args (cdr cmdlist)) | 3848 | (args (cdr cmdlist)) |
| @@ -3955,7 +3966,15 @@ If current buffer is in `inferior-python-mode', return it." | |||
| 3955 | 3966 | ||
| 3956 | (defun python-shell-get-process () | 3967 | (defun python-shell-get-process () |
| 3957 | "Return inferior Python process for current buffer." | 3968 | "Return inferior Python process for current buffer." |
| 3958 | (get-buffer-process (python-shell-get-buffer))) | 3969 | (unless (and python-shell--process-cache-valid |
| 3970 | (or (not python-shell--process-cache) | ||
| 3971 | (and (process-live-p python-shell--process-cache) | ||
| 3972 | (buffer-live-p | ||
| 3973 | (process-buffer python-shell--process-cache))))) | ||
| 3974 | (setq python-shell--process-cache | ||
| 3975 | (get-buffer-process (python-shell-get-buffer)) | ||
| 3976 | python-shell--process-cache-valid t)) | ||
| 3977 | python-shell--process-cache) | ||
| 3959 | 3978 | ||
| 3960 | (defun python-shell-get-process-or-error (&optional interactivep) | 3979 | (defun python-shell-get-process-or-error (&optional interactivep) |
| 3961 | "Return inferior Python process for current buffer or signal error. | 3980 | "Return inferior Python process for current buffer or signal error. |