Doom-emacs: Auto completion not working

Created on 21 May 2017  ·  29Comments  ·  Source: hlissner/doom-emacs

Auto completion is not working with the default "init.example.el" config.
Tested on macOS 10.12.5 and ubuntu 17.04.

:completion company obsolete

Most helpful comment

Hello,
same issue for python autocomplete. To activate it I need to manually disable and re-enable global-company-mode. It's tedious.

All 29 comments

Could you offer any other information? Like errors or steps to reproduce? What mode are you invoking auto-completion from?

Steps:

git clone https://github.com/hlissner/.emacs.d ~/.emacs.d
cd ~/.emacs.d
cp init.example.el init.el  # maybe edit init.el
make install
make compile       # optional, may take a while

then open emacs, edit a file (lua, python or C) and no autocompletion suggestion is shown.

Even I am not able to get it to work, I thought this was only an issue on my system.
Yes, I have libclang, and installed irony server from within emacs.
After looking into the config for sometime, I saw that you have mapped C-SPC to show suggestion in insert mode, so only then the suggestions are shown, Is this expected? or not? I searched online about on how you may have disabled the suggestions list to appear as text typed, but couldn't find any info. Thanks

leojrfs, are you sure that you have libclang installed on your system? and ran the command 'irony-install-server' from within emacs?

Ah, I see what you mean.

@vsr625 Yes, this was intentional (and a matter of personal preference; I rarely need auto-completion). However, you can reverse this with:

;; these are the defaults (before I changed them)
(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

@leojrfs

  • anaconda-mode (in Python) needs setuptools, e.g. pip install setuptools;
  • irony-mode (in C/C++/ObjC) needs irony-server: M-x irony-install-server
  • lua doesn't need anything, but company-lua (the plugin that gives you autocompletion in lua) is _very_ primitive. As in it only completes from a static list (for the Lua 5.1, 5.2, 5.3 and Love2D APIs). It won't complete custom functions or variables (frustrating, I know). For instance, try autocompleteing raw, you should get:

    lua autocompletion

    Unfortunately, that's the best we can hope for until someone writes a more comprehensive lua completion library.

If you want to test out completion in an environment where it's guaranteed to work, try Emacs Lisp. It has the best completion support in Emacs (understandably).

I apologize for the lack of documentation. I'm working on that. Up until 2 days ago, I really hadn't expected so many people to use my config.

Thanks for replying, that worked exactly as expected, now I get suggestions as I type.
One last question, in cc mode, I am getting suggestions only over the variables I define inside the file.
Is there a way for getting suggestions for snippets and basic c++ language stuff like for main,while,if?

If you want it to complete library functions Irony-mode is smart enough to follow included headers, e.g. #include <iostream>, then try to complete std::co.

But for language constructs like main/while/if, no, irony-mode won't give you that. But I have a good alternative: snippets. My snippets library has snippets for if, for, while, and others. You just need it somewhere yas-snippet-dirs can see them.

But you want those to be included in the completion results, don't you? That's where company-yasnippet comes in. You do need to add it to c++-mode's company backends, but that should give you what you want.

Though, I should add: I'm a bit hazy on the exact format for company-backends to get company-irony-c-headers, company-irony and company-yasnippet to cooperate. It could be '(company-irony-c-headers company-irony company-yasnippet) or '(company-irony-c-headers company-irony :with company-yasnippet) or '(company-yasnippet :with company-irony-c-headers company-irony).

Sorry I'm uncertain. I'm unable to test it myself at the moment.

@hlissner
I've added:

(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

to init.el, but i still don't have completion. is it supposed to go there?
Sorry, im trying emacs for the first time, with your config...

Almost. The module is lazy loaded, so any settings in init.el will be overwritten later.

A slight modification will make it work:

(require 'company)
(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

It'd be better if you made these changes in modules/completion/company/config.el (you'd need to add a :demand t to the def-package declaration), but the above will work just as well to get you started.

Still no completion with

(require 'company)
(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

in init.el.

is there any way that i can see if this is being read?

Oh wait, I recall you ran make compile, right? Emacs will prefer the compiled file over the uncompiled one. You'll need to run make compile again (or make clean to get rid of compiled files altogether -- compilation is optional, you shouldn't be using it while you're making changes to the config).

same situation.
just ran make clean and make compile.

But i just found that one module is failing to compile:

screen shot 2017-05-22 at 01 41 52

Then forgo compilation for now and just do make compile-lite, this will only compile the core files. I'm aware of that error and will push a fix for it tomorrow.

still no completion, even did a clean install:

git clone https://github.com/hlissner/.emacs.d ~/.emacs.d
cd ~/.emacs.d
cp init.example.el init.el

added the following to init.el:

(require 'company)
(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

And then:

make install
make compile-lite

Very strange. Could you run DEBUG=1 make doctor and paste its output here?

On May 22, 2017, 2:57 AM +0200, Leo Soares notifications@github.com, wrote:
>

still no completion, even did a clean install:

git clone https://github.com/hlissner/.emacs.d ~/.emacs.d cd ~/.emacs.d cp init.example.el init.el

added the following to init.el:

(require 'company) (setq company-idle-delay 0.2 company-minimum-prefix-length 3)

And then:

make install make compile


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (https://github.com/hlissner/.emacs.d/issues/77#issuecomment-302975750), or mute the thread (https://github.com/notifications/unsubscribe-auth/AAfLo-hztZzxiJkavIdfjgeW3kMZjHVtks5r8N1fgaJpZM4NhqwK).

DEBUG=1 make doctor
DOOM Doctor
Running Emacs v25.2.1
Compiled with:
  NOTIFY ACL LIBXML2 ZLIB
uname -a:
  Darwin colossus.home 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14
  16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

----


====
Have some debug information:

  + Attempt to load DOOM: success! Loaded v2.0.2
    Revision e9d7f6f6f2ebd38f2138399e6763c511ec6f1d5b

  + enabled modules:
    +evil                  +jump                  +snippets
    +file-templates        +spellcheck            +syntax-checker
    +version-control       +workspaces            +eval
    +debug                 +company               +ivy
    +doom                  +doom-dashboard        +doom-modeline
    +doom-quit             +hl-todo               +dired
    +electric-indent       +eshell                +gist
    +macos                 +rotate-text           +term
    +tmux                  +upload                +assembly
    +cc                    +crystal               +csharp
    +data                  +elm                   +emacs-lisp
    +go                    +haskell               +java
    +javascript            +julia                 +latex
    +lua                   +markdown              +org
    +php                   +purescript            +python
    +rest                  +ruby                  +rust
    +scala                 +sh                    +swift
    +typescript            +web                   +email
    +present               +rss                   +twitter
    +write                 +hlissner

  + enabled packages:
    ace-link-20170319.553              ace-window-20170421.428
    all-the-icons-20170516.158         all-the-icons-20170516.158
    anaconda-mode-20170405.301         android-mode-20170323.115
    async-20170502.2343                auctex-11.90.2
    auto-compile-20170130.1017         auto-yasnippet-20160925.225
    avy-20170411.608                   centered-window-mode-20170510.2345
    cmake-mode-20160928.505            coffee-mode-20170324.240
    command-log-mode-20160412.2147     company-20170517.1436
    company-anaconda-20160809.705      company-auctex-20161025.24
    company-dict-20160528.53           company-go-20170420.515
    company-inf-ruby-20140805.1354     company-irony-20170515.1608
    company-irony-c-headers-20151018.209 company-lua-20161227.1139
    company-quickhelp-20170429.1052    company-racer-20160722.1658
    company-restclient-20151202.401    company-shell-20170507.445
    company-sourcekit-20170126.353     company-statistics-20170210.1133
    company-tern-20161004.1147         company-web-20160502.658
    counsel-20170518.1425              counsel-css-20170305.147
    counsel-projectile-20170216.1426   crystal-mode-20170504.2024
    csharp-mode-20170502.158           cuda-mode-20151213.1921
    dante-20170508.2347                demangle-mode-20170311.1148
    dired-k-20170313.803               disaster-20170507.1626
    dockerfile-mode-20170418.1024      doom-themes-20170519.759
    dumb-jump-20170520.112             editorconfig-20170518.817
    eldoc-eval-20150512.506            elfeed-20170518.1835
    elfeed-org-20170423.128            elm-mode-20170322.1347
    emmet-mode-20161113.2158           ensime-20170519.303
    evil-20170521.1211                 evil-anzu-20170123.2318
    evil-args-20140329.1429            evil-commentary-20170413.751
    evil-easymotion-20170110.2004      evil-embrace-20160519.1129
    evil-escape-20170115.1343          evil-exchange-20170510.1959
    evil-indent-plus-20151109.1106     evil-magit-20161130.847
    evil-matchit-20170119.125          evil-mc-20170514.1908
    evil-multiedit-20170515.337        evil-numbers-20140606.551
    evil-snipe-20170405.1644           evil-surround-20170124.1110
    evil-textobj-anyblock-20161020.1112 evil-vimish-fold-20161103.333
    evil-visualstar-20160222.1648      exec-path-from-shell-20170508.4
    expand-region-20170514.1309        f-20170404.1039
    flycheck-20170511.1425             flycheck-elm-20160717.257
    flycheck-irony-20160317.1536       flycheck-pos-tip-20170504.1504
    flycheck-rust-20170404.842         flyspell-correct-20170213.700
    flyspell-correct-ivy-20161031.1134 gist-20161127.855
    git-gutter-fringe-20170112.2133    git-link-20170504.1834
    git-timemachine-20170325.220       gitconfig-mode-20160710.1913
    gitignore-mode-20160319.302        glsl-mode-20160209.833
    go-eldoc-20170305.627              go-guru-20170501.1058
    go-mode-20170308.1512              gorepl-mode-20151121.422
    goto-last-change-20150109.1023     groovy-mode-20170516.1155
    gxref-20170411.1053                haml-mode-20170208.28
    haskell-mode-20170519.1555         haxor-mode-20160618.429
    help-fns+-20170223.733             highlight-indentation-20170502.43
    highlight-numbers-20160717.1228    highlight-quoted-20140916.1122
    hl-todo-20161102.1337              hlinum-20170507.2227
    htmlize-20161211.1019              imenu-anywhere-20160831.356
    imenu-list-20170215.125            impatient-mode-20170505.1921
    inf-ruby-20170515.1648             irony-20170518.1024
    irony-eldoc-20170502.1208          ivy-20170521.1150
    ivy-bibtex-20170321.1306           js2-mode-20170516.1643
    js2-refactor-20170315.1315         json-mode-20170418.1900
    julia-mode-20170426.1806           less-css-mode-20160930.2153
    lua-mode-20170130.435              magit-20170518.1126
    markdown-mode-20170519.1159        markdown-toc-20170224.2350
    meghanada-20170518.923             mips-mode-20170310.2149
    modern-cpp-font-lock-20170224.114  moonscript-20160503.631
    mu4e-maildirs-extension-20170217.40 multi-term-20160619.233
    nasm-mode-20161216.736             nav-flash-20140508.1341
    neotree-20170510.2147              nodejs-repl-20170110.940
    nose-20140520.948                  ob-go-20170324.932
    ob-mongo-20161130.152              ob-redis-20160411.2013
    ob-restclient-20160323.2305        ob-rust-20150612.1323
    ob-sql-mode-20170213.1056          ob-translate-20160411.124
    omnisharp-20170509.104             opencl-mode-20160220.909
    org-bullets-20140918.1137          org-download-20170213.1151
    org-plus-contrib-20170515.1305     org-tree-slide-20160513.2325
    osx-clipboard-20141012.17          ox-reveal-20161027.226
    pcre2el-20161120.1303              persp-mode-20170509.829
    php-boris-20130527.121             php-extras-20160518.1616
    php-mode-20170428.1853             php-refactor-mode-20160417.1446
    phpunit-20161219.320               pip-requirements-20160930.2032
    projectile-20170416.148            psc-ide-20170512.1513
    pug-mode-20170127.1949             purescript-mode-20161216.133
    quickrun-20170222.1715             racer-20170218.516
    rainbow-delimiters-20160430.2358   rainbow-mode-0.12
    realgud-20170521.119               restclient-20170516.137
    rjsx-mode-20170422.832             rotate-text-20111204.139
    rspec-mode-20170312.56             ruby-refactor-20160214.850
    rust-mode-20170514.2022            s-20170428.1026
    sass-mode-20161006.2326            sbt-mode-20170517.631
    scala-mode-20170323.502            shackle-20170213.1534
    shader-mode-20170130.623           skewer-mode-20170122.938
    slime-20170511.1221                smart-forward-20140430.13
    smartparens-20170511.743           smex-20151212.1409
    ssh-deploy-20170520.26             stripe-buffer-20141208.708
    stylus-mode-20150313.812           swift-mode-20170224.1825
    swiper-20170515.1409               tern-20161222.850
    tide-20170516.543                  toml-mode-20161107.1000
    twittering-mode-20170312.735       typescript-mode-20170424.2231
    vi-tilde-fringe-20141027.1942      vimrc-mode-20150607.913
    visual-fill-column-20170502.1300   web-beautify-20161115.1447
    web-mode-20170510.1127             wgrep-20141016.1656
    which-key-20170521.549             xref-js2-20160803.116
    yaml-mode-20170406.241             yard-mode-20160310.850
    yasnippet-20170518.1753

  + byte-compiled files:
    core/core.elc                          core/core-ui.elc
    core/core-projects.elc                 core/core-popups.elc
    core/core-packages.elc                 core/core-os.elc
    core/core-lib.elc                      core/core-keybinds.elc
    core/core-editor.elc                   core/autoload/ui.elc
    core/autoload/test.elc                 core/autoload/system.elc
    core/autoload/popups.elc               core/autoload/minibuffer.elc
    core/autoload/message.elc              core/autoload/memoize.elc
    core/autoload/editor.elc               core/autoload/debug.elc
    core/autoload/buffers.elc

  + exec-path:
    /usr/local/opt/openssl/bin
    /usr/local/opt/gnu-tar/libexec/gnubin
    /Users/leo/.luarocks/bin
    /usr/local/bin
    ~/.luarocks/bin
    /usr/local/opt/net-snmp/bin
    /usr/local/opt/coreutils/libexec/gnubin
    /usr/local/sbin
    /usr/texbin
    ~/bin
    /usr/local/opt/gnu-tar/libexec/gnubin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /opt/X11/bin
    /usr/local/MacGPG2/bin
    /Users/leo/.fzf/bin
    /usr/local/Cellar/emacs/25.2/libexec/emacs/25.2/x86_64-apple-darwin16.5.0

  + PATH:
    /usr/local/opt/openssl/bin
    /usr/local/opt/gnu-tar/libexec/gnubin
    /Users/leo/.luarocks/bin
    /usr/local/bin
    ~/.luarocks/bin
    /usr/local/opt/net-snmp/bin
    /usr/local/opt/coreutils/libexec/gnubin
    /usr/local/sbin
    /usr/texbin
    ~/bin
    /usr/local/opt/gnu-tar/libexec/gnubin
    /usr/bin
    /bin
    /usr/sbin
    /sbin
    /opt/X11/bin
    /usr/local/MacGPG2/bin

Everything seems fine, happy Emacs’ing!

All three of your suggestions worked, thanks for taking time to reply. But it's strange that
you have
(after! yasnippet
(nconc company-backends '(company-yasnippet)))

in your company/config.el by this yasnippets should've worked by default

@vsr625 It's how company cycles through company-backends. In a C++ buffer company-backends will end up with:

((company-irony-c-headers company-irony)
 company-capf company-yasnippet)

In which case, your completion results will be computed like so:

(company-irony-c-headers + company-irony) || company-capf || company-yasnippet

So yasnippet won't get a turn unless all its predecessors fail. And by "fail", I don't mean "no results found", I mean more like "this major mode isn't my jam" or "I'm not in the mood".

@leojrfs I assume you still have

(require 'company)
(setq company-idle-delay 0.2
      company-minimum-prefix-length 3)

Scroll to the bottom of init.el. Make a new line, and:

  1. type (define-, wait a second. If you haven't gotten a completion popup yet press C-SPC.
  2. Still nothing? Press M-x and run global-company-mode. Pay attention to the minibuffer. It should say "Global Company mode enabled".
    2.1. If it says enabled, try step 1 again (from scratch)
    2.2. If it said "Global company mode disabled", that means your changes in init.el aren't being read for some reason. Try adding this to your init.el:
(message "Hello world")

Then restart Emacs and run M-x view-echo-area-messages and see if "Hello World" appeared in the log.

If it does work, let me know what step you were on.

Completion works on emacs lisp, but it doesn't on lua.

The only thing I can think of is that Emacs cannot see the lua executable. Try this: M-x eval-expression RET (executable-find "lua") and see what it says. If it returns nil, then that's the problem.

Though, I should add: I'm a bit hazy on the exact format for company-backends to get company-irony-c-headers, company-irony and company-yasnippet to cooperate. It could be '(company-irony-c-headers company-irony company-yasnippet) or '(company-irony-c-headers company-irony :with company-yasnippet) or '(company-yasnippet :with company-irony-c-headers company-irony).

Can you tell me the proper way to change the backends inside private init.el?

@vsr625 All set! settings should be done from your private config.el file. set! settings (like :company-backend) won't exist at the time your private init.el is loaded.

;;; private/{user-login-name}/config.el
(set! :company-backend 'python-mode '(company-anaconda))
;; multiple modes at once
(set! :company-backend '(css-mode scss-mode) '(company-css company-yasnippet))

Note: (set! :company-backend MODES BACKENDS) will overwrite past settings for that mode.

@hlissner Did you test it? Because for me it's not working, before your latest commits it was working fine with (after! company (set! :company-backend ..)), in my config.el file.
I don't know why but it stopped working now.
If I use this, in a (after! company) inside config.el, it works correctly.
Edit: After a bit of testing, this commit might be the issue. If i revert this and add
(after! company (set! :company-backend '(c-mode c++-mode objc-mode) '(company-irony-c-headers company-irony company-yasnippet)))
Then company mode will suggest snippets also.

You're right. Made a huge oversight in that commit; resulting in :company-backend doing nothing at all. I've fixed it as of https://github.com/hlissner/.emacs.d/commit/18ad96d15600017855591375f1b71b4e77774b1c

Yea, now it works, but only if it's inside a (after! company) block, but that's fine anyway. Thanks for looking into it though.

Closing this issue due to lack of response. As far as I know, completion is working fine, but documentation needs to be improved to inform people about external dependencies.

Hello,
same issue for python autocomplete. To activate it I need to manually disable and re-enable global-company-mode. It's tedious.

Was this page helpful?
0 / 5 - 0 ratings