Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

HighlightLanguage from filename

(1/1)

daniloz:
Hi All,

I'm writing a plugin and right now I'm struggling with the following, so maybe you can help me. :-)

Based on a file selected on the project pane, I want to discover the HighlightLanguage for it, but I can't get it to work. What I'm doing is

--- Code: ---...
EditorColourSet* theme = ed->GetColourSet();
HighlightLanguage lang = theme->GetLanguageForFilename(prjFile->file.GetFullName());

--- End code ---
which returns "CC" for a .cpp file.

However, it should be "C/C++", as confirmed by

--- Code: ---wxArrayString langs = theme->GetAllHighlightLanguages();
--- End code ---
In the langs array, there is no "CC", but "C/C++" indeed.

What am I missing here? What's the catch?

BTW, the first code returns an empty string for a .h file.  :o

danselmi:
This one returns the string you expected (at least on my system):

--- Code: ---Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(ed->GetLanguage() );
--- End code ---

daniloz:
Thanks for the answer danselmi.

I haven't tested it yet, but one thing I forgot to mention is that the file is not necessarily opened on an editor, so I cannot rely on "ed->GetLanguage()". I was just using "ed" to get to "EditorColourSet* theme". BTW, if there's a clever or better way to do it, I'd like to hear it...

Edit: top answer my question above, I just realized that I can simply do

--- Code: ---Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageForFilename(...)

--- End code ---
without going through the "theme" variable, but I still have the problem, of course.

daniloz:
Ok, following danselmi post, I found a solution (or should I say workaround) to my problem.

The way I'm doing it right now is

--- Code: ---HighlightLanguage langWrong = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageForFilename( _T(".")+prjFile->file.GetExt() );
HighlightLanguage lang = Manager::Get()->GetEditorManager()->GetColourSet()->GetLanguageName(langWrong);

--- End code ---

What I have, for example is:
langWrong = "CC" , lang = "C/C++"
langWrong = "MASM_Assembly", lang = "MASM Assembly"

Nonetheless, I'd like to understand what's the difference between both highlight language names and why do we have two. I suspect it has something to do with the lexers name and syntax highlighting, but I don't understand the C::B sources good enough to figure it out, so any explanation or clarification would be pretty much appreciated.

Thx!

danselmi:
The GetLanguage...() methods returning a HighlightLanguage which is an identifier for the language. The LanguageName is a human readable name for the Language (methods returning a wxString).

Navigation

[0] Message Index

Go to full version