• Login
Community
  • Login

NppExec compilation of AutoIt files, with includes...

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
15 Posts 3 Posters 4.3k 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.
  • D
    Dave Binbin
    last edited by Oct 27, 2021, 10:34 AM

    Hi,

    I’m using Notepad++ to code in AutoIt, which is a quite classic language with included/nested files.
    So for one project, I have several files that I edit in parralel and then run the whole thing to test it.

    For the moment, I use a NppExec script like this :

    npp_saveall
    echo Running : $(FILE_NAME)
    if $(EXT_PART) != .au3 goto BADFILE
    "C:\Program Files (x86)\AutoIt3\Au3check.exe" "$(FULL_CURRENT_PATH)"
    if $(EXITCODE) >= 2 goto EXITSCRIPT
    "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" /ErrorStdOut "$(FULL_CURRENT_PATH)"
    goto EXITSCRIPT
    :BADFILE
    echo "Not an autoit file !!!"
    :EXITSCRIPT
    

    It works, but only if I run it from the main/top file of my project, because the compiler needs this main/top file.
    So everytime I want to run my project, I have to swap to the main file, and then launch my NppExec script.

    Is there a way that the NppExec script would work from any file of my project ? that it could know the mainfile of my project ?
    Maybe with some kind of NPP environnement variable that I could set at the beginning of each file of my project ?
    And then changing $(FULL_CURRENT_PATH) in something else in my script ?
    Note : I would like this NppExec script to remain “general”, for every project that I could work on : I do not want to hardcode the name of the curent project in the NppExec script…

    Thanks for your help.

    P M 2 Replies Last reply Oct 27, 2021, 1:28 PM Reply Quote 0
    • P
      PeterJones @Dave Binbin
      last edited by Oct 27, 2021, 1:28 PM

      @Dave-Binbin ,

      Is there a way that the NppExec script would work from any file of my project ? that it could know the mainfile of my project ?
      Maybe with some kind of NPP environnement variable that I could set at the beginning of each file of my project ?

      I am not sure how you expect NppExec would parse your active file – unlike some of the other scripting language plugins, NppExec doesn’t really have easy access to whatever portion of the current file you want. So I don’t think it would be easy to implement something like that.

      In the end, you would have to have some way of telling NppExec what the “main” file is for each project. And since NppExec is more filesystem-focused than file-content-focused, I would suggest a specialized file for the purpose.

      In many software development environments, there is something called a “makefile”, where you define how to compile and/or test and/or otherwise “make” a project – and each project has its own makefile. It could be a literal makefile, which works with the make/gmake/nmake utility on your computer; or it could be a batchfile; or it could be some custom solution.

      So for your case, I might suggest creating a file called makefile.nppexec, which goes in the same folder as your .au3 files for a given project. The makefile.nppexec would look something like

      set PROJECTMAINFILE = PutMainFileNameHere.au3
      echo Running main program $PROJECTMAINFILE from directory $(CURRENT_DIRECTORY)
      "C:\Program Files (x86)\AutoIt3\Au3check.exe" "$(CURRENT_DIRECTORY)\$(PROJECTMAINFILE)"
      if $(EXITCODE) >= 2 goto EXITSCRIPT
      "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" /ErrorStdOut "$(CURRENT_DIRECTORY)\$(PROJECTMAINFILE)"
      :EXITSCRIPT
      

      … and you would customize the makefile.nppexec in each project to call that project’s main file (using the variable at the top)

      Then you would change your main NppExec script to:

      npp_saveall
      echo Starting from : $(FILE_NAME)
      cd "$(CURRENT_DIRECTORY)"
      if $(EXT_PART) != .au3 goto BADFILE
      npp_exec makefile.nppexec   // this runs the "makefile" for the current project
      goto EXITSCRIPT
      :BADFILE
      echo "Not an autoit file !!!"
      :EXITSCRIPT
      

      … so you would have one makefile.nppexec per project folder, and you would then run the central NppExec script, and based on the current directory of the active .au3 file, it would run the appropriate makefile.nppexec from that folder.

      D 2 Replies Last reply Oct 28, 2021, 2:34 PM Reply Quote 3
      • D
        Dave Binbin @PeterJones
        last edited by Oct 28, 2021, 2:34 PM

        @PeterJones Thank you for your very constructive solution !
        I will integrate it right now.

        1 Reply Last reply Reply Quote 0
        • D
          Dave Binbin @PeterJones
          last edited by Oct 28, 2021, 2:44 PM

          @PeterJones I just wonder if the variable PROJECTMAINFILE defined in the makefile.nppexec script would be visible in the common NppExec script ? Infact I wonder if the makefile could only contain this variable declaration and put the rest back in the main NppExec script ? I suppose it does not work like an “include”. Or maybe Environement variables are “remanent” ?

          1 Reply Last reply Reply Quote 0
          • M
            Michael Vincent @Dave Binbin
            last edited by Oct 28, 2021, 2:49 PM

            @Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:

            Is there a way that the NppExec script would work from any file of my project ?

            You could set a NppExec global variable to the project root directory and then at the beginning of your compile script, just CD to that directory. I do something very similar - I have a “project” NppExec script which sets a project directory as an NppExec global variable and then all of my other scripts can see / use that directory (e.g., CD to it) to do stuff. So I can set my project directory to the one with the Makefile and then press my compile shortcut hotkey for my NppExec compile script from the header file in a different directory and it will compile the whole project.

            Cheers.

            D 1 Reply Last reply Oct 28, 2021, 3:02 PM Reply Quote 0
            • D
              Dave Binbin @Michael Vincent
              last edited by Oct 28, 2021, 3:02 PM

              @Michael-Vincent I do not understand how you implement this… By global NppExec variable, do you mean env_set variable ? Could you post a example ?

              M P 2 Replies Last reply Oct 28, 2021, 3:17 PM Reply Quote 0
              • M
                Michael Vincent @Dave Binbin
                last edited by Oct 28, 2021, 3:17 PM

                @Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:

                By global NppExec variable, do you mean env_set variable ? Could you post a example ?

                Exactly:

                ENV_SET PROJECT_DIR=C:\my\proj\dir
                

                This way, if I spawn a shell (i.e., launch Command Prompt from NppExec) - that environment variable is present there as well.

                Cheers.

                D 1 Reply Last reply Oct 28, 2021, 3:26 PM Reply Quote 1
                • D
                  Dave Binbin @Michael Vincent
                  last edited by Oct 28, 2021, 3:26 PM

                  @Michael-Vincent as I will not define a “makefile” in every project, I would like to compile by default the current NPP file $(FULL_CURRENT_PATH). So I wonder how I could test if the env variable exists or not ?

                  if "$(SYS.PROJECTMAINFILE)" != "" then
                  

                  crashes if the env var is not defined…

                  P 1 Reply Last reply Oct 28, 2021, 3:34 PM Reply Quote 0
                  • P
                    PeterJones @Dave Binbin
                    last edited by PeterJones Oct 28, 2021, 3:35 PM Oct 28, 2021, 3:34 PM

                    @Dave-Binbin ,

                    In your main script, start with

                    ENV_SET PROJECTMAINFILE="$(FULL_CURRENT_PATH)"
                    

                    then call the makefile – if the makefile defines that same variable, the value will be updated to whatever’s in the makefile, otherwise it will use the initial value from the main script.

                    (There might even be a way in NppExec to say “if file makefile.nppexec exists then npp_exec that file”, but I don’t know how to do file-exist tests in NppExec. @Michael-Vincent might.)

                    D 1 Reply Last reply Oct 28, 2021, 3:45 PM Reply Quote 0
                    • P
                      PeterJones @Dave Binbin
                      last edited by Oct 28, 2021, 3:38 PM

                      @Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:

                      By global NppExec variable

                      local vs global vs environment

                      • set local myvar=value – only seen in the active script
                      • set myglobal=value – seen in the active script and in subsequent scripts or the Console
                      • env_set myenv=value – seen in the active script, subsequent scripts, and the console as $(SYS.MYENV); seen in any subshells (like cmd.exe or powershell called from NppExec) as a normal environment variable, using appropriate shell syntax
                      1 Reply Last reply Reply Quote 1
                      • D
                        Dave Binbin @PeterJones
                        last edited by Oct 28, 2021, 3:45 PM

                        @PeterJones said in NppExec compilation of AutoIt files, with includes...:

                        ENV_SET PROJECTMAINFILE=“$(FULL_CURRENT_PATH)”

                        great, thanks !!!

                        do you know how I can test the file extension “.au3” of this file like I did in the original script,
                        in case there is no makefile and I point on a non-au3 file…

                        if $(EXT_PART) != .au3 goto BADFILE
                        
                        P 1 Reply Last reply Oct 28, 2021, 3:56 PM Reply Quote 0
                        • P
                          PeterJones @Dave Binbin
                          last edited by PeterJones Oct 28, 2021, 4:38 PM Oct 28, 2021, 3:56 PM

                          @Dave-Binbin ,

                          do you know how I can test the file extension “.au3” of this file like I did in the original script,

                          By doing it like you did in the original script, or like I showed in my original “main NppExec script”.

                          main script

                          npp_saveall
                          ENV_SET PROJECTMAINFILE=$(FULL_CURRENT_PATH)
                          echo Starting from : $(FILE_NAME)
                          cd "$(CURRENT_DIRECTORY)"
                          if $(EXT_PART) != .au3 goto BADFILE
                          npp_exec makefile.nppexec   // this runs the "makefile" for the current project
                          "C:\Program Files (x86)\AutoIt3\Au3check.exe" "$(SYS.PROJECTMAINFILE)"
                          if $(EXITCODE) >= 2 goto EXITSCRIPT
                          "C:\Program Files (x86)\AutoIt3\AutoIt3.exe" /ErrorStdOut "$(SYS.PROJECTMAINFILE)"
                          goto EXITSCRIPT
                          :BADFILE
                          echo "Not an autoit file !!!"
                          :EXITSCRIPT
                          

                          makefile.nppexec

                          ENV_SET PROJECTMAINFILE=MyNameHere.au3
                          

                          —
                          EDIT: removed the quotes from the env_set, which puts quotes in the string

                          D 1 Reply Last reply Oct 28, 2021, 4:10 PM Reply Quote 1
                          • D
                            Dave Binbin @PeterJones
                            last edited by Oct 28, 2021, 4:10 PM

                            @PeterJones said in NppExec compilation of AutoIt files, with includes...:

                            EXT_PART

                            but in case the makefile exists, EXT_PART will not test the updated PROJECTMAINFILE but still the file from which I run the script, no ?

                            P 1 Reply Last reply Oct 28, 2021, 4:28 PM Reply Quote 0
                            • P
                              PeterJones @Dave Binbin
                              last edited by PeterJones Oct 28, 2021, 4:31 PM Oct 28, 2021, 4:28 PM

                              @Dave-Binbin said in NppExec compilation of AutoIt files, with includes...:

                              but in case the makefile exists, EXT_PART will not test the updated PROJECTMAINFILE but still the file from which I run the script, no ?

                              Correct, $(EXT_PART) is always the extension portion of the active file in Notepad++, and it is not affected by the makefile at all.

                              So I may have misunderstood your original follow-on request. I think the best advice is “don’t set PROJECTMAINFILE to a non-.au3 file”.

                              Using the substring notation (see help set or Plugins > NppExec > Docs…) for variable setting, you might be able to extract the last three characters from $(SYS.PROJECTMAINFILE) into a separate variable, and use that for testing whether or not to skip. But that would take some research and experimenting; I think you should be able to read those documents as well as I can.

                              P 1 Reply Last reply Oct 28, 2021, 4:46 PM Reply Quote 2
                              • P
                                PeterJones @PeterJones
                                last edited by Oct 28, 2021, 4:46 PM

                                I got curious, and had a couple spare minutes, so I did the experiment.

                                set local e ~ substr -4 4 $(SYS.PROJECTMAINFILE)
                                if $(e) != .au3 goto BADFILE
                                

                                so if you put that immediately after the npp_exec makefile.nppexec and before the Au3check.exe call, it will do a test for the PROJECTMAINFILE extension as well.

                                1 Reply Last reply Reply Quote 2
                                9 out of 15
                                • First post
                                  9/15
                                  Last post
                                The Community of users of the Notepad++ text editor.
                                Powered by NodeBB | Contributors