diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index b6981c9156c..2a3035c95c5 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3366,6 +3366,16 @@ from `python-shell-prompt-regexp', | |||
| 3366 | python-shell--prompt-calculated-output-regexp | 3366 | python-shell--prompt-calculated-output-regexp |
| 3367 | (funcall build-regexp output-prompts))))) | 3367 | (funcall build-regexp output-prompts))))) |
| 3368 | 3368 | ||
| 3369 | (defun python-shell-get-project-name () | ||
| 3370 | "Return the project name for the current buffer. | ||
| 3371 | Use `project-name-cached' if available." | ||
| 3372 | (when (featurep 'project) | ||
| 3373 | (if (fboundp 'project-name-cached) | ||
| 3374 | (project-name-cached default-directory) | ||
| 3375 | (when-let* ((proj (project-current))) | ||
| 3376 | (file-name-nondirectory | ||
| 3377 | (directory-file-name (project-root proj))))))) | ||
| 3378 | |||
| 3369 | (defun python-shell-get-process-name (dedicated) | 3379 | (defun python-shell-get-process-name (dedicated) |
| 3370 | "Calculate the appropriate process name for inferior Python process. | 3380 | "Calculate the appropriate process name for inferior Python process. |
| 3371 | If DEDICATED is nil, this is simply `python-shell-buffer-name'. | 3381 | If DEDICATED is nil, this is simply `python-shell-buffer-name'. |
| @@ -3374,11 +3384,8 @@ name respectively the current project name." | |||
| 3374 | (pcase dedicated | 3384 | (pcase dedicated |
| 3375 | ('nil python-shell-buffer-name) | 3385 | ('nil python-shell-buffer-name) |
| 3376 | ('project | 3386 | ('project |
| 3377 | (if-let* ((proj (and (featurep 'project) | 3387 | (if-let* ((proj-name (python-shell-get-project-name))) |
| 3378 | (project-current)))) | 3388 | (format "%s[%s]" python-shell-buffer-name proj-name) |
| 3379 | (format "%s[%s]" python-shell-buffer-name (file-name-nondirectory | ||
| 3380 | (directory-file-name | ||
| 3381 | (project-root proj)))) | ||
| 3382 | python-shell-buffer-name)) | 3389 | python-shell-buffer-name)) |
| 3383 | (_ (format "%s[%s]" python-shell-buffer-name (buffer-name))))) | 3390 | (_ (format "%s[%s]" python-shell-buffer-name (buffer-name))))) |
| 3384 | 3391 | ||
| @@ -3816,16 +3823,6 @@ variable. | |||
| 3816 | (compilation-shell-minor-mode 1) | 3823 | (compilation-shell-minor-mode 1) |
| 3817 | (python-pdbtrack-setup-tracking)) | 3824 | (python-pdbtrack-setup-tracking)) |
| 3818 | 3825 | ||
| 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 | |||
| 3829 | (defun python-shell-make-comint (cmd proc-name &optional show internal) | 3826 | (defun python-shell-make-comint (cmd proc-name &optional show internal) |
| 3830 | "Create a Python shell comint buffer. | 3827 | "Create a Python shell comint buffer. |
| 3831 | CMD is the Python command to be executed and PROC-NAME is the | 3828 | CMD is the Python command to be executed and PROC-NAME is the |
| @@ -3842,7 +3839,6 @@ killed." | |||
| 3842 | (let* ((proc-buffer-name | 3839 | (let* ((proc-buffer-name |
| 3843 | (format (if (not internal) "*%s*" " *%s*") proc-name))) | 3840 | (format (if (not internal) "*%s*" " *%s*") proc-name))) |
| 3844 | (when (not (comint-check-proc proc-buffer-name)) | 3841 | (when (not (comint-check-proc proc-buffer-name)) |
| 3845 | (python-shell--invalidate-process-cache) | ||
| 3846 | (let* ((cmdlist (split-string-and-unquote cmd)) | 3842 | (let* ((cmdlist (split-string-and-unquote cmd)) |
| 3847 | (interpreter (car cmdlist)) | 3843 | (interpreter (car cmdlist)) |
| 3848 | (args (cdr cmdlist)) | 3844 | (args (cdr cmdlist)) |
| @@ -3966,15 +3962,7 @@ If current buffer is in `inferior-python-mode', return it." | |||
| 3966 | 3962 | ||
| 3967 | (defun python-shell-get-process () | 3963 | (defun python-shell-get-process () |
| 3968 | "Return inferior Python process for current buffer." | 3964 | "Return inferior Python process for current buffer." |
| 3969 | (unless (and python-shell--process-cache-valid | 3965 | (get-buffer-process (python-shell-get-buffer))) |
| 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) | ||
| 3978 | 3966 | ||
| 3979 | (defun python-shell-get-process-or-error (&optional interactivep) | 3967 | (defun python-shell-get-process-or-error (&optional interactivep) |
| 3980 | "Return inferior Python process for current buffer or signal error. | 3968 | "Return inferior Python process for current buffer or signal error. |
| @@ -5854,7 +5842,7 @@ Set to nil by `python-eldoc-function' if | |||
| 5854 | 5842 | ||
| 5855 | (defcustom python-eldoc-function-timeout 1 | 5843 | (defcustom python-eldoc-function-timeout 1 |
| 5856 | "Timeout for `python-eldoc-function' in seconds." | 5844 | "Timeout for `python-eldoc-function' in seconds." |
| 5857 | :type 'integer | 5845 | :type 'number |
| 5858 | :version "25.1") | 5846 | :version "25.1") |
| 5859 | 5847 | ||
| 5860 | (defcustom python-eldoc-function-timeout-permanent t | 5848 | (defcustom python-eldoc-function-timeout-permanent t |