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 in the minibuffer #42

Open
Bad-ptr opened this issue Dec 4, 2013 · 6 comments
Open

Completion in the minibuffer #42

Bad-ptr opened this issue Dec 4, 2013 · 6 comments
Labels

Comments

@Bad-ptr
Copy link
Contributor

Bad-ptr commented Dec 4, 2013

I think it will be helpful if company-elisp backend will be enabled also for inferior-emacs-lisp-mode.

Also, here is a quick scratch of how company-mode could work for minibuffer completions(handy for eval-expression(M-:)): https://gist.github.com/Bad-ptr/7787596 .
Maybe it will give you some thoughts of how it could be done and maybe added to company-mode.

@dgutov
Copy link
Member

dgutov commented Dec 5, 2013

Part one: done.

Second part: the approach is good, but do you actually like how the company tooltip looks is the minibuffer?

I have a widescreen monitor, so I kind of dislike packages that make minibuffer taller (like ido-vertical-mode and grizzl), because that leaves lots of unoccupied space to the right. And the windows are jumping.

So I think we should first learn to render the popup in the window above the minibuffer.

But if you're using this configuration already, I'll gladly commit your modification of company--should-complete and the introduction of the related variable, so that you don't need to redefine the function.

N.B.: company-elisp-minibuffer can delegate to company-elisp, at least for some commands. No need to copy the definition.

@Bad-ptr
Copy link
Contributor Author

Bad-ptr commented Dec 5, 2013

Part one: done.

Good.

do you actually like how the company tooltip looks is the minibuffer?

Not quite.

I kind of dislike packages that make minibuffer taller (like ido-vertical-mode )

Can't agree. I do use ido-vertical-mode and like it. Yes it makes minibuffer taller, but only for while you interact with it.

So I think we should first learn to render the popup in the window above the minibuffer.

Maybe

But if you're using this configuration already

Yes, I do. I made it mainly for eval-expression cause there is no completion in it and it similar to ielm(or just editing elisp file). While for execute-extended-command there is smex, ido, icomplete and many other completion engines.

I'll gladly commit your modification of company--should-complete and the introduction of the related variable

I think it will be good. (Yes, I agree that using tooltips in minibuffer is quite controversial concept.)

company-elisp-minibuffer can delegate to company-elisp

ok. I'll look at that.

@dgutov
Copy link
Member

dgutov commented Dec 6, 2013

Maybe

Good, let's keep this issue open until then.

I think it will be good. (Yes, I agree that using tooltips in minibuffer is quite controversial concept.)

Actually, I'm just going to remove that (minibufferp) check. Since global-company-mode doesn't enable the local mode in the minibuffer anymore, there's no need to work around it.

dgutov added a commit that referenced this issue Dec 6, 2013
@dgutov dgutov added the wishlist label Jun 7, 2014
@Bad-ptr
Copy link
Contributor Author

Bad-ptr commented Sep 20, 2014

Hello.
As you broke again my 'completion in minibuffer' code(It worked then it didn't then worked again and now it don't. I guess it's all about dancing around company--posn-col-row and related stuff).

And now again the problem is that the tooltip overlay appears at the cursor position, cursor jumps somewhere and everything becomes messy.

What I want to suggest is to put more responsibility for such situations on users(or mainteiners of major/minor modes that breaks company) ;p, by something like:

  (defvar-local company-col-offset 0 "Horisontal tooltip offset.")
  (defvar-local company-row-offset 0 "Vertical tooltip offset.")

  (defun company--posn-col-row (posn)
    (let ((col (car (posn-col-row posn)))
          ;; `posn-col-row' doesn't work well with lines of different height.
          ;; `posn-actual-col-row' doesn't handle multiple-width characters.
          (row (cdr (posn-actual-col-row posn))))
      (when (and header-line-format (version< emacs-version "24.3.93.3"))
        ;; http://debbugs.gnu.org/18384
        (cl-decf row))
      (cons (+ col (window-hscroll) company-col-offset) (+ row company-row-offset))))

It works for my case(I just set col-offset and row-offset to 1) and may be useful in solving other issues with wrongly placed tooltip, as it seems that general solution is not possible.

@dgutov
Copy link
Member

dgutov commented Sep 20, 2014

Have you tried making an around-advice for this function? It should work just as well.

And now again the problem is that the tooltip overlay appears at the cursor position, cursor jumps somewhere and everything becomes messy.

Does that only happen in minibuffer? I've seen this problem once, but it should've been fixed by a3cd0d6.

you broke again my 'completion in minibuffer' code

Sorry, but that isn't something I'm paying attention to, yet. If you'd like to help prototyping popup display using different approach, which should work in minibuffer, as well in other advanced situation, see http://lists.gnu.org/archive/html/emacs-devel/2014-08/msg00295.html.

@dgutov dgutov changed the title Completions in ielm and in minibuffer. Completion in the minibuffer Oct 11, 2023
@dgutov
Copy link
Member

dgutov commented Oct 31, 2023

Some up-to-date recommendations for when someone wants to use Company in the minibuffer:

(add-hook 'minibuffer-setup-hook 'my/company-mode-maybe)

(defun my/company-mode-maybe ()
  (when (local-variable-p 'completion-at-point-functions)
    (company-mode 1)))

;; And entirely optional:
(define-key company-mode-map (kbd "<tab>") 'company-complete-common-or-cycle)

Plus it's preferable to install company-posframe, if only to reduce the jumping in the minibuffer's height.

The pos-col-row advice above doesn't seem necessary, OTOH.

Anyway, most commands (e.g. describe-function or find-file) don't set up completion-at-point-functions, so any kind of integration with them would require to also write a completing-read-function adapter. Or, in find-file's case, at least adding it to the special cases in the snippet above, in order for company-files to be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants