1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-10 08:52:40 -07:00

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)
This commit is contained in:
kobarity 2026-03-06 16:27:44 +09:00 committed by Eli Zaretskii
parent cb583c737c
commit b9b59447a1

View file

@ -3652,14 +3652,18 @@ eventually provide a shell."
(defconst python-shell-setup-code
"\
try:
import termios
except ImportError:
pass
else:
attr = termios.tcgetattr(0)
attr[3] &= ~termios.ECHO
termios.tcsetattr(0, termios.TCSADRAIN, attr)"
def _PYTHON_EL_setup():
try:
import termios
except ImportError:
pass
else:
attr = termios.tcgetattr(0)
attr[3] &= ~termios.ECHO
termios.tcsetattr(0, termios.TCSADRAIN, attr)
_PYTHON_EL_setup()
del _PYTHON_EL_setup"
"Code used to setup the inferior Python processes.")
(defconst python-shell-eval-setup-code
@ -4639,11 +4643,15 @@ shell has no readline support.")
"Detect the readline support for Python shell completion."
(let* ((process (python-shell-get-process))
(output (python-shell-send-string-no-output "
try:
import readline
print(readline.get_completer_delims())
except:
print('No readline support')" process)))
def _PYTHON_EL_detect_readline():
try:
import readline
print(readline.get_completer_delims())
except:
print('No readline support')
_PYTHON_EL_detect_readline()
del _PYTHON_EL_detect_readline" process)))
(setq-local python-shell-readline-completer-delims
(unless (string-search "No readline support" output)
(string-trim-right output)))))