How to use auto-complete with use-package and have auto-complete loaded later?

Following config is working, but how to get rid of the defer 2?

(use-package auto-complete-config
    :defer 2
    :bind (:map ac-mode-map
                ("M-<tab>" . auto-complete))
    (setq ac-auto-start nil
          ac-quick-help-delay 0.5)
    (global-auto-complete-mode t))

I tried global-auto-complete-mode and auto-complete mapped to global key map key M-TAB but both are not working.

  • Use :after instead of :defer. (use-package foo :after bar)
    – fhdhsni
    Commented Jun 15, 2017 at 4:28
  • @fhdhsni thanks for the suggestion. I can't spot a package which I could use in place of bar. But the :after key is a nice solution for yasnippet which is pulled by auto-complete. (yasnippet takes some time to load and is the reason I want to delay auto-complete loading)
    – jue
    Commented Jun 15, 2017 at 13:46
  • You seems to :bind M-TAB to ac-mode-map, which will be activated AFTER loading auto-complete-mode. Try deleting :defer line and changing :bind to global -- (("M-<tab>" . auto-complete))
    – lurdan
    Commented Jun 16, 2017 at 1:16
  • @lurdan This, I already did, it is not working. I intended the sentence below the code to state this.
    – jue
    Commented Jun 16, 2017 at 7:05
  • I'm sorry missing that. I've tested locally and update as an answer :-)
    – lurdan
    Commented Jun 16, 2017 at 8:10

1 Answer 1


auto-complete checks if you are already in auto-complete-mode (in function ac-start). But with lazy loading, when you call auto-complete, you are not in auto-complete-mode because it is not loaded yet.

So, you should call either auto-complete-mode or global-auto-complete-mode before you call auto-complete.

If you stick it to be loaded later, this snippet may help:

(use-package auto-complete-config
  :ensure auto-complete
  :bind ("M-<tab>" . my--auto-complete)
  (defun my--auto-complete ()
    (unless (boundp 'auto-complete-mode)
      (global-auto-complete-mode 1))

I myself use :demand t to load immediately.

Note: M-<Tab> is not working but M-<tab> works

  • I like your idea, but there seems yet another problem. The key M-<tab> keeps bound to completion-at-point in scratch buffer and in text-mode to ispell-complete-word even with a minimalistic config run by emacs -Q -l test-config.el I don't get whats happening.
    – jue
    Commented Jun 16, 2017 at 10:00
  • I do not want to use :demand t because in my config auto-complete pulls yasnippet and this takes some seconds to load.
    – jue
    Commented Jun 16, 2017 at 10:05
  • please change the :bind line to :bind ("M-<tab>" . my--auto-complete), then your code works. Reason: Tab does not work but tab is and double parentheses are not necessary.
    – jue
    Commented Jun 16, 2017 at 12:38

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.