Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completion-at-point #42

Closed
piranha opened this issue Apr 7, 2020 · 7 comments
Closed

completion-at-point #42

piranha opened this issue Apr 7, 2020 · 7 comments

Comments

@piranha
Copy link

piranha commented Apr 7, 2020

I wonder if it's possible to use selectrum for completion-at-point? It's pretty much "magically" took over all selection inputs, except this one: it shows a new buffer with completion-list-mode.

@raxod502
Copy link
Member

raxod502 commented Apr 7, 2020

I agree, that default interface looks pretty icky (I had never used completion-at-point before). Should be not too hard to implement.

@AmaiKinono
Copy link
Contributor

AmaiKinono commented Apr 8, 2020

Try this from my (currently private) package ;)

(defun citre-completion-in-region (start end collection &optional predicate)
  "A function that replace default `completion-in-region-function'.
This completes the text between START and END using COLLECTION.
PREDICATE says when to exit.

When there are multiple candidates, this uses standard
`completing-read' interface, while the default one in Emacs pops
a *Completions* buffer to show them.  When combined with some
minibuffer completion framework, it's more user-friendly then the
default one.

Notice when `completing-read-function' is
`completing-read-default' (i.e., not enhanced by a minibuffer
completion framework), this falls back to
`completion--in-region'."
  (if (eq completing-read-function #'completing-read-default)
      (completion--in-region start end collection predicate)
    (let* ((str (buffer-substring-no-properties start end))
           (completion-ignore-case (string= str (downcase str)))
           (candidates
            (nconc
             (completion-all-completions str collection predicate (- end start))
             nil))
           (completion nil))
      (pcase (length candidates)
        (0 (message "No completions"))
        (1 (setq completion (car candidates)))
        (_ (setq completion (completing-read (format "(%s): " str)
                                             candidates predicate t))))
      (when completion
        (delete-region start end)
        (insert (substring-no-properties completion))))))

and set completion-in-region-function to it.

@raxod502
Copy link
Member

@AmaiKinono Would you be alright with my making some amendments and then including a version of your code in Selectrum?

@AmaiKinono
Copy link
Contributor

Of course ;) Please do it.

And, I have some suggestions. A completion-at-point-function backend can have an :annotation-function property in its return value. The default completion--in-region uses it to display an annotation for each candidate. I didn't look into how it handles this. And, if you look into the code of elisp-completion-at-point, you'll see it offers some extension properties that's useful for company-capf. I think it would be good if selectrum could make use of :annotation-function and :company-docsig. We can use a prefix and a right-margin text to display them.

@raxod502
Copy link
Member

I haven't implemented any extensions at this time, but would be happy to see a pull request.

@raxod502 raxod502 added the waiting on response Needs more info or follow-up, will be closed after 90 days if no response label Apr 19, 2020
AmaiKinono added a commit to AmaiKinono/selectrum that referenced this issue Apr 19, 2020
raxod502 added a commit that referenced this issue Apr 24, 2020
…62)

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
@andyleejordan
Copy link
Contributor

I feel like ya'll were reading my mind. I went through the pain of setting up Company so I could use completions from LSP without the terrible default completion framework...this is all I wanted, to select completions using Selectrum.

Thank you! 😍

@raxod502
Copy link
Member

This thread is being closed automatically by Tidier because it is labeled with "waiting on response" and has not seen any activity for 90 days. But don't worry—if you have any information that might advance the discussion, leave a comment and I will be happy to reopen the thread :)

@raxod502 raxod502 removed the waiting on response Needs more info or follow-up, will be closed after 90 days if no response label Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants