3

I'm trying to get company mode to automatically trigger the pop-up with a list of possible completion. Unless I'm doing this wrong this is not the default behaviour? Current I have to run M-x company-complete manually.

I am not interesting in binding it to a key. I want the idle-completion behaviour. I'm using this with rustic (rust-mode fork).

Steps to reproduce:

  • Start from fresh emacs
[ -e ~/.emacs.d ] && mv ~/.emacs.d ~/.emacs.d.bak
mkdir ~/.emacs.d && cat <<'EOT' > ~/.emacs.d/init.el
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "https://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.org/packages/")))

(require 'package)
(package-initialize)
EOT
  • Start Emacs
  • Install packages (from MELPA): lsp-mode, company, rustic
  • Install rustup (instructions at https://rustup.rs )
  • Install additionnal components: rustup component add rls rustfmt rust-src
  • Create new test project: cargo new rtest
  • Add the following to init.el:
(defun my-rust-hook ()
  (require 'company)
  (setq company-minimum-prefix-length 2)
  (setq company-idle-delay 0)

  ;; conf 1
  ;(setq company-auto-complete nil)
  ;; conf 2
  (setq company-auto-complete t)
  (add-to-list 'company-auto-complete-chars (char-syntax ?:))

  (company-mode 1)
  )

(eval-after-load 'rustic
  '(progn
     (require 'lsp)
     (when (not (require 'yasnippet nil 'no-err))
       (setq lsp-enable-snippet nil))
     (add-hook 'rustic-mode-hook 'my-rust-hook)))
  • Restart emacs
  • Open rtest/src/main.rs
  • Type:
use std::env;

fn main() {
    // place point here at the end
}
  • Type env:: and wait. Completion menu doesn't show up.
  • You can try conf 1 or 2 from the init.el but you will see same result.
  • Running M-x company-complete works and shows the menu but idling doesn't.
1

1 Answer 1

1

What is the value of company-begin-commands? It should include at least self-insert-command. Also, try changing company-idle-delay to a low value above zero.

The Rust setup I describe in my setting up Rust with Emacs guide comes with a repo that has a working auto completion config via company. When in doubt, compare with that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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