emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Recommendation for CAPF setup when you don't know completion string


From: JD Smith
Subject: Re: Recommendation for CAPF setup when you don't know completion string in advance
Date: Mon, 10 May 2021 23:33:44 -0400

> On Apr 3, 2021, at 7:49 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> 
>> So it’s a quandary: I won’t yet know `beg’ and `end’ until _after_
>> interacting with iPython.  Is there any way to “revise” ‘beg’ and ‘end’ in
>> a collection function returned from a CAPF?
> 
> Indeed, that's a problem.
> You might be able to get away with the following:
> 
> Make your CAPF function return a beg..end that covers "the whole line"
> and which returns a completion table in the form of a function.
> That function will then defer to the iPython code for the grunt of its
> work and will return the "real" boundaries via the
> `completion-boundaries` method.  This will probably require some caching
> in the completion table so we don't call iPython too many times for
> a single completion (like once for `completion-boundaries`, once for
> `try-completion`, once for `all-completions`, etc...).


Thanks for these good suggestions.  I have been attempting a solution along 
these lines, and I think the performance is fine.  I notice that CAPF first 
asks for metadata (which are static here), then for the boundaries.  At that 
point, I don’t know the boundaries, so I talk to the iPython process, and ask 
it for all the completions for the entire line, given my position within it. It 
returns these, along with the portion of the full line it has decided to 
complete.  From this, I compute and return the boundaries.  Then, in subsequent 
calls to my table lambda, CAPF proceeds with its various ACTION's.  

Pseudo-code for the completion table function I’m building:

(lambda (string pred action)
  (when (no-result-yet-cached-or-cached-string-is-substring-of-string)
    (if (eq action 'metadata) `(metadata …)
      (unless last-prefix
        ;; talk to ipython and save the completion info
        )
      (if (eq (car-safe action) 'boundaries) ; munge the boundaries
          `(boundaries from . to) ; using saved data from ipython
        (complete-with-action action completion-alist string pred)))))

The problem I have encountered is in the final call to `complete-with-action’.  
The original string may be an entire line, such as:

        for i in ran[Tab]

and iPython correctly figures out to complete just a portion of that string; 
say ran -> range.  I tell CAPF about these boundaries (in this case, 9 . 0).  
If, however, I later call complete-with-action (which just calls 
try-completion, all-completions, etc.) with the entire line string (“for in 
ran”), together with a completion-alist that contains iPython’s sub-string 
completions (like “range”), it thinks there is no completion.  If instead I 
just peel off the part of the full line that needs completing (“ran”) and pass 
that to complete-with-action as STRING, it recognizes that there's a good 
completion now, but then _replaces the entire line_ with the result.

How do I get 
complete-with-action/try-completion/test-completion/all-completions etc. to 
respect my boundaries?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]