Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hey, I know that emacs supports code completion. But to be honest I have never been a good FAQ reader, at least for something that I'm completely new to. So I wonder what I need to download and how to make so emacs can do some smart code completion for me in C++, and Java. Or is there any package which does code completion for many of major languages?

share|improve this question
up vote 18 down vote accepted

The basic way that will work across any sort of buffer in emacs is dynamic abbreviation used by hitting M-/ (aka alt+/)

That will expand text to duplicate other strings already existing in your current buffer or in other buffers currently open.

For more extensive code completion that is language specific for C++ or Java (or others), you'll want to look at a code templating or snippet package. There are some discussed in this related question on StackOverflow. One that is commonly mentioned in these discussions is yasnippet -- there's a screencast demo in this post on an emacs blog.

share|improve this answer

@Doug's answer is a little out of date and his focus is on code expansion by using pre-defined snippets.

I think the OP's question is about intellisense (auto complete method name of a class, for example).

  1. The most popular one is hippie expand, the syntax analyzer is actually using emacs tags. So it support all the languages ctags supports (including C++ and Java). But the actual result is not perfect because ctags only uses regular expression to analyzed the code. See my init-hippie-expand.el for the details.

  2. auto-complete is a more modern one with fancy UI (dropdown menu, even in console window). If you use clang as a backend. The intellisense is much better. To get the clang working, you need install auto-complete-clang which is the plugin of auto-complete. It only supports the lanuage clang supports (C/C++/Obj-C). As Sylvain Benner pointed out, you can use emacs-eclim as the java parsing back end which actually calls the executable of eclipse. So auto-complete can support java. See my init-auto-complete.el for details.

  3. semantic provide both the UI and the backend parsing engine which are written in elisp only. It's slow. The dropdown UI is OK but require X window. The intellisense result is better than ctags. And the documenation is too geeky for me. See init-semantic.el for details.

  4. company-mode is similar to auto-complete, the difference is it package everything in one bundle. for example, for c++ developers, if you use auto-complete, you also need install auto-complete-clang, but for company, you only need company itself. another huge UI difference is by default, the company will show the candidate automatically. It means you press less keys in company.

In summary, the big four (hippie-expand, auto-complete, semantic, company) are the ones you may be interested. Many others are just too trivial to mention and their features may be already covered by the big four. For example, auto-complete could use yasnippet as input source (auto-complete provide the UI, but the actual candidates are produced by yasnippet backend).

As for me, I use hippie-expand and company-mode.

UPDATE: Now (Year 2014) company-mode and auto-complete are most popular and actively maintained. I think you can pick one from either of them.

hippie-expand could be also turned on because its default key binding does not conflict with the others. But I don't think you need turn on its ctags support.

share|improve this answer
Thanks for these. I'll have to explore. – Doug Harris Jan 9 '14 at 18:30
which is the best auto-completion package in Emacs 24 for latex? – doctorate Nov 21 '14 at 19:44
@doctorate I think you need use auto-complete and its source, but I'm a programmer instead of latex user, so you'd better double check at Google plus Emacs community, lots of academic guys there. – chen bin Nov 22 '14 at 1:06

Short answer: I know none for emacs that is useful for java. Dynamic expand does not care for the libraries in your class path, it does not know anything about the code you're typing it can only expand to text that already exists in one of the buffers. JDE and emacs-eclim try to provide this functionality but personally I was not impressed.

share|improve this answer

Short answer: M-/

Long answer: RTFM :-)

share|improve this answer
+1, god i hope the next question i see is "need help using RTFM command" – rownage Jan 10 '11 at 16:38
@rownage: oh, thats ``info-emacs-manual'` (C-h r) – SamB Jan 10 '11 at 18:51
How about C-h k M-/ ? – Doug Harris Jan 10 '11 at 20:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .