Community

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

    *_js.php as javascript style

    General Discussion
    2
    6
    300
    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.
    • Jesus Campos
      Jesus Campos last edited by

      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!

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

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

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

          @Jesus-Campos

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

          1 Reply Last reply Reply Quote 3
          • Jesus Campos
            Jesus Campos last edited by

            “a Pythonscript solution”

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

            Thanks for reply.
            Regards.

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

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

              1 Reply Last reply Reply Quote 4
              • Jesus Campos
                Jesus Campos last edited by

                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!

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