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#58389: 29.0.50; Python completion fails under certain conditions Date: Sun, 09 Oct 2022 15:58:11 +0900 Message-ID: Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sun_Oct__9_15:58:10_2022-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36554"; 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/29.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) To: 58389@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 09 08:59:13 2022 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 1ohQHI-0009OR-UH for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Oct 2022 08:59:13 +0200 Original-Received: from localhost ([::1]:51860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohQHH-0001aP-TA for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Oct 2022 02:59:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohQH9-0001a3-0L for bug-gnu-emacs@gnu.org; Sun, 09 Oct 2022 02:59:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohQH8-0007pZ-LZ for bug-gnu-emacs@gnu.org; Sun, 09 Oct 2022 02:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ohQH8-0000ma-AG for bug-gnu-emacs@gnu.org; Sun, 09 Oct 2022 02:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Oct 2022 06:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58389 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16652987272985 (code B ref -1); Sun, 09 Oct 2022 06:59:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Oct 2022 06:58:47 +0000 Original-Received: from localhost ([127.0.0.1]:41844 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohQGs-0000m5-Qt for submit@debbugs.gnu.org; Sun, 09 Oct 2022 02:58:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56046) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ohQGr-0000lw-0o for submit@debbugs.gnu.org; Sun, 09 Oct 2022 02:58:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohQGq-0001YY-OR for bug-gnu-emacs@gnu.org; Sun, 09 Oct 2022 02:58:44 -0400 Original-Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:37707) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohQGn-0007nq-NP for bug-gnu-emacs@gnu.org; Sun, 09 Oct 2022 02:58:44 -0400 Original-Received: by mail-pg1-x533.google.com with SMTP id bh13so7990829pgb.4 for ; Sat, 08 Oct 2022 23:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=10WIWXbitJ3pnd/GQc6/E0abf4+j82lmAVrkYVHVabk=; b=j26QhC9Cn6lE4KS0MoENuQUXoJkkjLIEIVEyemkdnR7V3tHzfsH2WdxiMCqqksFwQW y9WamcAo4wirXu0xoXoYNc0voiUX/xDmuBptrSLsG2NSzDHRQTE8Zd9g0JXwcR1KjP5k u6FKHU2TOjvjAvXe1RyYpSPBYoHQm3qeJAqjBFKveNMoR2U3dP2bLJenF5E/HJEcUMZa bYATP60VlaRj8H3BOD8KYpreAGgY4R+ggbexVqRCakVTQIUk4jTUgwLyUhKpf8BtswA8 yCTYKXjn8sHcl6Q6QYZ4qJQQ9Kr3F7UXIYNgdBNeHv/H47d0fGoFPo4HLbn0UOYjqG14 8PaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=10WIWXbitJ3pnd/GQc6/E0abf4+j82lmAVrkYVHVabk=; b=jRHQrKQyGYUJlBbGjQVYfLl5GMDt17WjtePk0DO0b9jr2xqCVIKazkwws1JPunIVwv ZjKaINuGxWOoZrD7Wj4XdGXYisdtVizWHwwJeXEaqY9hRnCYTSBCbMVEI4JYmJLoPP4j r6ey7+yKmjl34uuOG8DcOkAVbBo/RAL1u/MqqQ95OQwI8evsd8TuIuNJLrd4FJRmjHIb QoOsLVEf/R6kyVfSRBBN/DcSI1vxDt+RIoDGFG58Nr2y2E9V4TfbWtPC2/88v4Q8nz2A XeAyicxGvaBk0umgXeNuQTZNglYnrhZoHrwhJR8CBtAEP32gK4u+/XVak3nX7jigP9ys 0xGg== X-Gm-Message-State: ACrzQf1eRIM/LmgK08K1Yxry1FC6RHx3QKgr4qEn04SEg6icYCAO9zy4 pFNh/93J8r5aWId7ZgQqd+C5whUF+kI= X-Google-Smtp-Source: AMsMyM4Zev/DarsXa5gjpcvCyfZT2OTZhPW1dWSc38sCmBziv70uNQZ7fPvJvAKJ+Th2gExbxsvgOA== X-Received: by 2002:a05:6a00:1a07:b0:541:6060:705d with SMTP id g7-20020a056a001a0700b005416060705dmr13881501pfv.61.1665298719099; Sat, 08 Oct 2022 23:58:39 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id b8-20020a170903228800b0016c9e5f291bsm4340227plh.111.2022.10.08.23.58.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 23:58:38 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=kobarity@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:244945 Archived-At: --Multipart_Sun_Oct__9_15:58:10_2022-1 Content-Type: text/plain; charset=US-ASCII Hi, Completion in Python mode buffer fails under certain conditions: - non-native completion is used, - ElDoc mode is used, or - FFAP is used. Here is how to reproduce the problem of non-native completion: 1. emacs -Q 2. Open the following Python file. #+begin_src python import sys #+end_src 3. Use M-x customize-variable to disable python-shell-completion-native-enable 4. C-u -1 M-x eldoc-mode (Disable ElDoc mode) 5. C-c C-p (M-x run-python) 6. C-x o (Back to the Python mode buffer) 7. C-c C-c (M-x python-shell-send-buffer) 8. C-n (M-x next-line) 9. Type "sys." 10. C-M-i (M-x completion-at-point) 11. Completions are shown in *Completions* buffer. 12. Type "e" 13. C-M-i (M-x completion-at-point) 14. "No match" is shown in the minibuffer. This does not happen when native completion is enabled and ElDoc mode is disabled. The following steps show the problem of ElDoc mode: 1. emacs -Q 2. Open the following Python file. #+begin_src python import sys #+end_src 3. Make sure that ElDoc mode is enabled. 4. C-c C-p (M-x run-python) 5. Make sure that "Shell native completion is enabled." is shown in the minibuffer. 6. C-x o (Back to the Python mode buffer) 7. C-c C-c (M-x python-shell-send-buffer) 8. C-n (M-x next-line) 9. Type "sys." 10. Wait for 1-2 seconds to make sure ElDoc function is run by the idle timer. 11. C-M-i (M-x completion-at-point) 12. "No match" is shown in the minibuffer. The problem with FFAP can be reproduced with similar steps. The direct cause of these problems is that `python-util-comint-last-prompt' returns nil, which is not supposed in `python-shell-completion-at-point'. `python-util-comint-last-prompt' is a wrapper to return `comint-last-prompt'. `comint-last-prompt' is initialized to nil in `comint-snapshot-last-prompt' and is set in `comint-output-filter'. However, `python-shell-send-string-no-output' which is used by the features mentioned above temporarily changes the `process-filter' to redirect the output. This causes `comint-output-filter' to not be called and `comint-last-prompt' to remain nil. I think `comint-snapshot-last-prompt' should not be called as long as `comint-output-filter' is not called and the Inferior Python Shell buffer is not changed. Attached is a patch to fix this issue. Best Regards, -- In GNU Emacs 29.0.50 (build 5, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2022-10-09 built on ubuntu Repository revision: 9d47364634f96b2f2651a7f3942f8f87b920f02d Repository branch: master System Description: Ubuntu 22.04.1 LTS Configured using: 'configure --without-libgmp' Configured features: ACL CAIRO FREETYPE GIF GLIB GNUTLS GSETTINGS HARFBUZZ JPEG LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM LUCID ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/screen term/xterm xterm byte-opt gv bytecomp byte-compile cconv rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads inotify dynamic-setting system-font-setting font-render-setting cairo x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 46148 9345) (symbols 48 5790 0) (strings 32 15049 1660) (string-bytes 1 427012) (vectors 16 8356) (vector-slots 8 105418 10463) (floats 8 24 349) (intervals 56 216 0) (buffers 1000 11)) --Multipart_Sun_Oct__9_15:58:10_2022-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-Python-completion-failure-under-certain-conditio.patch" Content-Disposition: attachment; filename="0001-Fix-Python-completion-failure-under-certain-conditio.patch" Content-Transfer-Encoding: 7bit >From 6bd4d7fdf16cda18a921c2b63221fc2aac84fb8c Mon Sep 17 00:00:00 2001 From: kobarity Date: Sun, 9 Oct 2022 15:39:52 +0900 Subject: [PATCH] Fix Python completion failure under certain conditions * lisp/progmodes/python.el (python-shell-send-string-no-output): Invalidate `comint-snapshot-last-prompt'. * test/lisp/progmodes/python-tests.el (python-tests-shell-wait-for-prompt): New helper function. (python-tests-with-temp-buffer-with-shell): New helper macro. (python-shell-completion-1, python-shell-completion-native-1) (python-shell-completion-native-with-ffap-1) (python-shell-completion-native-with-eldoc-1): New tests. --- lisp/progmodes/python.el | 2 + test/lisp/progmodes/python-tests.el | 90 +++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 80c5b31b6e..9f29eb417e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3417,6 +3417,8 @@ python-shell-send-string-no-output (lambda (_proc str) (with-current-buffer (process-buffer process) (python-shell-output-filter str)))) + ((symbol-function 'comint-snapshot-last-prompt) + #'ignore) (python-shell-output-filter-in-progress t) (inhibit-quit t)) (or diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index fdaedb5fd7..eed9c18ede 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -43,6 +43,34 @@ python-tests-with-temp-buffer (goto-char (point-min)) ,@body))) +(defun python-tests-shell-wait-for-prompt () + "Wait for the prompt in the shell buffer." + (with-current-buffer (python-shell-get-buffer) + (while (not (python-util-comint-last-prompt)) + (sit-for 0.1)))) + +(defmacro python-tests-with-temp-buffer-with-shell (contents &rest body) + "Create a `python-mode' enabled temp buffer with CONTENTS and `run-python'. +BODY is code to be executed within the temp buffer. Point is +always located at the beginning of buffer. Native completion is +turned off. Shell buffer will be killed on exit." + (declare (indent 1) (debug t)) + `(with-temp-buffer + (let ((python-indent-guess-indent-offset nil) + (python-shell-completion-native-enable nil)) + (python-mode) + (unwind-protect + (progn + (run-python nil t) + (insert ,contents) + (goto-char (point-min)) + (python-tests-shell-wait-for-prompt) + ,@body) + (when (python-shell-get-buffer) + (python-shell-with-shell-buffer + (let (kill-buffer-hook kill-buffer-query-functions) + (kill-buffer)))))))) + (defmacro python-tests-with-temp-file (contents &rest body) "Create a `python-mode' enabled file with CONTENTS. BODY is code to be executed within the temp buffer. Point is @@ -4365,6 +4393,68 @@ python-shell-completion-native-interpreter-disabled-p-1 (python-shell-interpreter "/some/path/to/bin/pypy")) (should (python-shell-completion-native-interpreter-disabled-p)))) +(ert-deftest python-shell-completion-1 () + (skip-unless (executable-find python-tests-shell-interpreter)) + (python-tests-with-temp-buffer-with-shell + " +import abc +" + (let ((inhibit-message t)) + (python-shell-send-buffer) + (python-tests-shell-wait-for-prompt) + (goto-char (point-max)) + (insert "abc.") + (should (completion-at-point)) + (insert "A") + (should (completion-at-point))))) + +(ert-deftest python-shell-completion-native-1 () + (skip-unless (executable-find python-tests-shell-interpreter)) + (python-tests-with-temp-buffer-with-shell + " +import abc +" + (let ((inhibit-message t)) + (python-shell-completion-native-turn-on) + (python-shell-send-buffer) + (python-tests-shell-wait-for-prompt) + (goto-char (point-max)) + (insert "abc.") + (should (completion-at-point)) + (insert "A") + (should (completion-at-point))))) + +(ert-deftest python-shell-completion-native-with-ffap-1 () + (skip-unless (executable-find python-tests-shell-interpreter)) + (python-tests-with-temp-buffer-with-shell + " +import abc +" + (let ((inhibit-message t)) + (python-shell-completion-native-turn-on) + (python-shell-send-buffer) + (python-tests-shell-wait-for-prompt) + (goto-char (point-max)) + (insert "abc.") + ;; This is called when FFAP is enabled and a find-file function is called. + (python-ffap-module-path "abc.") + (should (completion-at-point))))) + +(ert-deftest python-shell-completion-native-with-eldoc-1 () + (skip-unless (executable-find python-tests-shell-interpreter)) + (python-tests-with-temp-buffer-with-shell + " +import abc +" + (let ((inhibit-message t)) + (python-shell-completion-native-turn-on) + (python-shell-send-buffer) + (python-tests-shell-wait-for-prompt) + (goto-char (point-max)) + (insert "abc.") + ;; This is called by idle-timer when ElDoc is enabled. + (python-eldoc-function) + (should (completion-at-point))))) -- 2.34.1 --Multipart_Sun_Oct__9_15:58:10_2022-1--