*_js.php as javascript style



  • Hi,

    It’s possible to auto set the language as javascript when the file ends as _js.php? Hi already set in the Style Configurator -> user extensions _js.php but it didn’t work… It would save me a lot of time.

    Regards!



  • @Jesus-Campos

    Ummm… all of that is based upon a file’s extension. The extension is (roughly) defined as whatever follows the final . in a file’s pathname, after the final path separator (e.g. \). By now you should have your answer, but in case you don’t I’ll give it to you: What you are asking isn’t reasonably possible.



  • @Jesus-Campos

    I have reconsidered. I think a script could do it. If you are interested in, say a Pythonscript solution, reply back.



  • “a Pythonscript solution”

    It would be great. I googled but I don’t even know how to start… :/

    Thanks for reply.
    Regards.



  • @Jesus-Campos

    So taking a nod from this recent posting, we can tweak what is found there, to obtain:

    # -*- coding: utf-8 -*-
    
    from Npp import editor, notepad, NOTIFICATION, MENUCOMMAND
    
    def callback_npp_FILESAVED(args):
        for (filename, bufferID, index, view) in notepad.getFiles():
            if bufferID == args['bufferID']:
                if filename.endswith('_js.php'):
                    notepad.menuCommand(MENUCOMMAND.LANG_JS)
                break
    
    notepad.callback(callback_npp_FILESAVED, [NOTIFICATION.FILESAVED])
    

    Which should do what you want.



  • Hi, thanks for the script. It opened a new world to me :)

    I Changed the enumerator [NOTIFICATION.FILESAVED] to [NOTIFICATION.FILEOPENED] and It worked but with a problem: if I do not have any opened file it work well, if I have, it change the language to the first opened file… So, I just added notepad.activateFile(filename) before the menu command and it work ok :)

    Thanks!


Log in to reply