Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    language select on notepad launch

    Plugin Development
    4
    9
    223
    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.
    • lubysj
      lubysj last edited by

      Hi

      I would like notepad automatically select user defined language based on the first line content.

      I have been trying to practice using command like this shown below but did not work. I think there is more to it than i thought.

      const char * lan = “xml”;
      ::SendMessage(nppData._nppHandle, SCI_SETLEXERLANGUAGE, 0, (LPARAM)lan);

      Thanks

      1 Reply Last reply Reply Quote 0
      • lubysj
        lubysj last edited by

        In the end after playing with the code I have understood that it is not possible to write such plugin. My biggest bet was to change language at a plugin initialization stage but the command (I have used a different command to the one listed above) gets ignored or overwritten.

        It is a bit pity that I cant do it as I work with old UNIX style files where the files do not include extensions and the extension definition is within a file. That is making to look at different editor despite I like notepad++.

        Thanks

        Alan Kilborn 1 Reply Last reply Reply Quote 0
        • Alan Kilborn
          Alan Kilborn @lubysj last edited by Alan Kilborn

          @lubysj

          It seems like you might be able to do this with one of the scripting plugins.

          You could (write and) install some logic that would fire upon opening a file. The logic could look at the first line and then select a different “language” based upon what is found in the first line’s contents…

          1 Reply Last reply Reply Quote 0
          • PeterJones
            PeterJones last edited by

            I tried playing with it some in PythonScript and my Perl library: it appears there may be a bug in the SCI_SETLEXERLANGUAGE string-based message, because it isn’t affecting the language chosen. There’s the SCI_SETLEXER int-based message which does work languages, but that cannot set a specific UDL.

            You could navigate the Languages menu, and look for the dynamically-allocated menuCmdID for your UDL.

            1 Reply Last reply Reply Quote 0
            • Ekopalypse
              Ekopalypse last edited by

              In general I would say using a notepad message ensures more or less
              that the UI gets updated as well where as scintilla messages flying under the radar of npp.

              @lubysj
              in your case I would say act on notepads bufferactivated notification,
              get the first line of the document and send either a menucommand,
              in case of udls or use NPPM_SETCURRENTLANGTYPE in case of builtin languages.

              Example how something might look like:

              from Npp import notepad, NOTIFICATION, editor, LANGTYPE
              
              def callback_BUFFERACTIVATED(args):
                  x = editor.getLine(0)
                  if x.startswith('// c++'):
                      notepad.setLangType(LANGTYPE.CPP)
                  elif x.startswith('# npp3'):
                      notepad.runMenuCommand('Language', 'NPP3')
                  else:
                      notepad.setLangType(LANGTYPE.PYTHON)
                      
              notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED])
              
              lubysj 1 Reply Last reply Reply Quote 4
              • lubysj
                lubysj last edited by lubysj

                Thanks to all. Buffer activated message did the trick. I do not work with Python, though always wanted to learn. For those who want code in c is below. It is quite good that it allows to catch other notepad messages, so plugin can play more part rather than being passive and reacting to user menu commands.

                xtern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
                {
                	switch (notifyCode->nmhdr.code) 
                	{
                		
                		case NPPN_BUFFERACTIVATED:
                		{
                			::SendMessage(nppData._nppHandle, NPPM_MENUCOMMAND, 0, IDM_LANG_XML);
                		}
                		break;
                		default:
                			return;
                	}
                }
                
                1 Reply Last reply Reply Quote 2
                • lubysj
                  lubysj @Ekopalypse last edited by

                  Going back to UDLs… I was able to execute normal menu commands including for changing build in languages. However, I wasn’t able to change to a user defined language.

                  @Ekopalypse are you able to open phyton library to check how does runcommand translates into c call?

                  Ekopalypse 1 Reply Last reply Reply Quote 0
                  • Ekopalypse
                    Ekopalypse @lubysj last edited by

                    @lubysj

                    Pythonscript plugin is on github and here the part you are interested in.

                    1 Reply Last reply Reply Quote 1
                    • lubysj
                      lubysj last edited by

                      @Ekopalypse , thanks. I will need to dig a bit to get a around.

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post
                      Copyright © 2014 NodeBB Forums | Contributors