aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorkobarity2026-03-06 16:27:44 +0900
committerEli Zaretskii2026-03-07 13:32:11 +0200
commitb9b59447a154ba6796b18cfb3821cb748b5dfdfb (patch)
tree248dd4355676edf7c9600b99c324d8c8ec1174e4 /lisp/progmodes/python.el
parentcb583c737ccbb5ebf853b106e82d76cda30010dd (diff)
downloademacs-b9b59447a154ba6796b18cfb3821cb748b5dfdfb.tar.gz
emacs-b9b59447a154ba6796b18cfb3821cb748b5dfdfb.zip
Improve Python setup codes to avoid leaving global names
* lisp/progmodes/python.el (python-shell-setup-code) (python-shell-readline-detect): Improve Python code. (Bug#80551)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el34
1 files changed, 21 insertions, 13 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 0b4a773516a..ad0e84bf74f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3652,14 +3652,18 @@ eventually provide a shell."
3652 3652
3653(defconst python-shell-setup-code 3653(defconst python-shell-setup-code
3654 "\ 3654 "\
3655try: 3655def _PYTHON_EL_setup():
3656 import termios 3656 try:
3657except ImportError: 3657 import termios
3658 pass 3658 except ImportError:
3659else: 3659 pass
3660 attr = termios.tcgetattr(0) 3660 else:
3661 attr[3] &= ~termios.ECHO 3661 attr = termios.tcgetattr(0)
3662 termios.tcsetattr(0, termios.TCSADRAIN, attr)" 3662 attr[3] &= ~termios.ECHO
3663 termios.tcsetattr(0, termios.TCSADRAIN, attr)
3664
3665_PYTHON_EL_setup()
3666del _PYTHON_EL_setup"
3663 "Code used to setup the inferior Python processes.") 3667 "Code used to setup the inferior Python processes.")
3664 3668
3665(defconst python-shell-eval-setup-code 3669(defconst python-shell-eval-setup-code
@@ -4639,11 +4643,15 @@ shell has no readline support.")
4639 "Detect the readline support for Python shell completion." 4643 "Detect the readline support for Python shell completion."
4640 (let* ((process (python-shell-get-process)) 4644 (let* ((process (python-shell-get-process))
4641 (output (python-shell-send-string-no-output " 4645 (output (python-shell-send-string-no-output "
4642try: 4646def _PYTHON_EL_detect_readline():
4643 import readline 4647 try:
4644 print(readline.get_completer_delims()) 4648 import readline
4645except: 4649 print(readline.get_completer_delims())
4646 print('No readline support')" process))) 4650 except:
4651 print('No readline support')
4652
4653_PYTHON_EL_detect_readline()
4654del _PYTHON_EL_detect_readline" process)))
4647 (setq-local python-shell-readline-completer-delims 4655 (setq-local python-shell-readline-completer-delims
4648 (unless (string-search "No readline support" output) 4656 (unless (string-search "No readline support" output)
4649 (string-trim-right output))))) 4657 (string-trim-right output)))))