Switch to a different language, through scripting?

fb16
2013-04-08
2013-04-11
  • fb16
    fb16
    2013-04-08

    I'd like to know if it's possible to switch to a different language, through scripting, instead of going through: Menu:Language:[any-language]

    Thanks

     
    • In python script, you can do notepad.setLangType(LANGTYPE.HTML)
      You can set the language type of a different buffer than the current home
      by supplying the buffer id as the second parameter.

      Obviously languages are settable to whatever you need. See
      https://github.com/davegb3/PythonScript/blob/master/PythonScript/src/NotepadPython.cppfrom
      line 93 for a list (sadly this list is missing from the
      documentation).

       
  • fb16
    fb16
    2013-04-08

    Hello Dave, thank you for answering.

    I've put the only line "notepad.setLangType(LANGTYPE.CSS)" in a new py script. Restarted. Now when I run the script (Menu:Plugins:Python Script:Scripts:[my-script.py]), NPP++ crashes and a runtime error is returned. Here is the error capture: [IMG]http://i49.tinypic.com/1r68u9.png[/IMG]

    (NPP++ 6.2.3 along with PyScript 0.9.2)

     
  • fb16
    fb16
    2013-04-11

    These lines work. Unfortunately I don't know how to run a check on the input value, against the available <LangType> values in https://github.com/davegb3/PythonScript/blob/master/PythonScript/src/NotepadPython.cpp

    from Npp import *
    
    bufferID = notepad.getCurrentBufferID()
    inputLANG=notepad.prompt("Insert the <LangType> value to convert into (case insensitive):", "Notepad++ Prompt", "")
    notepad.setLangType(eval("LANGTYPE."+inputLANG.upper()), bufferID)