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#68559: [PATCH] Improve Python shell completion Date: Sat, 17 Feb 2024 22:33:56 +0900 Message-ID: References: <6BAFD8BF-8F18-4D9F-9DB3-A185AEF2EBCA@gmail.com> <8B4172D0-FC31-4437-99C4-683C892C5F86@gmail.com> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15156"; 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: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , Eli Zaretskii , 68559@debbugs.gnu.org To: Liu Hui Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 17 14:36:01 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 1rbKrJ-0003oF-3V for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 17 Feb 2024 14:36:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rbKr2-0006qm-3j; Sat, 17 Feb 2024 08:35:44 -0500 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 1rbKr0-0006qO-Qy for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 08:35:42 -0500 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 1rbKr0-0001Kc-Ig for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 08:35:42 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rbKrK-00009m-DK for bug-gnu-emacs@gnu.org; Sat, 17 Feb 2024 08:36:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 17 Feb 2024 13:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68559 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 68559-submit@debbugs.gnu.org id=B68559.1708176923550 (code B ref 68559); Sat, 17 Feb 2024 13:36:02 +0000 Original-Received: (at 68559) by debbugs.gnu.org; 17 Feb 2024 13:35:23 +0000 Original-Received: from localhost ([127.0.0.1]:60553 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rbKqh-00008o-1o for submit@debbugs.gnu.org; Sat, 17 Feb 2024 08:35:23 -0500 Original-Received: from mail-pl1-f176.google.com ([209.85.214.176]:53409) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rbKqf-00008V-9U for 68559@debbugs.gnu.org; Sat, 17 Feb 2024 08:35:22 -0500 Original-Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d95d67ff45so24318155ad.2 for <68559@debbugs.gnu.org>; Sat, 17 Feb 2024 05:35:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708176835; x=1708781635; darn=debbugs.gnu.org; h=content-transfer-encoding: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=lBTzuuPVYNFjAlshBQBzfE3bpSCOuZI1QW5JrNd6KHA=; b=clAUs5Ev0lZoI4glJH5UqVNKkx3Y4PJDaaWo8dHl/5MM7zQUH85pRVaN/POzIi+5H2 j8HsUMfdyp0tU6nhs3/8BmJ77JUyKLXsYGWXazTeYoZ1pJe8bpJlGlOopRBY89XNUIDq ZqEJczENoje4khzHNMWkhLC3ED3FzZ/bAwt5BEXwaFl0Gdh9ZkS4dTfgu3z0vvHcpJZt cZI6kI+yyU72pTAy1bMITsfeqlEQuhdGUhkVg5zk7KdT9QX4CSkEhtQ5c5XRvdVThmv+ 1fiAWU3eyI+yq+gVFSgMRwfQqujsVtEDEixYk0uJV3+SVxh2o5BHzdR7Q3QvOIv3eHPG vkwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708176835; x=1708781635; h=content-transfer-encoding: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=lBTzuuPVYNFjAlshBQBzfE3bpSCOuZI1QW5JrNd6KHA=; b=UG1o3USDSvMMb0lOF7sp19jQVm/UBaaBDWB02mW0otNNWBvz1xKhylA1pxe0gXVuXE VeRAsWe+O1rEpa6kmQgO89QXj86oDDQdjMOzLBHGhISqb1nGMTeZdvTDiOv2JxV1KSyj 0IhVZkw6uL0lEwQuspytChG6rjbwlIzYydUwXDSyodb2nR8He6nvCa0LGMMJYuaJwpaA jBP/DfaPJ1+y2ktb6oECLAqADoklyOF6whJ5srThG/Qhd1fnh0KgBi5P5Oacltx0cHsE EOj1rqBcuDI6w//9MPHhijd1D0pHB6o+/f8MRi6XmgNbSzk1wDvDxx//ifZ5QUjW2bwl jZsQ== X-Forwarded-Encrypted: i=1; AJvYcCUqiIx4fg1uDXf+wdQgZUNDTLdHvzgl3fF7307s69D9MZaSxfAXQLUa+qKw26gFKMs6sC4qEW6C35R+B6XI0G1ABRbfXO0= X-Gm-Message-State: AOJu0YzCRBROxTUvFHHVwa3Aanmo4N2q/38rqRdrHH/LpGaVdHukN+Ar CDv3h54KL7yA/u3Yg9T3YZPjOaHDrJjCnty3fZzXifyr4DzX6Kd1 X-Google-Smtp-Source: AGHT+IF3Xs0g03ORK8hKTQxVF1M6P5Td2dBBrFVZ9fHeGYTGTfLwJAlzfYD6JTxvnMg3KGvfnZ4+/A== X-Received: by 2002:a17:903:32c7:b0:1db:8c27:c24d with SMTP id i7-20020a17090332c700b001db8c27c24dmr8539327plr.50.1708176834846; Sat, 17 Feb 2024 05:33:54 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id kf14-20020a17090305ce00b001db66f3748fsm1449448plb.182.2024.02.17.05.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 05:33:54 -0800 (PST) In-Reply-To: <86jzn4v23f.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:280127 Archived-At: Eli Zaretskii wrote: > > 0001-Remove-echoed-back-string-in-python-shell-completion.patch > > extracts only the last line to exclude echoed back strings. > >=20 > > 0001-Set-tty-mode-to-raw-when-setting-up-Inferior-Python.patch sets > > the Inferior Python tty to raw mode. python-ffap-module-path-1 will > > no longer need to be skipped on Mac. If it is safe to set tty to raw > > mode on all UNIX based systems, I prefer this method. >=20 > Will this work on MS-Windows as well? If you are unsure, would you > please tell me how to test whether this works on Windows, so I could > collect the information for you? It does not affect MS-Windows because it sets only when the tty library can be imported. Although the tty library exists in MS-Windows, importing the tty library will result in an error because there is no underlying termios library. Mattias Engdeg=C3=A5rd wrote: >=20 > 16 feb. 2024 kl. 16.24 skrev kobarity : >=20 > > I made prototype patches for each method. I don't use Mac so it would > > be helpful if you could try these. >=20 > Nice, thank you! I can confirm that they both appear to work, at least in= the sense that the python-tests pass (except for the ones skipped intentio= nally), and the python shell behaves reasonable. >=20 > Only the set-tty-mode patch eliminates echo in the interactive python she= ll; in that sense it's preferable. Thank you for testing my patches. > Both produce the very annoying warning >=20 > Warning (python): Your =E2=80=98python-shell-interpreter=E2=80=99 doesn= =E2=80=99t seem to support readline, yet =E2=80=98python-shell-completion-n= ative-enable=E2=80=99 was t and "python3" is not part of the =E2=80=98pytho= n-shell-completion-native-disabled-interpreters=E2=80=99 list. Native comp= letions have been disabled locally. Consider installing the python package = "readline". >=20 > which is not even correct since the standard Python does have a working r= eadline module, even if it uses libedit. You are right. Maybe the package name should be fixed to "gnureadline" as described in etc/PROBLEMS. On Mac, it might be better to set the default value of `python-shell-completion-native-enable' to nil. > > 0001-Set-tty-mode-to-raw-when-setting-up-Inferior-Python.patch sets > > the Inferior Python tty to raw mode. python-ffap-module-path-1 will > > no longer need to be skipped on Mac. >=20 > Right, that test runs and passes. >=20 > > If it is safe to set tty to raw > > mode on all UNIX based systems, I prefer this method. >=20 > Same here. I see no reason why it wouldn't be safe, either. Thanks. > > By the way, is it necessary to send > > `python-shell-completion-setup-code' for every completion in > > `python-shell-completion-get-completions'? To me it seems sufficient > > to send it once at initialization. >=20 > Indeed, it does seem a bit extravagant. This would be one of the items for future improvement. Liu Hui wrote: >=20 > kobarity writes: >=20 > > 0001-Set-tty-mode-to-raw-when-setting-up-Inferior-Python.patch sets > > the Inferior Python tty to raw mode. python-ffap-module-path-1 will > > no longer need to be skipped on Mac. If it is safe to set tty to raw > > mode on all UNIX based systems, I prefer this method. >=20 > How about the following change, which only affects libedit-based > readline? It may enable native completion on mac, but I cannot test > it. >=20 > diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el > index b7e43f3fc68..f59bc19367b 100644 > --- a/lisp/progmodes/python.el > +++ b/lisp/progmodes/python.el > @@ -4286,6 +4286,9 @@ (defcustom python-shell-completion-setup-code > except: > pass > else: > + if readline.__doc__ and 'libedit' in readline.__doc__: > + import tty > + tty.setraw(0) > # Try to reuse current completer. > completer =3D readline.get_completer() > if not completer: > @@ -4471,8 +4474,8 @@ (defun python-shell-completion-native-setup () > instance.rlcomplete =3D new_completer >=20 > if readline.__doc__ and 'libedit' in readline.__doc__: > - raise Exception('''libedit based readline is known not to wo= rk, > - see etc/PROBLEMS under \"In Inferior Python mode, input is echoed\= ".''') > + import tty > + tty.setraw(0) > readline.parse_and_bind('bind ^I rl_complete') > else: > readline.parse_and_bind('tab: complete') Disabling echo back may not be sufficient to enable native completions on Mac. I have not tried raw mode, but have tried readline.parse_and_bind('setty -echo') and readline.parse_and_bind('edit on'). Native completions could be enabled, but it was unstable. I have no objection if Mac users check the above patch and if it is OK.