CEDET 
 User Tools 
  Simple Setup 
  Project Management 
  Smart Completion 
  Find References 
  Code Generation 
  UML Graphs 
  Language Support 
  Project Support 
 Developer Primers 
  Add a Language 
  Add external tool 
 Parts of CEDET 
  EDE 
  Semantic 
  SRecode 
  Cogre 
  Speedbar 
  EIEIO 
  Misc Tools 
  Documentation 
 Releases 
  1.0.1 
  1.1 
 Source Forge 
  Project 
  Mailing Lists 
   cedet-devel 
   cedet-semantic 
   cedet-eieio 
  Screenshots 
  Git Repository 
 More Tools 
  JDEE 
  ECB 
  CompletionUI 
 
<< Files >>

Smart Completion

CEDET's smart code completion, is sometimes known as "Intellisense". The CEDET infrastructure for parsing and tagging files, and analyzing source code is one of the most accurate completion tools for C++ anywhere. It will correctly handle inheritance scoping rules, templates, smart-pointers, and automatically filters based on what the value will be assigned into.

Code completion is not restricted to just C or C++. The completion engine is generic and works for any language that has a robust tagging parser written for CEDET, and a thin adaptation layer for the language.

In addition, the same engine used for smart completion enables smart function prototype help which will correctly display a prototype for the method of the correct class you are working with. It also enables you to jump to the correct declaration of what is referenced under point.

The image to the right shows smart completion configured to use tooltips in a CEDET unit test source file going through a templated smart pointer.

What makes it Smart?

Emacs has many pre-existing completion systems. One of the most popular kinds is sometimes known as "dabbrev", or Dynamic Abbreviations. This works by looking at the text prefix, and then snooping around for similar text to guess what you might be typing. Dabbrevs might be considered "clever", but not smart.

For CEDET, the smart completion engine is in a subsystem called Semantic. Semantic is a tool that starts with lexical and syntactic analysis and builds up to a code analyzer that can resolve completions from a an incomplete code fragment.

The smart completion in Semantic looks up your prefix in a database of all the variables, functions, and data types available to to semantic System. The scope of the code lookups is done with the EDE Project manager.

By way of example, if you start with a code snippet like this:

#include "moose.h"

int main() {
  struct Moose M;

  int q = M->

If the cursor is just after the M->, the first thing Semantic does is identify M as the variable of type struct Moose. The datatype Moose is then looked up in any databases available to this file. Logically, it would examine and find the Moose in the file moose.h.

Once found, all the members of Moose are examined. Since the result is being passed into q which is of type int, only things that can resolve to the same datatype are offered. That could be fields of type int, or other structures or classes that might also have ints in them.

The image below shows the smart completion engine working with Qt.

Setup

Start with the general CEDET setup. Be sure to enable both EDE, and Semantic's basic code helpers.

(load-file "~/cedet-1.0pre6/common/cedet.el")
(global-ede-mode 1)                      ; Enable the Project management system
(semantic-load-enable-code-helpers)      ; Enable prototype help and smart completion 

Next, you can configure one of the many smart completion tools. The engine that generates the completions list is used in a wide variety of tools within Semantic, and also externally authored.

Alex Ott has written a great article called A Gentle Introduction to CEDET that shows many different ways of enabling smart code completion.

Different completion Interfaces

Here are a few tools available in CEDET/Semantic for performing completion.

Start inline completion

   M-x semantic-complete-analyze-inline
This is a command that does completion inline (underlining the target symbol) and allows TAB to be used for completion purposes.

Automatically starting inline completion in idle time

   M-x global-semantic-idle-completions-mode

This is a minor mode which runs semantic-complete-analyze-inline-idle during idle time. Instead of trying to complete the symbol immediately, it will just display the possible completions, and underline the current symbol the cursor is on.

Starting for inline completion when "." is pressed

  (define-key your-mode-map-here "." 'semantic-complete-self-insert)

Binding semantic-complete-self-insert to a key will insert that key's text, as per self-insert-command, and then run the inline completion engine if there is appropriate context nearby.

Speedbar completion mode

   M-x semantic-speedbar-analysis

This will start Speedbar in a special mode. In this mode it will analyze the cursor location, and provide intelligent references. Unlike inline completion, a raw list of options is provided and you just need to click on the one you want. Sometimes you need to press g to force an update.

Command based completion

The commands available (for binding to a key) are:

  • semantic-ia-complete-symbol
  • semantic-ia-complete-symbol-menu
  • semantic-ia-complete-tip

These commands are all very simple, and are designed as examples that a coder could examine to learn how to write their own completion interface.


 
Get CEDET at SourceForge.net.
gnu Eric's homepage
Return to CEDET.
Send mail to cedet-devel to contact the developers.
Visit Siege-engine.com to see what I do in analog land.

Copyright(C) 1997,98,99,2000,01,02,03,04,05,06,07,08,09,10,11 Eric M. Ludlam
Verbatim copying and distribution is permitted in any medium, provided this notice is preserved.