redguardtoo / company-ctags

Fastest Emacs auto-completion using Company and Ctags
GNU General Public License v3.0
56 stars 3 forks source link

`M-/` won't give any candidates even if `(company-ctags-auto-setup)` was given #14

Closed yszhang95 closed 2 years ago

yszhang95 commented 2 years ago

Hi, Here is a naive question. I am a novice to emacs and company-mode. I am not sure if I did something wrong. I describe briefly my issue here. M-/ won't give me the candidate in TAGS file.

I have a setup in such a way:

  1. The OS is Fedora 34 (WSL version). emacs version is 27.2
  2. I generated tags using universal ctags.
  3. I cloned the full emacs starter kit from purcell with the fix. I added the following to init-local.el.
    (require-package 'company-ctags)
    (require 'company-ctags)
    (with-eval-after-load 'company
    (company-ctags-auto-setup))
    (provide 'init-local.el)
  4. I have a test project, created in the following way:
    mkdir include src
    echo "void test();" > include/functions.hpp
    cat > src/functions.cpp <<- _EOF_
    #include "include/functions.hpp"
    #include <iostream>
    void test()
    { std::cout << "Hello, world!" << std::endl; }
    _EOF_
    cat > src/main.cpp <<- _EOF_
    #include "include/functions.hpp"
    #include <iostream>
    int main()
    { }
    _EOF_
    ctags -R -e

    Now when I edited the main body of src/main.cpp, I inserted tes and type M-/. I expected the test will pop up. However, it shows No completion found. I have to type M-x company-ctags to find the candidate for completion. I tried the C-h v company-backends and it returns

    Its value is
    (company-slime company-ac-php-backend company-bbdb company-semantic company-cmake company-capf company-clang company-files
               (company-dabbrev-code company-gtags company-ctags company-keywords)
               company-oddmuse company-dabbrev)
    Original value was
    (company-bbdb company-semantic company-cmake company-capf company-clang company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)

    I am not familiar with the syntax and not sure why there is an inner-parenthesis to group a few backends. I guess the precedence of backends for company-mode is just from left to right in order. I tried to manipulate a bit, using

    (with-eval-after-load 'company
    (push 'compnay-ctags company-backends))

    And this time pop-up works.

Is this behavior expected or not?

Feel free to direct me to other channels and close this issue if this is not an issue related to this nice package.

Many thanks in advance!

redguardtoo commented 2 years ago

M-/ key is usually binding to M-x hippie-expand which has nothing to do with company-mode

I'm not sure how you setup company-mode. company-ctags-auto-setup just sets up company-backends. As I can see, it works.

If company-backends values is '(a b (c d) e), the backend "a" is run first, if it returns zero candidate, "b" will run. If "b" also returns zero candidate, both the "c" and "d" in next sub-group will run, and their cominbined candidates are returned. If that's also zero, the backend "e" will run.

It's all documented in `company-mode manual, please read it. It was updated recently.

It's a shame most online tutorials don't teach how to set up company-backends.

yszhang95 commented 2 years ago

Thank you so much for the prompt reply!

I run C-h k M-/ and it returns that this key binding is bound to company-complete.

I will read the online doc for company-mode. Sorry for this naive question.

Let me close this issue since it cannot be reproduced. And I will report back after I figured out why I failed using the default setup provided by this package.

Thanks again!

yszhang95 commented 2 years ago

Only one (grouped) backend can run each time. The backends are invoked one by one. But once a backend is invoked, the others won't turn on anymore. See the link