Community
    • Login

    Notepad++ Language List

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    7 Posts 3 Posters 1.9k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Michael VincentM Offline
      Michael Vincent
      last edited by

      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 the for loop example above.

      Cheers.

      EkopalypseE 1 Reply Last reply Reply Quote 2
      • EkopalypseE Offline
        Ekopalypse @Michael Vincent
        last edited by

        @Michael-Vincent

        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

        Michael VincentM 2 Replies Last reply Reply Quote 3
        • Michael VincentM Offline
          Michael Vincent @Ekopalypse
          last edited by

          @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.

          1 Reply Last reply Reply Quote 3
          • Michael VincentM Offline
            Michael Vincent @Ekopalypse
            last edited by

            @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.

            dinkumoilD 1 Reply Last reply Reply Quote 3
            • dinkumoilD Offline
              dinkumoil @Michael Vincent
              last edited by dinkumoil

              @Michael-Vincent

              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 and L_JS.

              Michael VincentM 1 Reply Last reply Reply Quote 3
              • Michael VincentM Offline
                Michael Vincent @dinkumoil
                last edited by

                @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 VincentM 1 Reply Last reply Reply Quote 1
                • Michael VincentM Offline
                  Michael Vincent @Michael Vincent
                  last edited by

                  @Michael-Vincent said in Notepad++ Language List:

                  I may “borrow” that :-)

                  @dinkumoil

                  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.

                  1 Reply Last reply Reply Quote 4

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors