diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 9c5e1e5ee6c..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. |
| @@ -4514,6 +4533,13 @@ def __PYTHON_EL_get_completions(text): | |||
| 4514 | "Code used to setup completion in inferior Python processes." | 4533 | "Code used to setup completion in inferior Python processes." |
| 4515 | :type 'string) | 4534 | :type 'string) |
| 4516 | 4535 | ||
| 4536 | (defun python-shell-completion-send-setup-code () | ||
| 4537 | "Send `python-shell-completion-setup-code' to inferior Python process." | ||
| 4538 | (python-shell-send-string-no-output python-shell-completion-setup-code)) | ||
| 4539 | |||
| 4540 | (add-hook 'python-shell-first-prompt-hook | ||
| 4541 | #'python-shell-completion-send-setup-code) | ||
| 4542 | |||
| 4517 | (define-obsolete-variable-alias | 4543 | (define-obsolete-variable-alias |
| 4518 | 'python-shell-completion-module-string-code | 4544 | 'python-shell-completion-module-string-code |
| 4519 | 'python-shell-completion-string-code | 4545 | 'python-shell-completion-string-code |
| @@ -4844,8 +4870,7 @@ With argument MSG show activation/deactivation message." | |||
| 4844 | (with-current-buffer (process-buffer process) | 4870 | (with-current-buffer (process-buffer process) |
| 4845 | (let ((completions | 4871 | (let ((completions |
| 4846 | (python-shell-send-string-no-output | 4872 | (python-shell-send-string-no-output |
| 4847 | (format "%s\nprint(__PYTHON_EL_get_completions(%s))" | 4873 | (format "print(__PYTHON_EL_get_completions(%s))" |
| 4848 | python-shell-completion-setup-code | ||
| 4849 | (python-shell--encode-string input)) | 4874 | (python-shell--encode-string input)) |
| 4850 | process))) | 4875 | process))) |
| 4851 | (condition-case nil | 4876 | (condition-case nil |