From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#50459: 28.0.50; Python shell completion is incompatible with flex, orderless, etc. Date: Thu, 09 Sep 2021 18:46:57 +0200 Message-ID: <87mtolr91a.fsf@gmail.com> References: <87wnnsl1d1.fsf@gmail.com> <87czpijixk.fsf@gmail.com> <877dfqjfwu.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29548"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Gregory Heytings , Michael Albinus To: 50459@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 09 18:48:11 2021 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 1mONDe-0007X8-VN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Sep 2021 18:48:11 +0200 Original-Received: from localhost ([::1]:50980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mONDd-0006tX-Uo for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 Sep 2021 12:48:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mONDW-0006rm-Sm for bug-gnu-emacs@gnu.org; Thu, 09 Sep 2021 12:48:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mONDW-0000c0-Jj for bug-gnu-emacs@gnu.org; Thu, 09 Sep 2021 12:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mONDW-0005kR-Hb for bug-gnu-emacs@gnu.org; Thu, 09 Sep 2021 12:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 Sep 2021 16:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50459 X-GNU-PR-Package: emacs Original-Received: via spool by 50459-submit@debbugs.gnu.org id=B50459.163120603222018 (code B ref 50459); Thu, 09 Sep 2021 16:48:02 +0000 Original-Received: (at 50459) by debbugs.gnu.org; 9 Sep 2021 16:47:12 +0000 Original-Received: from localhost ([127.0.0.1]:36102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mONCh-0005j4-Kk for submit@debbugs.gnu.org; Thu, 09 Sep 2021 12:47:11 -0400 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:34307) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mONCf-0005ir-OA for 50459@debbugs.gnu.org; Thu, 09 Sep 2021 12:47:10 -0400 Original-Received: by mail-wm1-f49.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so1486457wmh.1 for <50459@debbugs.gnu.org>; Thu, 09 Sep 2021 09:47:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=fuUNL1sKHeWShB55rBBO0cs7/sPgKMk5+Rh9dwuYriQ=; b=gyIbVyU+/3PoJYJ+JgATCMf2VPj7z+c+/Rmwv1nMGNarCqS1s7mws64sSj1Ldf2j+s TzYWTZOqNsOAIm1f3dPMMaNJyr4XDibCDjxQ+y8El9CU3KaBHywwQ8Vsg0BcvLL+txb2 dsDgtKo9lrIJrQVGqgH/dUfUc8itPr6xEPyCAGAsNfJaLG+5krz53/a45TQLKU1YkPXH Q3B3vlXLsADUrENQasH5B0s3L0sN2oK/opZCSuWPYRNNE4s91LY1C9SS6EGZvi08Yihg P+ZEJEFnmMp2JLgGS/p0SEb+hAQOSyyBxvFxout2c10/DEsjl9ukva4oVaO+VppPcV60 bZjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=fuUNL1sKHeWShB55rBBO0cs7/sPgKMk5+Rh9dwuYriQ=; b=oKwRWGs7Bhu1Kjuti+An2OVEk2nGTXBHF31WMU7PNOx7V4uxlhE8/QviiGJ2TQj4Mw 1y1YTJ75Rgzl9VYIbtVH2pT9G30GJGcIu7IrIMfDBrZTjbe+C6iy2dQ8Y6HsjfW3R5Is kjJkZ8HLL7DYqjiPmvAilOercYoB9aoPzC9EfsIOs+oR133f416bwqjiKN6QqfMljkw+ J3RX8zheOCc3UFBvvsWG7kCzdef9N0C2lURxbbpNRJ1jxch5Z4oQDLKcDKau1iAn6ljZ 8Tr2UaBx0gwWpS8WVVktrX2K8D/8I1yt7P3uyFKfZ8iXBqSWaubNNdnk6YRVI6N5/9am mMFA== X-Gm-Message-State: AOAM531lOHM+Xp3waNL2EReZBzNT27wpUbxoHAmpMjA700bXS/DXHWG/ sM10xlyvhjs1nEn4Xxdvksw= X-Google-Smtp-Source: ABdhPJxz4BoEzXAikTA9mIx9OJxwJ8LnVZL/Fzu/E25DTLIPoJXc+z5w5dxcCz60+Src05fqeDyj6g== X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr4079804wmk.135.1631206023698; Thu, 09 Sep 2021 09:47:03 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::b1d]) by smtp.gmail.com with ESMTPSA id m3sm2856791wrg.45.2021.09.09.09.47.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 09:47:02 -0700 (PDT) In-Reply-To: (Gregory Heytings's message of "Thu, 09 Sep 2021 08:50:59 +0000") 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:213927 Archived-At: --=-=-= Content-Type: text/plain After more discussions elsewhere [1], I noticed another problem with the dynamic completion table from python.el. Each call to the completion table requires communication with the inferior process. If called frequently enough, the comint input filters can get confused, and some garbage gets printed to the shell. If the inferior is running over Tramp, the problem gets amplified. Now, this is not likely to cause much trouble when calling `completion-at-point' manually, but it is a problem with any of continuously-updating completion UIs like Company or Corfu. To alleviate this, the completion-at-point function could implement some sort of caching. The difficult question is when to invalidate the cache. I've attached one possiblility as a draft patch. If the approach seems reasonable, then I'll format it properly. As a side effect, the patch also solves the original issue described in this ticket. Please let me know what you think. [1] https://github.com/oantolin/orderless/issues/79 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=python-capf.diff diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 4f222b4cf5..3239722981 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3841,6 +3841,8 @@ python-shell-completion-get-completions (split-string completions "^'\\|^\"\\|;\\|'$\\|\"$" t))))) +(defvar-local python-shell--capf-cache nil) + (defun python-shell-completion-at-point (&optional process) "Function for `completion-at-point-functions' in `inferior-python-mode'. Optional argument PROCESS forces completions to be retrieved @@ -3895,11 +3897,13 @@ python-shell-completion-at-point #'ignore #'python-shell-completion-get-completions)) (t #'python-shell-completion-native-get-completions))))) - (list start end - (completion-table-dynamic - (apply-partially - completion-fn - process import-statement))))) + (let ((re (or (car python-shell--capf-cache) regexp-unmatchable)) + (prefix (buffer-substring-no-properties start end))) + (unless (string-match re prefix) + (setq python-shell--capf-cache + (cons (concat "\\`" (regexp-quote prefix) "\\(?:\\sw\\|\\s_\\)*\\'") + (funcall completion-fn process import-statement prefix))))) + (list start end (cdr python-shell--capf-cache)))) (define-obsolete-function-alias 'python-shell-completion-complete-at-point --=-=-=--