4

According to describe-key (C-h k), every character I type runs self-insert-command and I suspect that self-insert-command calls some undocumented hook to perform text completition.

I am trying to debug company-mode, which occasionally fails to complete my input. So, describe-function says that self-insert-command calls post-self-insert-hook. I set it to nil and tried to type something that would be autocompleted — and it was completed anyway! In addition to this, self-insert-command calls expand-abbrev and auto-fill-function, but I tried to call both, and neither shows a popup text. So, it seems like every keypress runs some other hook used by company-mode.

I found that company-complete-common is the function that does autocompletition, so I set a breakpoint there to find this mysterious hook by using a backtrace. And… it didn't work! It works if I call company-complete-common interactively, but if I trigger completion by typing a character, and the same window pops up, the breakpoint is ignored!

I'm out of ideas, I hope somebody knows how this works.

  • I found in the company.el that company-mode sets some company-pre-command and company-post-command to a pre-command-hook/post-command-hook, but these doesn't do autocompletition either. – Hi-Angel Nov 22 '14 at 23:19
7

Unless you invoke one of the completion commands directly (such as M-x company-complete-common), the completion maybe-happens and the popup is rendered in company-post-command.

It looks at the current command, sees if it satisfies the value of company-begin-commands, and calls company--perform.

The latter looks at the buffer contents, and checks whether the prefix value returned by the currently used backend satisfies company-minimum-prefix-length, if so then asks for completions from the backend.

If completions were found, company-post-command calls all currently configured frontends with an argument post-command. That's where the popup rendering happens.

When completion doesn't work (and you don't see any errors in *Messages*), check whether it works with M-x company-complete-common, at the same buffer position. If it does, you might need to figure out the exact command your keypress was calling (try C-h k), and then add it to company-begin-commands.

  • I came to the conclusion because for I am near of a character that triggers autocompletition, if I am press M-: and enter (company-post-command), nothing happens. – Hi-Angel Nov 23 '14 at 8:18
  • 1
    That won't work; see the update. – Dmitry Nov 23 '14 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.