Question

I am seeking a plugin to do autocompletion popup for c++ development in emacs. what I have tried are Cedet Semantics and the Autocompletion mode, they are pretty neat in terms of completing the variable and function names as long as I have a few words already. For example, I have a class named foo and a function that returns an integer 1

class foo{
   int getInt(){return 1};
};

In the main method, so long as I started typing this

int main(){
 foo bar;
 bar.get...
}

the plugins have no problem popping up suggestions like bar.getInt(). However, what I am really looking for is something like in Eclipse, as soon as I press the "dot", possible choices could be generated for me. Is that possible in Emacs? Thanks

Was it helpful?

Solution

It depends on your settings of auto-complete & CEDET. It looks like that auto-complete is setup to show possible completions only after several characters will be typed. You can check value of the ac-auto-start variable - if this is a number, then auto-complete will be called after this number of characters. Another important thing is a what is in your ac-sources variable - for work with CEDET you need to use ac-source-semantic-raw or ac-source-semantic completion source. To automatic completion after . or -> you can try to use Semantic's built-in completion with something like:

(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

P.S. Had you seen my article on CEDET & C++?

OTHER TIPS

I have found that cedet is really underwhelming, especially under cmake projects.

I would recommend using https://github.com/Andersbakken/rtags It underlines errors as you type as well as using smart completions. Just add this to your init file after obtaining the required emacs packages

(require 'rtags)
(require 'popup)
(require 'rtags-ac)
(setq rtags-completions-enabled t)
(rtags-enable-standard-keybindings c-mode-base-map)
(add-hook 'c++-mode-hook
          (lambda ()
            (setq ac-sources '(ac-source-rtags)
)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top