unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Augusto Stoffel <arstoffel@gmail.com>
To: 50459@debbugs.gnu.org
Cc: Gregory Heytings <gregory@heytings.org>,
	Michael Albinus <michael.albinus@gmx.de>
Subject: bug#50459: 28.0.50; Python shell completion is incompatible with flex, orderless, etc.
Date: Thu, 09 Sep 2021 18:46:57 +0200	[thread overview]
Message-ID: <87mtolr91a.fsf@gmail.com> (raw)
In-Reply-To: <cd485de4cdd0d9059951@heytings.org> (Gregory Heytings's message of "Thu, 09 Sep 2021 08:50:59 +0000")

[-- Attachment #1: Type: text/plain, Size: 1006 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: python-capf.diff --]
[-- Type: text/x-patch, Size: 1471 bytes --]

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

  reply	other threads:[~2021-09-09 16:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 17:52 bug#50459: 28.0.50; Python shell completion is incompatible with flex, orderless, etc Augusto Stoffel
2021-09-08 17:44 ` Augusto Stoffel
2021-09-09  7:11   ` Michael Albinus
2021-09-09  7:32     ` Gregory Heytings
2021-09-09  7:30 ` Gregory Heytings
2021-09-09  7:40   ` Augusto Stoffel
2021-09-09  7:49     ` Gregory Heytings
2021-09-09  8:45       ` Augusto Stoffel
2021-09-09  8:50         ` Gregory Heytings
2021-09-09 16:46           ` Augusto Stoffel [this message]
2021-09-10 11:37             ` Lars Ingebrigtsen
2021-09-10 11:50               ` Augusto Stoffel
2021-09-10 13:14                 ` João Távora
2021-09-10 13:28                   ` Dmitry Gutov
2021-09-10 14:06                     ` João Távora
2021-09-10 14:22                       ` Dmitry Gutov
2021-09-10 14:39                         ` João Távora
2021-09-10 14:43                           ` Dmitry Gutov
2021-09-10 19:27                             ` Augusto Stoffel
2021-09-10 20:08                               ` João Távora
2021-09-11 12:09                 ` Lars Ingebrigtsen
2021-09-11 12:34                   ` Augusto Stoffel
2021-09-11 12:36                     ` Lars Ingebrigtsen
2021-09-10 13:32             ` Dmitry Gutov
2021-09-10 19:08 ` bug#50459: 28.0.50; [PATCH] " Augusto Stoffel
2021-09-11 12:50   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mtolr91a.fsf@gmail.com \
    --to=arstoffel@gmail.com \
    --cc=50459@debbugs.gnu.org \
    --cc=gregory@heytings.org \
    --cc=michael.albinus@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).