From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#45938: [PATCH] Avoid ANSI escape characters (bug#45938) Date: Thu, 29 Aug 2024 07:47:19 +0300 Message-ID: <86a5gwgcko.fsf@gnu.org> References: <87v9bvwn63.fsf@gmail.com> <87zfoxocyu.fsf@lipklim.org> <861q28j1rt.fsf@gnu.org> <877cc0a9xt.fsf@lipklim.org> <86jzg0h6ql.fsf@gnu.org> <87le0g8jr4.fsf@lipklim.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22350"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45938@debbugs.gnu.org, kobarity@gmail.com To: Evgenii Klimov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 29 06:48:16 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sjX4y-0005fa-Bl for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Aug 2024 06:48:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjX4r-00005s-VV; Thu, 29 Aug 2024 00:48:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjX4p-00005b-RK for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 00:48:08 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sjX4p-0000K1-HS for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 00:48:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=jIDsNhtIAQDA+gqTzkyYStuMS7RfXwM1jnVFr/7gDd8=; b=K4tHG3HXJfoqYG3oAYsLFSF5CxQDKinn1pQFM4krbx7o8Tn5Au0WCNdUR5HyVK0hDrhmLRIfXEE/T2yaDUag91eKIorjb84FmEruqfAO0mJSb770qQi7EWy56+lCCfdsFEQ0YYnr4d07E8tdBk3b7Ye6qDrB0Y3CvJPVnkEBCBYiG2/QbGGS2H1Kzzl1DuwdRETdmxlgH2xONvy7d3XDp9t/foq+V/IY31ca1tPWnpsooPGJrN2KBHuTNv+XZLiQsiEeXZIprkblF+8yG0GMvYHILS6ZTgphOaok8TZLG4qa9aKFsmbuBNzGmzbueN5mXFnXi4JWA2em+P7YxMx3/g==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjX5i-0000RF-C3 for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 00:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Aug 2024 04:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45938 X-GNU-PR-Package: emacs Original-Received: via spool by 45938-submit@debbugs.gnu.org id=B45938.17249069051623 (code B ref 45938); Thu, 29 Aug 2024 04:49:02 +0000 Original-Received: (at 45938) by debbugs.gnu.org; 29 Aug 2024 04:48:25 +0000 Original-Received: from localhost ([127.0.0.1]:50046 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjX57-0000Q7-1v for submit@debbugs.gnu.org; Thu, 29 Aug 2024 00:48:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:56898) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjX54-0000Pu-U9 for 45938@debbugs.gnu.org; Thu, 29 Aug 2024 00:48:23 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sjX46-0000GB-FY; Thu, 29 Aug 2024 00:47:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=jIDsNhtIAQDA+gqTzkyYStuMS7RfXwM1jnVFr/7gDd8=; b=EtaVPotZ8KHY 1UDtyBjnlhQAFEjWd4Og3lJZjL9WjacclHKO+jSa2+Ycv2i0//N78Ou3zOiNpF0YRRKxmPCDNYour qM1OlwYw3I2LkPSHSsSTvVEJIv4cTxOGA86Dmav1iCgGi3S/+eAXab5WW64xAlkVeRLR5IIFPNhng x/xMilxWXl4lUCIlaWVXtGZT0E9yaqJPDtsRktR4aEwyap0SS/LaJ7UNgt4+jz4d05oxVohXiR3ZF uAHrNSCOM5xLmY77ytS558TQpWKuyNme1vkAc44GW9MJPOfR+M6YB4asiIuTg+OejomwDc3R8+rcP /c60iW8zZI/5WLySYnFcGA==; In-Reply-To: <87le0g8jr4.fsf@lipklim.org> (message from Evgenii Klimov on Wed, 28 Aug 2024 21:39:27 +0100) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290898 Archived-At: > From: Evgenii Klimov > Cc: kobarity@gmail.com, 45938@debbugs.gnu.org > Date: Wed, 28 Aug 2024 21:39:27 +0100 > > Eli Zaretskii writes: > > >> From: Evgenii Klimov > >> Cc: kobarity , 45938@debbugs.gnu.org > >> Date: Wed, 28 Aug 2024 17:28:30 +0100 > >> > >> Eli Zaretskii writes: > >> [...] > >> >> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el > >> >> index a00289d6de9..7193cc19425 100644 > >> >> --- a/lisp/progmodes/python.el > >> >> +++ b/lisp/progmodes/python.el > >> >> @@ -4549,6 +4549,9 @@ (defun python-shell-completion-native-setup () > >> >> readline.parse_and_bind('tab: complete') > >> >> # Require just one tab to send output. > >> >> readline.parse_and_bind('set show-all-if-ambiguous on') > >> >> + # Avoid ANSI escape characters in the output > >> >> + readline.parse_and_bind('set colored-completion-prefix off') > >> >> + readline.parse_and_bind('set colored-stats off') > >> >> # Avoid replacing common prefix with ellipsis. > >> >> readline.parse_and_bind('set completion-prefix-display-length 0') > >> >> > >> > > >> > Are these commands available in every version of Python? > >> > >> These commands are from GNU Readline, not from Python > > > > Yes, I know. But not every Python is built with GNU Readline, right? > > If Python is not built with GNU Readline, then this function > (python-shell-completion-native-setup) will not set up native completion > in any case: > > ;; Shell completion: hitting tab will try to complete the current > ;; word. The two built-in mechanisms depend on Python's readline > ;; module [1] > > (defun python-shell-completion-native-setup () > "Try to setup native completion, return non-nil on success." > (let* ((process (python-shell-get-process)) > (output (python-shell-send-string-no-output " > def __PYTHON_EL_native_completion_setup(): > try: > import readline > ... > except: > import sys > print ('python.el: native completion setup failed, %s: %s' > % sys.exc_info()[:2]) > > [...] > > Which versions of Python or GNU/Linux are likely to have older > > versions of Readline? And what happens in an older Readline when > > these commands are sent? > > I tested what happens if we pass nonexistent variable - it prints to > stdout: > > In [15]: readline.parse_and_bind("set nonexistent-variable off") > readline: nonexistent-variable: unknown variable name > > In the context of `python-shell-completion-native-setup' such output > doesn't hurt, because output string still matches with expected one. > E.g. let's say that I added nonexistent-variable: > > (defun python-shell-completion-native-setup () > "Try to setup native completion, return non-nil on success." > (let* ((process (python-shell-get-process)) > (output (python-shell-send-string-no-output " > def __PYTHON_EL_native_completion_setup(): > ... > if readline.__doc__ and 'libedit' in readline.__doc__: > raise Exception('''libedit based readline is known not to work, > see etc/PROBLEMS under \"In Inferior Python mode, input is echoed\".''') > readline.parse_and_bind('bind ^I rl_complete') > else: > readline.parse_and_bind('tab: complete') > # Require just one tab to send output. > readline.parse_and_bind('set show-all-if-ambiguous on') > -> readline.parse_and_bind('set nonexistent-variable off') > # Avoid replacing common prefix with ellipsis. > readline.parse_and_bind('set completion-prefix-display-length 0') > > print ('python.el: native completion setup loaded') > except: > import sys > print ('python.el: native completion setup failed, %s: %s' > % sys.exc_info()[:2]) > > __PYTHON_EL_native_completion_setup()" process))) > (when (string-match-p "python\\.el: native completion setup loaded" > output) > (python-shell-completion-native-try)))) > > Then the `output' would be: > > "readline: nonexistent-variable: unknown variable name\npython.el: native completion setup loaded\n" > > and > > (string-match-p "python\\.el: native completion setup loaded" > output) > > finds the match. > > I tried that in CPython and IPython. > > Actually, I also tried python built with readline-6.2 > (`python-shell-completion-native-setup' already uses > "show-all-if-ambiguous", first appeared in that version) and found out > that that version doesn't even print anything when nonexistent variable > is passed. > > eugene@gx:~/git (gx) > $ guix shell --with-input=readline=readline@6.2 python > eugene@gx:~/git (gx) [env] > $ which python3 > /gnu/store/hhcay3d42k3k7avahrmlqv3qnjk2l6wp-profile/bin/python3 > eugene@gx:~/git (gx) [env] > $ echo $GUIX_ENVIRONMENT > /gnu/store/hhcay3d42k3k7avahrmlqv3qnjk2l6wp-profile > eugene@gx:~/git (gx) [env] > $ python3 > Python 3.10.7 (main, Jan 1 1970, 00:00:01) [GCC 11.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import readline > >>> readline.parse_and_bind("set nonexistent-variable off") > >>> Thanks, this all sounds good. Let's see what kobarity has to say about this.