Okay, I've attached a patch which seems to work fine. On Fri, 10 Sep 2021 at 16:32, Dmitry Gutov wrote: > On 09.09.2021 19:46, Augusto Stoffel wrote: >> 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. > > It's much simpler than what we talked about, but given that > python-shell-completion-at-point doesn't really look past the current > line, your approach should work fine. Yes, and you're right --- I've did it that way because this comint-based completion basically only works for globals anyway. > > I'm not very familiar with the code, so I cannot approve the exact > patch, though, sorry. > > As a bonus, though, maybe add the position of prompt on the > shell-buffer to the invalidation key? Like, if a user imports some new > lib in there, that can bring in new completions. Good idea. I've added this to the patch. It still won't show the new completions until the user evaluates the import, but this is the best you can get by querying an interpreter for the completions. I've also changed a bit the way the "native completion" setup code is sent, so that it doesn't print a message directly in the shell buffer (there is still an echo area message).