So, first step: Install the CEDET development version.
- Get the development code from CEDET. Our primary repository can be
accessed through Bazaar:
bzr checkout bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk cedet
But there's also a git mirror at
(can also be accessed via http)
- Enter the toplevel cedet directory and call 'make'.
- Open your init file (.emacs) and add the following lines:
;; Load CEDET ;; This should be near the top of your init file, so that this can ;; really replace the CEDET that ships with Emacs proper. (load-file "/home/foo/cedet/cedet-devel-load.el") ;; Add further minor-modes to be enabled by semantic-mode. ;; See doc-string of `semantic-default-submodes' for other things ;; you can use here. (add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode) (add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode) ;; Enable Semantic (semantic-mode 1)
- Restart Emacs.
Congratulations, you've just installed CEDET. If you got problems with these steps, please report them in the comments or better through the CEDET-devel mailing list. We just completely switched to a new development branch for better merging with Emacs, so it might be entirely possible we have missed something.
- Install the mozrepl extension from
- Restart Firefox and start Mozrepl from its menu entry under "Tools".
- You should now be able to connect to port 4242 (try "telnet localhost 4242" or "nc localhost 4242", which should show you the mozrepl prompt).
- Now let's turn to Emacs. Open a file "test.html" and copy&paste the
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> </head> <body> This is just a test. </body> </html>
As you can see, this is basically a HTML5 file that loads the jQuery framework from googleapis.com.
- Save the file and do
M-x semanticdb-mozrepl-activate RET
Then, enter the URL "file:///<FULL PATH>/test.html". CEDET's Semantic will then open a connection to mozrepl and load the file in Firefox. After this is done, Emacs should say "Finished activating mozrepl database for <URL>", and Firefox should show you the above test.html file.
- Now create a new file "foo.js". Emacs should automatically switch to
might not work). Now simply enter
and wait for a second or two. Semantic should then start to give you completions on the jQuery object '$' through the so called "ghost text" style.
You can cycle through the completions by pressing TAB and choose one with RET. If you've never dealt with jQuery, just type
and wait for a second, and more familiar stuff should appear.
OK, if this is working so far, you are actually finished with the basic setup! Everything what follows now is dealing with the different types of completion interfaces you can use.
What you've already seen is the so called "idle completion" from Semantic, which by default uses this special kind of "ghost text" which isn't too intrusive so that it should not interfere with typing. However, you're probably more used to the typical popup-tooltips, which are also available. But first, let me say right off the bat that all completion mechanisms in CEDET are pretty basic. CEDET was always intended to be more of a framework for application developers, and luckily there are now at least two very nice completion frameworks which support CEDET, but have to be installed separately. I'll deal with those two in a minute, but first let's look at the ones you can use right away:
- M-x semantic-ia-complete-symbol-menu: This will display a menu with
the possible completions. You can choose one by pressing up/down and
RET. This is an older demonstration function for completion in
- M-x semantic-complete-analyze-inline: This is the newer and more
modern interface for doing completions in CEDET. You can define
different completion styles by doing
M-x customize-variable RET semantic-complete-inline-analyzer-displayor-class RET
If you are unhappy with these types of completions, you might want to take a look at the separate completion packages which are available. The two most popular are auto-complete and company-mode:
- auto-complete is available at
It has a lot of features and is pretty snappy. It supports CEDET's Semantic and I happen to like it a lot.
In the screenshot you could see further documentation for the 'ajax' function if mozrepl could supply any (possible for other languages like Emacs Lisp, though). However, its default configuration might be a bit "too much" for you. For example, you might want to restrict the number of backends it asks for completions. If you just set
(setq-default ac-sources '(ac-source-semantic-raw))
it will only query Semantic for completions and nothing else. Also, have a look at the variables "ac-delay" and "ac-auto-start", which define when auto-completion starts; the default behavior might be too intrusive for you, especially since getting completions from Semantic might not be fast enough for fluid typing (for large C++ projects it surely isn't).
- company-mode is available via GNU ELPA (built into Emacs24, just do
M-x list-packages), or from
In my opinion it is easier to configure and its defaults are less intrusive than auto-complete, but it also has less features. On Emacs24, it doesn't play well with an activated header-line (if you don't know what this is, you're not using them). Otherwise, it is a really nice framework for completions and works with CEDET out of the box. You just have to configure "company-semantic-modes", for example
(setq company-semantic-modes '(c-mode c++-mode js-mode jde-mode java-mode emacs-lisp-mode))
and make sure the buffer-local 'company-backend' includes 'company-semantic'. Please see the documentation for details. You can see an example in the first screenshot on this page.
OK, I think you have enough to get started. Please let me know how this stuff works for you. It is a pretty new thing and I'm not sure how stable this actually is; communicating with mozrepl is a bit of a challenge, but at least for me, it works pretty well so far.
Now that we've dealt with the interesting part, a few words on how it works, which should also highlight the problems this approach has.
There's one thing though: if you're switching tabs, the context in mozrepl will switch, too. There is however a built-in solution to this problem, but it is not activated by default since I'm not sure yet how well it works. The semanticdb-mozrepl backend can detect if you have switched to another tab and switch back automatically if it needs to query mozrepl. The variable that controls this behavior is "semanticdb-mozrepl-switch-tabs"; just see its docstring.
OK, I think this will suffice for now. Please let me know how this works for you, either in the comments or ask question on the CEDET-devel mailing list (which BTW is also available via Gmane as gmane.emacs.cedet).