From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#45938: [PATCH] Avoid ANSI escape characters (bug#45938) Date: Thu, 29 Aug 2024 21:20:50 +0900 Message-ID: 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> <86a5gwgcko.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6382"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 45938@debbugs.gnu.org To: Eli Zaretskii , Evgenii Klimov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 29 14:22:29 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 1sjeAX-0001UJ-3S for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 29 Aug 2024 14:22:29 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjeAE-00023S-QU; Thu, 29 Aug 2024 08:22: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 1sjeAC-00023D-O9 for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 08:22:09 -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 1sjeAB-00005h-HI for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 08:22:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:From:Date:To:Subject; bh=8HngEg+2l60O14jctMX7/wpTbWbD18OyrDwIptoqgwc=; b=FxSdWoA5H/bR4agLpWAM0w5uO23ddav+viq8/CyKCcOgOQhZ9bOJHlb5b0nnY/PYqOxwp6Ga8JEhS5i9S9l6DAET2uUumNFN6/F6koJqk9cTf2/I9ZxvIOOfGJdvKK9REOI1ACan1p/vhSISdqweWwNTbNCqDT1eUJv0f7T3zTcCEHPGbUe1CvHNcURrhGmMsEjRBA+BpRt4HmyM2ivqu1jNPr0yXCWgTVp3p2qRgxDr2QsPIrBbl8RmZbxcyOLeFbyhSJb3RuWJXHgeXbOkQsC3tbpERb+vfPDhp4t7DX+N3thMTFKJnHaFORt0efrE6hIzdszFp+H5e4rYHzpZxA==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjeB4-0005gS-9P for bug-gnu-emacs@gnu.org; Thu, 29 Aug 2024 08:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Aug 2024 12:23: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.172493418121839 (code B ref 45938); Thu, 29 Aug 2024 12:23:02 +0000 Original-Received: (at 45938) by debbugs.gnu.org; 29 Aug 2024 12:23:01 +0000 Original-Received: from localhost ([127.0.0.1]:50702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjeB2-0005gB-OX for submit@debbugs.gnu.org; Thu, 29 Aug 2024 08:23:01 -0400 Original-Received: from mail-pf1-f176.google.com ([209.85.210.176]:55659) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjeAy-0005fv-Gf for 45938@debbugs.gnu.org; Thu, 29 Aug 2024 08:22:59 -0400 Original-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-71423704ef3so429476b3a.3 for <45938@debbugs.gnu.org>; Thu, 29 Aug 2024 05:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724934055; x=1725538855; darn=debbugs.gnu.org; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=8HngEg+2l60O14jctMX7/wpTbWbD18OyrDwIptoqgwc=; b=JuNgslteE8J4TaB36fVUyAmM8Yw4E4OWK3UB/DfdtwpbV+xil2RfYT0eZWUnYgqWO7 zIKP8nVfSQrr5n51ftisZSburJszEsI7d5oNd2rlxn7eqLK0T7/RyxMl/8hLSk0K05Xe hYkf0+EnB3N+8kIkx+I+V2WKckOB/vPhcbCsZoAhJ0Oyyd7ilkZ5dA43+WOGZy/rMHA2 jjFxIgxN81dRRg4xiAH/TcVgcQuBEe14fyQOHJTEuEPBhOnsHvskd/lfPvnejpaFhK4G b4nzf0d7E0FExClra9Bp5h44H9F8IUrcAkjJaAcj6E5h3biSzaYib5JRzn1Dg2ZTOn7P YnkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724934055; x=1725538855; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8HngEg+2l60O14jctMX7/wpTbWbD18OyrDwIptoqgwc=; b=OW+ZIwrUtGZ3S/LjUEz0MqVA3F1RAzVk3ygtDaZmkIgcj7EGbWsdk8IiFqPTvNh8kl Ht/OoKla+dz5DkVPWdfldqKlcwqg6Jh19x+kjnX5Ltdgj2TKDPxNbIoaSvjYNLPS5uHx Z+g7UR//Nlmhu4rQCnSyfrBrt3CHjy2yJio5NlmCvJ1WhU6HjXrm747BzSu+jipUCMhc 9iJ0igDgCM3gpKtZbwyhkJc6oTcNITVJ+bjpEYHI6YfFtJJMJokd6+XFVIBzL2BZoRm2 gLDBYmKBWfB40h41FDrSFKLvED0mNsNvXKcWGslXMFCMx5gIRc1Tt0sfwUuU6XGgDkw/ dULg== X-Gm-Message-State: AOJu0YzYde3GJ0VfF0x/9jdzl3s5F4WJJhe1s0/6OWS4lzMRKKe5IOVc xdX1ra0mrf8trzQDxXMGQGLwp5M80S5TVqZoRo9aaU2zsRUe6pZH X-Google-Smtp-Source: AGHT+IF3Afu7R7LPx8lc5yPdqAQquVtt108H1dTl0IFfmabhN4neFje6CQr7qbJ/MD0lyQwg+4B1OQ== X-Received: by 2002:a05:6a00:228c:b0:714:3a7e:31e0 with SMTP id d2e1a72fcca58-715dfc9005amr2848635b3a.29.1724934054888; Thu, 29 Aug 2024 05:20:54 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7d22e77a7besm1102355a12.37.2024.08.29.05.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 05:20:54 -0700 (PDT) In-Reply-To: <86a5gwgcko.fsf@gnu.org> 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:290932 Archived-At: Eli Zaretskii wrote: > > > 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. I confirmed that the patch resolves the issue. Also, Evgenii's survey seems sufficient. So I agree with this patch.