aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorkobarity2026-01-11 17:49:29 +0900
committerEli Zaretskii2026-01-17 15:05:33 +0200
commitc97b8e6650fa28f44e36e200f966046ffe99fe0f (patch)
treeb2979240a3ffba0c741a9590cc65d04c83655d22 /lisp/progmodes/python.el
parent6e37af1fe89316fa921539340fcce9af94e9e69d (diff)
downloademacs-c97b8e6650fa28f44e36e200f966046ffe99fe0f.tar.gz
emacs-c97b8e6650fa28f44e36e200f966046ffe99fe0f.zip
Improve non-native completion in Python mode
Previously, both the definition of __PYTHON_EL_get_completions and the call to __PYTHON_EL_get_completions were sent to the inferior Python each time 'python-shell-completion-get-completions' was executed. However, there is no need to send the definition every time as long as the definition remains unchanged. We improved this so that the definition of __PYTHON_EL_get_completions is only sent during the inferior Python initialization; it is no longer sent during 'python-shell-completion-get-completions' execution. * lisp/progmodes/python.el (python-shell-completion-send-setup-code): New function. (python-shell-first-prompt-hook): Add the above new function. (python-shell-completion-get-completions): Omit sending 'python-shell-completion-setup-code'. (Bug#80182)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el10
1 files changed, 8 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 9c5e1e5ee6c..5a820f05d77 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4514,6 +4514,13 @@ def __PYTHON_EL_get_completions(text):
4514 "Code used to setup completion in inferior Python processes." 4514 "Code used to setup completion in inferior Python processes."
4515 :type 'string) 4515 :type 'string)
4516 4516
4517(defun python-shell-completion-send-setup-code ()
4518 "Send `python-shell-completion-setup-code' to inferior Python process."
4519 (python-shell-send-string-no-output python-shell-completion-setup-code))
4520
4521(add-hook 'python-shell-first-prompt-hook
4522 #'python-shell-completion-send-setup-code)
4523
4517(define-obsolete-variable-alias 4524(define-obsolete-variable-alias
4518 'python-shell-completion-module-string-code 4525 'python-shell-completion-module-string-code
4519 'python-shell-completion-string-code 4526 'python-shell-completion-string-code
@@ -4844,8 +4851,7 @@ With argument MSG show activation/deactivation message."
4844 (with-current-buffer (process-buffer process) 4851 (with-current-buffer (process-buffer process)
4845 (let ((completions 4852 (let ((completions
4846 (python-shell-send-string-no-output 4853 (python-shell-send-string-no-output
4847 (format "%s\nprint(__PYTHON_EL_get_completions(%s))" 4854 (format "print(__PYTHON_EL_get_completions(%s))"
4848 python-shell-completion-setup-code
4849 (python-shell--encode-string input)) 4855 (python-shell--encode-string input))
4850 process))) 4856 process)))
4851 (condition-case nil 4857 (condition-case nil