• Login
Community
  • Login

*_js.php as javascript style

Scheduled Pinned Locked Moved General Discussion
6 Posts 2 Posters 707 Views
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.
  • J
    Jesus Campos
    last edited by Aug 28, 2019, 8:41 AM

    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!

    A 1 Reply Last reply Aug 28, 2019, 12:11 PM Reply Quote 0
    • A
      Alan Kilborn @Jesus Campos
      last edited by Aug 28, 2019, 12:11 PM

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

      A 1 Reply Last reply Aug 28, 2019, 7:55 PM Reply Quote 1
      • A
        Alan Kilborn @Alan Kilborn
        last edited by Aug 28, 2019, 7:55 PM

        @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
        • J
          Jesus Campos
          last edited by Sep 4, 2019, 3:53 PM

          “a Pythonscript solution”

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

          Thanks for reply.
          Regards.

          A 1 Reply Last reply Sep 4, 2019, 5:52 PM Reply Quote 0
          • A
            Alan Kilborn @Jesus Campos
            last edited by Sep 4, 2019, 5:52 PM

            @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
            • J
              Jesus Campos
              last edited by Sep 5, 2019, 10:23 AM

              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
              3 out of 6
              • First post
                3/6
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors