[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: |
Stefan Monnier |
Subject: |
Re: Recommendation for CAPF setup when you don't know completion string in advance |
Date: |
Tue, 11 May 2021 00:04:54 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> (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)))))
[...]
> 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?
There's `completion-table-with-context`.
Note that it comes with the following:
;; TODO: add `suffix' maybe?
so you probably won't be able to use it as-is and you'll need to write
your function instead. But hopefully it should be enough to get
you started. It shouldn't be terribly hard.
I think one problem you may encounter is that in the default UI,
selecting an entry from *Completions* (e.g. with a middle click) will
probably throw away the "suffix" (i.e. the text after the end of the
boundary).
If so, I suggest you `M-x report-emacs-bug` (tho maybe I did fix this
one already; but there might be a few other such corner cases where we
throw away the text after the end of the boundary).
Stefan