From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#25025: python-shell-calculate-command is wrong Date: Wed, 30 Nov 2016 17:10:34 -0500 Message-ID: References: <83polk3qow.fsf@gnu.org> <83inra13r3.fsf@gnu.org> <8337ic29y0.fsf@gnu.org> <87r35wj4b8.fsf@users.sourceforge.net> <83zikkzytf.fsf@gnu.org> <8737i9iz28.fsf@users.sourceforge.net> <1949fc46-fd26-dddb-86b2-ab3478587271@gmail.com> <87wpflhgsf.fsf@users.sourceforge.net> <83a8chq7x6.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1480543879 7211 195.159.176.226 (30 Nov 2016 22:11:19 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 30 Nov 2016 22:11:19 +0000 (UTC) Cc: 25025@debbugs.gnu.org, =?UTF-8?Q?Cl=C3=A9ment?= Pit--Claudel To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 30 23:11:15 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCD5u-00018M-DD for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Nov 2016 23:11:14 +0100 Original-Received: from localhost ([::1]:46876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCD5y-0005Fj-64 for geb-bug-gnu-emacs@m.gmane.org; Wed, 30 Nov 2016 17:11:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCD5n-0005CB-U4 for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 17:11:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCD5j-0005O5-3Q for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 17:11:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60656) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cCD5i-0005Ny-VG for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 17:11:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cCD5i-00028a-Cz for bug-gnu-emacs@gnu.org; Wed, 30 Nov 2016 17:11:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Nov 2016 22:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25025 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 25025-submit@debbugs.gnu.org id=B25025.14805438428187 (code B ref 25025); Wed, 30 Nov 2016 22:11:02 +0000 Original-Received: (at 25025) by debbugs.gnu.org; 30 Nov 2016 22:10:42 +0000 Original-Received: from localhost ([127.0.0.1]:47822 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCD5O-00027z-9Z for submit@debbugs.gnu.org; Wed, 30 Nov 2016 17:10:42 -0500 Original-Received: from mail-yw0-f174.google.com ([209.85.161.174]:33485) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cCD5M-00027j-D1 for 25025@debbugs.gnu.org; Wed, 30 Nov 2016 17:10:40 -0500 Original-Received: by mail-yw0-f174.google.com with SMTP id r204so169719066ywb.0 for <25025@debbugs.gnu.org>; Wed, 30 Nov 2016 14:10:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=ufeujWoZupv7n+9eM9AiRKIjQZ9bP8GhuoJS15fQh2I=; b=vt1QdD9fWwf8wiuUyNbTXH4gOT1CsVrAhwp2qZnmWxVop6Zc8Fz6VeicweTCDHkpbk HC5U5SkImf4IfU/Y9cxYj/to4W58D5Iusc1viohj74u7EH8dAMJ5V8ebtUa8eEaL8oV1 t3n5bC++kpHXmZbwksfSh5y34pPnJLGwU+Fu2SIV0ZyDQK2AMTEZs0p1QPgMKOBBuipj VS8RJ6AkLVwzCCw/YvS5onbzh8pSnedJH2n0Ryram+vEk6zmcq+/H8UCIIg516TXwtex RgspJPAuVyWeYIIv60f8XN8FEqcOpPwAOPRfMtlIrwsH1WEUmEcEOktGtNy/VKhD01E0 IhwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=ufeujWoZupv7n+9eM9AiRKIjQZ9bP8GhuoJS15fQh2I=; b=h5MjLrgVbvdItI5v6Moy9bUaCY0gUen8rdrrtbv6nQQrdBCcjRYWT/qhQJypVkYuVs 26/gPf0//MqQ+yCq8ku0s+9981lTmO33SGv6eLl9R8sy9/LfhQji5BTUQ7NlqHArZ7w3 BtRBNR5TvWmn3S+ZOgfWYfBoC9ltXlvgl1XABzN7BCoSfXKQxdAzO9KxIJB1RaZgfl+W G5fFWnI2+3ez+UiH8JoBYEZl6ny4PpEtCgDGS3nXUvJo4RMP/CY7vBcXj+X3AVCXXN7f afX7X1jpT6z5loomlDGurm2yKuCMThNjAVZqdZFRDxWnyzxnPcBFCXJL2NZ2584cN5oX xGWw== X-Gm-Message-State: AKaTC010oKRCtf+aMSM83T8SqtzeNSUzr2w/m5GITAEpWdwmKp+B5fAT38CQ+JgJDytN1J/IJAHeD4gvVofoYA== X-Received: by 10.157.54.245 with SMTP id s50mr19293813otd.181.1480543834892; Wed, 30 Nov 2016 14:10:34 -0800 (PST) Original-Received: by 10.157.6.234 with HTTP; Wed, 30 Nov 2016 14:10:34 -0800 (PST) In-Reply-To: <83a8chq7x6.fsf@gnu.org> X-Google-Sender-Auth: SGotm5EeR8whscHLrpocvRR87h8 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:126331 Archived-At: On Wed, Nov 30, 2016 at 10:55 AM, Eli Zaretskii wrote: >> From: npostavs@users.sourceforge.net >> Cc: Eli Zaretskii , 25025@debbugs.gnu.org >> Date: Tue, 29 Nov 2016 20:56:16 -0500 >> >> Cl=C3=A9ment Pit--Claudel writes: >> >> > On 2016-11-29 19:36, npostavs@users.sourceforge.net wrote: >> >> Eli Zaretskii writes: >> >> >> >>>> From: npostavs@users.sourceforge.net >> >>>> Cc: 25025@debbugs.gnu.org, clement.pit@gmail.com >> >>>> Date: Sun, 27 Nov 2016 11:06:03 -0500 >> >>>> >> >>>>> Why does it need to be split? A shell command can (even should) b= e >> >>>>> handed to the shell as a single string. >> >>>> >> >>>> Currently it's not a shell command, because a shell isn't being use= d. >> >>>> My other suggestion was to use a shell: >> >>>> >> >>>>>> It might be more intuitive to actually use a shell and then the u= ser >> >>>>>> would enter a shell command (though inserting a shell into things >> >>>>>> might bring more complications). >> >>> >> >>> If it doesn't use a shell, then it has no business quoting commands = or >> >>> their parts using shell-related APIs. >> >>> >> >>> So yes, I think using a shell would be TRT here. Can someone please >> >>> work on a patch in that direction? This problem exists for a long >> >>> time, so I hope we could solve it soon. >> >> >> >> Hmm, the difficulty in using a shell is that the current code wants t= o >> >> parse the command into interpreter and arguments in order to match >> >> against `python-shell-completion-native-disabled-interpreters'. >> > >> > That doesn't prevent us from using a shell. We run the command >> > unmodified through a shell, and we split it and analyze it separately >> > to decide whether to enable completion. But we don't split and >> > reassemble it before running it. >> >> Yes, but then we need to parse a shell quoted command, which is quite a >> bit more difficult. That gets back to your suggestion about getting an >> elisp equivalent to shlex I suppose. >> >> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D25025#28 > > Confused: how does python-shell-completion-native-disabled-interpreters > get into this picture? The function which uses it, > python-shell-completion-native-interpreter-disabled-p, looks at > python-shell-interpreter, which isn't affected by quoting or by how > the command is treated. What am I missing? This? (defun run-python (&optional cmd dedicated show) ... (python-shell-make-comint (or cmd (python-shell-calculate-command)) ... (defun python-shell-make-comint (cmd proc-name &optional show internal) ... (let* ((cmdlist (split-string-and-unquote cmd)) (interpreter (car cmdlist)) (args (cdr cmdlist)) (buffer (apply #'make-comint-in-buffer proc-name proc-buffer-name interpreter nil args)) ... ;; Users can override the interpreter and args ;; interactively when calling `run-python', let-binding ;; these allows having the new right values in all ;; setup code that is done in `inferior-python-mode', ;; which is important, especially for prompt detection. (python-shell--interpreter interpreter) (python-shell--interpreter-args (mapconcat #'identity args " "))) (with-current-buffer buffer (inferior-python-mode)) ... (define-derived-mode inferior-python-mode comint-mode "Inferior Python" ... ;; Users can interactively override default values for ;; `python-shell-interpreter' and `python-shell-interpreter-args' ;; when calling `run-python'. This ensures values let-bound in ;; `python-shell-make-comint' are locally set if needed. (set (make-local-variable 'python-shell-interpreter) (or python-shell--interpreter python-shell-interpreter)) (set (make-local-variable 'python-shell-interpreter-args) (or python-shell--interpreter-args python-shell-interpreter-args)) ...