From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Evgenii Klimov via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#45938: [PATCH] Avoid ANSI escape characters (bug#45938) Date: Wed, 28 Aug 2024 21:39:27 +0100 Message-ID: <87le0g8jr4.fsf@lipklim.org> References: <87v9bvwn63.fsf@gmail.com> <87zfoxocyu.fsf@lipklim.org> <861q28j1rt.fsf@gnu.org> <877cc0a9xt.fsf@lipklim.org> <86jzg0h6ql.fsf@gnu.org> Reply-To: Evgenii Klimov Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15805"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 45938@debbugs.gnu.org, kobarity@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 28 22:40:24 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 1sjPSp-0003uq-Tq for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 28 Aug 2024 22:40:24 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sjPSd-0001fS-QC; Wed, 28 Aug 2024 16:40:12 -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 1sjPSb-0001fK-ED for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 16:40: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 1sjPSb-0007TA-4Z for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 16:40:09 -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:Date:References:In-Reply-To:From:To:Subject; bh=jAALx0SlDNm8olzbVQZstbCQFxxs2eq8lB9ssO63MN8=; b=O/T38XlHs6L54GEV1GDJe0M44Qh4XE0eHaJZRz76ynsr2Y6SoTNCvaIs8EbqKspQmwW1R90xTDioIsK+dYRlzraQy15QXsPrpdfzOsxkLcQdc+Gg0wygAWPvizlIOCxdwhzYEl3+2DkVSmCoF5bpOp4q+suuQKQOcj15jLvemw9V3oIMNFbXlKiUohQ8WSeAG38Kz4DQCQR0zt6xABCRqkuyj6TiC4VxNbWZjHNpKnkxIjg2HbQptdmF0GHZ9Hj7o0GKajsKc+bF/qdGAhnhZFv+Q7MS+Be61XDiDnhGH+rRiQy9CvQctntXRIpgeZwFQejvWp5PsOyxIJANsZhzRw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sjPTS-0003IX-IV for bug-gnu-emacs@gnu.org; Wed, 28 Aug 2024 16:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Evgenii Klimov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Aug 2024 20:41: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.172487763512618 (code B ref 45938); Wed, 28 Aug 2024 20:41:02 +0000 Original-Received: (at 45938) by debbugs.gnu.org; 28 Aug 2024 20:40:35 +0000 Original-Received: from localhost ([127.0.0.1]:49782 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjPT0-0003HS-PB for submit@debbugs.gnu.org; Wed, 28 Aug 2024 16:40:35 -0400 Original-Received: from out-170.mta0.migadu.com ([91.218.175.170]:14524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sjPSx-0003HB-62 for 45938@debbugs.gnu.org; Wed, 28 Aug 2024 16:40:33 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lipklim.org; s=key1; t=1724877570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jAALx0SlDNm8olzbVQZstbCQFxxs2eq8lB9ssO63MN8=; b=gNiDDfbzLFIIixZxXRvo56YDKF3Cp7zBdxOp4JhpBp+4O64/39JlcrFZPmfYorZA3btooQ ggNhURhW+DQvrNKS7bmvK1AnKYfA7CM66OLhNsgde474CJJiseI43PX4limq2ioOv3F4al VrrV8MALwBzURTpWnMXpigUYZg+I5Vo= In-Reply-To: <86jzg0h6ql.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 28 Aug 2024 20:55:46 +0300") X-Migadu-Flow: FLOW_OUT 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:290883 Archived-At: 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") >>> [1] https://git.sv.gnu.org/cgit/emacs.git/tree/lisp/progmodes/python.el?h=master#n119