I have discussed this feature with Loaden. (If I remember correct, there are some other discussion about this)
But making the code more colorfull is a good idea?
to implement this, we just need to add the keyword to some scintilla keyword list, and then scintilla edit control will do the job.
Codelite has this kind of feature, see the code snippet from Codelite IDE:
void ContextCpp::OnFileSaved()
{
PERF_FUNCTION();
VariableList var_list;
std::map< std::string, Variable > var_map;
std::map< wxString, TagEntryPtr> foo_map;
std::map<std::string, std::string> ignoreTokens;
wxArrayString varList;
wxArrayString projectTags;
LEditor &rCtrl = GetCtrl();
VALIDATE_WORKSPACE();
// if there is nothing to color, go ahead and return
if ( !(TagsManagerST::Get()->GetCtagsOptions().GetFlags() & CC_COLOUR_WORKSPACE_TAGS) && !(TagsManagerST::Get()->GetCtagsOptions().GetFlags() & CC_COLOUR_VARS) ) {
return;
}
// wxSCI_C_WORD2
if (TagsManagerST::Get()->GetCtagsOptions().GetFlags() & CC_COLOUR_WORKSPACE_TAGS) {
// get list of all tags from the workspace
TagsManagerST::Get()->GetAllTagsNames(projectTags);
}
// wxSCI_C_GLOBALCLASS
if (TagsManagerST::Get()->GetCtagsOptions().GetFlags() & CC_COLOUR_VARS) {
//---------------------------------------------------------------------
// Colour local variables
//---------------------------------------------------------------------
PERF_BLOCK("Getting Locals") {
const wxCharBuffer patbuf = _C(rCtrl.GetText());
// collect list of variables
get_variables( patbuf.data(), var_list, ignoreTokens, false);
}
// list all functions of this file
std::vector< TagEntryPtr > tags;
TagsManagerST::Get()->GetFunctions(tags, rCtrl.GetFileName().GetFullPath());
PERF_BLOCK("Adding Functions") {
VariableList::iterator viter = var_list.begin();
for (; viter != var_list.end(); viter++ ) {
Variable vv = *viter;
varList.Add(_U(vv.m_name.c_str()));
}
// parse all function's arguments and add them as well
for (size_t i=0; i<tags.size(); i++) {
wxString sig = tags.at(i)->GetSignature();
const wxCharBuffer cb = _C(sig);
VariableList vars_list;
get_variables(cb.data(), vars_list, ignoreTokens, true);
VariableList::iterator it = vars_list.begin();
for (; it != vars_list.end(); it++ ) {
Variable var = *it;
wxString name = _U(var.m_name.c_str());
if (varList.Index(name) == wxNOT_FOUND) {
// add it
varList.Add(name);
}
}
}
}
}
PERF_BLOCK("Setting Keywords") {
size_t cc_flags = TagsManagerST::Get()->GetCtagsOptions().GetFlags();
if (cc_flags & CC_COLOUR_WORKSPACE_TAGS) {
wxString flatStr;
for (size_t i=0; i< projectTags.GetCount(); i++) {
// add only entries that does not appear in the variable list
//if (varList.Index(projectTags.Item(i)) == wxNOT_FOUND) {
flatStr << projectTags.Item(i) << wxT(" ");
}
rCtrl.SetKeyWords(1, flatStr);
} else {
rCtrl.SetKeyWords(1, wxEmptyString);
}
if (cc_flags & CC_COLOUR_VARS) {
// convert it to space delimited string
wxString varFlatStr;
for (size_t i=0; i< varList.GetCount(); i++) {
varFlatStr << varList.Item(i) << wxT(" ");
}
rCtrl.SetKeyWords(3, varFlatStr);
} else {
rCtrl.SetKeyWords(3, wxEmptyString);
}
}
}