5

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

Cong Hui
  • 633
  • 1
  • 13
  • 25

2 Answers2

2

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++?

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • 1
    Hey Alex! Actually I saw your article and am trying to mimic what you did but couldn't configure it right. Well, I got a few questions.About the ***dot*** insertion, I did what you suggested above, but everytime I typed in a ***dot** like in the case above after **bar***, I got this message ***Symbol's function definition is void: eieio-build-class-alist*** and couldn't even insert a normal dot sign at all. Also the ***ac-source***, I am using the auto completion packet, seems like the ac-source is a part of it. what's the relationship between them, I am kind of confused. Thank you – Cong Hui May 20 '12 at 12:18
  • btw, I set the ***ac-auto-start** variable to be 4, but everytime I started up Emacs, I needed to manually check the value of the variable by typing in C-H v **ac-auto-start*** first, then my ***dot*** insertion would work afterward, otherwise I kept getting the ***definition is void*** error. By the way, the ***dot*** seems to have trouble finding system headers too, like I typed in a dot after a Vector object, I couldn't see the size() function popping up as I wanted. Thank you so much – Cong Hui May 20 '12 at 13:21
  • hmm, that strange - it looks like eieio wasn't correctly loaded. Which version of Semantic are you using? – Alex Ott May 20 '12 at 18:43
  • Regadring `ac-source` - this variable holds a list of data sources that will be used to retrieve data. By default it should contain some function that perform lookup in current and other buffers, and complete using this information. To use Semantic data source you need to add it to this variable. Look to line 44 of my config (for new CEDET) - https://github.com/alexott/emacs-configs/blob/master/rc/emacs-rc-cedet.el – Alex Ott May 20 '12 at 18:45
  • Thank you for replying me. Well, I was using the latest cedet 1.1, and I don't really know which version of semantic it contains. The ac-source had no problem looking up variables and functions in buffers, but had time looking up for system headers, even I included ***(semantic-add-system-include "/usr/include/c++/4.6.3" 'c++-mode)***. i.e I was using vector from STL, I was hoping it to pop up suggestions after the dot insertion, like push_back(), but it couldn't find the STL header I guess. Thank you – Cong Hui May 20 '12 at 19:07
  • Instead of using `semantic-add-system-include`, it's better to use `semantic-gcc` package - it will detect gcc's version, and will setup all corresponding system paths. CEDET 1.1 should work fine - check my setup for it - https://github.com/alexott/emacs-configs/blob/master/rc/emacs-rc-cedet-old.el - but I hadn't used `auto-complete` package there, instead I used CEDET's built-in completion functions (bound to `C-RET`) – Alex Ott May 20 '12 at 20:38
0

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)
)))
octi
  • 1,470
  • 1
  • 17
  • 28