Notepad++ Language List
-
I have a plugin where I need to know the Notepad++ language list. I see “Notepad_plus_msgs.h” which is part of the template plugin has:
enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\ [...]
And that would work if there was some way to get the enum “name” from the LangType array (and then just strip the “L_”). Other thoughts are to just create an array of strings and (pseudo-code follows):
for i = (0 .. 85) { langArray[i] = NPPM_GETLANGUAGENAME (i) }
But I’m using 85 because I “know” there are 86 elements in the languages enum. In fact, if I ask NPP for language 86, it replies with “Normal Text” (which is language 0) so a proper while loop returning “i” until
NPPM_GETLANGUAGENAME (i)
returns a NULL wouldn’t work. Is there a NppGetNumberOfLanguages() call I’m not familiar with?As you can probably tell, C++ isn’t my “first language” so it’s quite possible I’m missing something obvious. Currently, I’m just defining my own array of strings and “hardcoding” the
enum LangType
“names” sans the “L_”. I was hoping to have something a bit more dynamic like thefor
loop example above.Cheers.
-
what about something like this pseudo code
enum LangType {L_TEXT, L_PHP , L_C, ... L_EXTERNAL}; for ( int i=0; i<LangType.L_EXTERNAL; i++ ) { langArray[i] = NPPM_GETLANGUAGENAME (i) }
L_EXTERNAL should be always the last entry in LangType
-
@Ekopalypse said in Notepad++ Language List:
L_EXTERNAL should be always the last entry in LangType
In fact you’re correct:
"Notepad_plus_msgs.h”:
// The end of enumated language type, so it should be always at the end L_EXTERNAL};
So your code makes perfect sense and it was something obvious I was missing! Thanks!
SOLVED!
Cheers.
-
@Ekopalypse said in Notepad++ Language List:
what about something like this pseudo code
Here is the actual code I used:
vector<string> lang_menu; std::string wstrtostr( const std::wstring &wstr ) { // Convert a Unicode string to an ASCII string [...] [...] lang_menu.clear(); for ( int i = 0; i <= L_EXTERNAL; i++ ) { TCHAR langName[MAX_PATH]; SendMessage( nppData._nppHandle, NPPM_GETLANGUAGENAME, i, ( LPARAM ) langName ); lang_menu.push_back( wstrtostr( langName )); } [...]
Thanks a million!
Cheers.
-
The disadvantage of your method is that you have to update your Notepad_plus_msgs.h file and recompile and redistribute your plugin everytime a new programming language is added to Notepad++.
I solved the same problem in my AutoCodepage plugin by querying language names in a repeat…until loop, that terminates if the returned language name equals to
External
. This way I don’t need to recompile and redistribute my plugin only because of extended programming language support of Notepad++.Additional hint: My loop doesn’t process
L_USER
andL_JS
. -
@dinkumoil said in Notepad++ Language List:
I solved the same problem in my AutoCodepage plugin by querying language names in a repeat…until loop, that terminates if the returned language name equals to External
I may “borrow” that :-)
Thanks!
-
@Michael-Vincent said in Notepad++ Language List:
I may “borrow” that :-)
It’s in Pascal! argh! I converted your recommendation into C++ (i think):
TCHAR langName[MAX_PATH]; lang_menu.clear(); do { SendMessage( nppData._nppHandle, NPPM_GETLANGUAGENAME, i, ( LPARAM ) langName ); lang_menu.push_back( wstrtostr( langName )); i++; } while ( strcmp( wstrtostr( langName ).c_str(), "External" ) != 0 ); lang_menu.push_back( "GLOBAL" );
This way no dependence on L_EXTERNAL or the Notepad_plus_msgs.h file.
Thanks for taking the time to recommend that!
Cheers.