completion-at-point
function for pdb
(Python debugger)
Enable pdb completions for specific modes by adding pdb-capf
to completion-at-point-functions
, e.g. (for GUD):
(add-hook 'pdb-mode-hook
(lambda ()
(add-hook 'completion-at-point-functions
'pdb-capf nil t)))
[ME]: when completion-at-point called, pdb-capf--completions return the correct completion strings but completion-table-with-cache called two times and one of which includes unrelated global completions and in the end, there is no completion is found. It seems like when completion-table-with-cache first time, it has the related completions but then overriden by other completions... why?
[AI]: Without seeing the specific code in action it's hard to know for sure, but I can provide a few potential explanations and solutions:
-
completion-table-with-cache
is designed to cache completion results for performance. But as the state of a pdb session may change minutes to minutes, so the cache might be causing troubles. It's possible that it's caching earlier completions that are no longer relevant.If possible, you can work around this by using
completion-table-dynamic
wrap aroundpdb-capf--completions
instead ofcompletion-table-with-cache
. This makes the completions to be re-calculated every time, bypassing the cache:(completion-table-dynamic #'pdb-capf--completions)
-
If switching to
completion-table-dynamic
doesn't resolve the issue, it's also possible that there's a race condition between the two calls tocompletion-table-with-cache
. If the pdb process hasn't finished computing the completions by the time the second call is made, the second call might overwrite the result of the first call.If this is the case, you can try to add a sleep or a loop that waits until the pdb process has generated the completions before calling
completion-table-with-cache
for the second time.
It's also worth noting that in your current implementation, pdb-capf--completions
is fetching the completions synchronously: it waits until the completions have been returned before it finishes. This means that if the pdb process takes a while to generate the completions, Emacs will hang. You might want to refactor pdb-capf--completions
to fetch the completions asynchronously to improve the user experience.