1

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))
    :init
    (setq ac-auto-start nil
          ac-quick-help-delay 0.5)
    :config
    (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.

5
  • Use :after instead of :defer. (use-package foo :after bar)
    – fhdhsni
    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
    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
    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
    Jun 16, 2017 at 7:05
  • I'm sorry missing that. I've tested locally and update as an answer :-)
    – lurdan
    Jun 16, 2017 at 8:10

1 Answer 1

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)
  :init
  (defun my--auto-complete ()
    (interactive)
    (unless (boundp 'auto-complete-mode)
      (global-auto-complete-mode 1))
    (auto-complete))
  )

I myself use :demand t to load immediately.

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

3
  • 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
    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
    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
    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.